已关闭的驱动器不允许下载

This commit is contained in:
赵俊
2021-04-11 15:56:08 +08:00
parent c4a17985a4
commit 23bb3960ab
4 changed files with 57 additions and 5 deletions

View File

@@ -3,10 +3,12 @@ package im.zhaojun.zfile.controller.home;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.URLUtil;
import im.zhaojun.zfile.context.DriveContext;
import im.zhaojun.zfile.exception.NotAllowedDownloadException;
import im.zhaojun.zfile.exception.NotEnabledDriveException;
import im.zhaojun.zfile.model.constant.ZFileConstant;
import im.zhaojun.zfile.model.dto.FileItemDTO;
import im.zhaojun.zfile.model.entity.DriveConfig;
import im.zhaojun.zfile.model.enums.FileTypeEnum;
import im.zhaojun.zfile.service.DriveConfigService;
import im.zhaojun.zfile.service.base.AbstractBaseFileService;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
@@ -37,7 +39,14 @@ public class DirectLinkController {
*/
@GetMapping("/directlink/{driveId}/**")
public String directlink(@PathVariable("driveId") Integer driveId,
final HttpServletRequest request) {
final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
DriveConfig driveConfig = driveConfigService.findById(driveId);
Boolean enable = driveConfig.getEnable();
if (!enable) {
throw new NotEnabledDriveException();
}
String path = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

View File

@@ -3,7 +3,7 @@ package im.zhaojun.zfile.controller.home;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.context.DriveContext;
import im.zhaojun.zfile.exception.NotExistFileException;
import im.zhaojun.zfile.exception.NotEnabledDriveException;
import im.zhaojun.zfile.exception.PasswordVerifyException;
import im.zhaojun.zfile.model.constant.ZFileConstant;
import im.zhaojun.zfile.model.dto.FileItemDTO;
@@ -113,6 +113,12 @@ public class FileController {
// 开始获取参数信息
SystemFrontConfigDTO systemConfig = systemConfigService.getSystemFrontConfig(driveId);
DriveConfig driveConfig = driveConfigService.findById(driveId);
Boolean enable = driveConfig.getEnable();
if (!enable) {
throw new NotEnabledDriveException();
}
systemConfig.setDebugMode(debug);
systemConfig.setDefaultSwitchToImgMode(driveConfig.getDefaultSwitchToImgMode());

View File

@@ -19,12 +19,22 @@ public class GlobleExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobleExceptionHandler.class);
/**
* 不存在的文件异常
*/
@ExceptionHandler({NotEnabledDriveException.class})
@ResponseBody
public ResultBean notEnabledDrive() {
return ResultBean.error("驱动器已关闭");
}
/**
* 不存在的文件异常
*/
@ExceptionHandler({NotExistFileException.class})
@ResponseBody
public ResultBean notExistFile(Exception ex) {
public ResultBean notExistFile() {
return ResultBean.error("文件不存在");
}
@@ -35,7 +45,7 @@ public class GlobleExceptionHandler {
@ExceptionHandler({HttpMediaTypeNotAcceptableException.class, ClientAbortException.class})
@ResponseBody
@ResponseStatus
public void clientAbortException(Exception ex) {
public void clientAbortException() {
// if (log.isDebugEnabled()) {
// log.debug("出现了断开异常:", ex);
// }

View File

@@ -0,0 +1,27 @@
package im.zhaojun.zfile.exception;
/**
* 未启用的驱动器异常
*/
public class NotEnabledDriveException extends RuntimeException {
public NotEnabledDriveException() {
}
public NotEnabledDriveException(String message) {
super(message);
}
public NotEnabledDriveException(String message, Throwable cause) {
super(message, cause);
}
public NotEnabledDriveException(Throwable cause) {
super(cause);
}
public NotEnabledDriveException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}