mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
🏗️ 增强系统校验
This commit is contained in:
@@ -63,6 +63,9 @@ public class GlobleExceptionHandler {
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件预览异常
|
||||
*/
|
||||
@ExceptionHandler({PreviewException.class})
|
||||
@ResponseBody
|
||||
@ResponseStatus
|
||||
@@ -71,6 +74,18 @@ public class GlobleExceptionHandler {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化异常
|
||||
*/
|
||||
@ExceptionHandler({InitializeException.class})
|
||||
@ResponseBody
|
||||
@ResponseStatus
|
||||
public ResultBean initializeException(InitializeException ex) {
|
||||
return ResultBean.error(ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ExceptionHandler
|
||||
@ResponseBody
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package im.zhaojun.zfile.service;
|
||||
|
||||
import im.zhaojun.zfile.context.StorageTypeContext;
|
||||
import im.zhaojun.zfile.exception.InitializeException;
|
||||
import im.zhaojun.zfile.model.dto.DriveConfigDTO;
|
||||
import im.zhaojun.zfile.model.dto.StorageStrategyConfig;
|
||||
import im.zhaojun.zfile.model.entity.DriveConfig;
|
||||
@@ -163,6 +164,11 @@ public class DriveConfigService {
|
||||
storageConfigRepository.saveAll(storageConfigList);
|
||||
|
||||
driveContext.initDrive(driveConfig.getId());
|
||||
|
||||
AbstractBaseFileService driveService = driveContext.getDriveService(driveConfig.getId());
|
||||
if (driveService.getIsUnInitialized()) {
|
||||
throw new InitializeException("初始化异常, 请检查配置是否正确.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public class StorageConfigService {
|
||||
@Resource
|
||||
private StorageConfigRepository storageConfigRepository;
|
||||
|
||||
|
||||
public List<StorageConfig> selectStorageConfigByType(StorageTypeEnum storageTypeEnum) {
|
||||
return storageConfigRepository.findByTypeOrderById(storageTypeEnum);
|
||||
}
|
||||
@@ -56,6 +57,4 @@ public class StorageConfigService {
|
||||
storageConfigRepository.saveAll(storageConfigList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -63,12 +64,17 @@ public class LocalServiceImpl extends AbstractBaseFileService implements BaseFil
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileItemDTO> fileList(String path) {
|
||||
public List<FileItemDTO> fileList(String path) throws FileNotFoundException {
|
||||
List<FileItemDTO> fileItemList = new ArrayList<>();
|
||||
|
||||
String fullPath = StringUtils.concatPath(filePath, path);
|
||||
|
||||
File file = new File(fullPath);
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("文件不存在");
|
||||
}
|
||||
|
||||
File[] files = file.listFiles();
|
||||
|
||||
if (files == null) {
|
||||
|
||||
Reference in New Issue
Block a user