mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
✨ 已关闭的驱动器不允许下载
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user