Skip to content

Commit

Permalink
🏗️ 增强系统校验
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojun1998 committed Apr 20, 2020
1 parent 708eb33 commit 547e688
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void clientAbortException(Exception ex) {
// }
}

/**
* 文件预览异常
*/
@ExceptionHandler({PreviewException.class})
@ResponseBody
@ResponseStatus
Expand All @@ -71,6 +74,18 @@ public ResultBean previewException(PreviewException ex) {
}


/**
* 初始化异常
*/
@ExceptionHandler({InitializeException.class})
@ResponseBody
@ResponseStatus
public ResultBean initializeException(InitializeException ex) {
return ResultBean.error(ex.getMessage());
}




@ExceptionHandler
@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -163,6 +164,11 @@ public void save(DriveConfigDTO driveConfigDTO) {
storageConfigRepository.saveAll(storageConfigList);

driveContext.initDrive(driveConfig.getId());

AbstractBaseFileService driveService = driveContext.getDriveService(driveConfig.getId());
if (driveService.getIsUnInitialized()) {
throw new InitializeException("初始化异常, 请检查配置是否正确.");
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class StorageConfigService {
@Resource
private StorageConfigRepository storageConfigRepository;


public List<StorageConfig> selectStorageConfigByType(StorageTypeEnum storageTypeEnum) {
return storageConfigRepository.findByTypeOrderById(storageTypeEnum);
}
Expand Down Expand Up @@ -56,6 +57,4 @@ public void updateStorageConfig(List<StorageConfig> storageConfigList) {
storageConfigRepository.saveAll(storageConfigList);
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import javax.annotation.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -63,12 +64,17 @@ public void init(Integer driveId) {
}

@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) {
Expand Down

0 comments on commit 547e688

Please sign in to comment.