diff --git a/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAop.java b/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java similarity index 98% rename from src/main/java/im/zhaojun/zfile/aspect/FileListCacheAop.java rename to src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java index edff900..22ee95e 100644 --- a/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAop.java +++ b/src/main/java/im/zhaojun/zfile/aspect/FileListCacheAspect.java @@ -19,7 +19,7 @@ import java.util.List; */ @Aspect @Component -public class FileListCacheAop { +public class FileListCacheAspect { @Resource private ZFileCache zFileCache; diff --git a/src/main/java/im/zhaojun/zfile/cache/MyTimedCache.java b/src/main/java/im/zhaojun/zfile/cache/MyTimedCache.java index 48787b2..6364c0b 100644 --- a/src/main/java/im/zhaojun/zfile/cache/MyTimedCache.java +++ b/src/main/java/im/zhaojun/zfile/cache/MyTimedCache.java @@ -32,7 +32,7 @@ public class MyTimedCache extends TimedCache { driveContext = SpringContextHolder.getBean(DriveContext.class); } DriveCacheKey cacheKey = (DriveCacheKey) key; - AbstractBaseFileService baseFileService = driveContext.getDriveService(cacheKey.getDriveId()); + AbstractBaseFileService baseFileService = driveContext.get(cacheKey.getDriveId()); try { baseFileService.fileList(cacheKey.getKey()); } catch (Exception e) { diff --git a/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java b/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java index 50fb066..a56f6ec 100644 --- a/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java +++ b/src/main/java/im/zhaojun/zfile/cache/ZFileCache.java @@ -28,15 +28,21 @@ import java.util.concurrent.ConcurrentMap; @Component public class ZFileCache { + /** + * 缓存过期时间 + */ @Value("${zfile.cache.timeout}") private long timeout; + /** + * 缓存自动刷新间隔 + */ @Value("${zfile.cache.auto-refresh.interval}") private long autoRefreshInterval; /** - * 缓存 map 对象. + * 文件/文件对象缓存. * * ConcurrentMap>> * ConcurrentMap> diff --git a/src/main/java/im/zhaojun/zfile/config/OneDriveConfig.java b/src/main/java/im/zhaojun/zfile/config/OneDriveConfig.java index 2e7a5dc..7f341f5 100644 --- a/src/main/java/im/zhaojun/zfile/config/OneDriveConfig.java +++ b/src/main/java/im/zhaojun/zfile/config/OneDriveConfig.java @@ -30,7 +30,6 @@ public class OneDriveConfig { @Resource private OneDriveChinaServiceImpl oneDriveChinaServiceImpl; - /** * OneDrive 请求 RestTemplate, 会在请求头中添加 Bearer: Authorization {token} 信息, 用于 API 认证. */ diff --git a/src/main/java/im/zhaojun/zfile/context/DriveContext.java b/src/main/java/im/zhaojun/zfile/context/DriveContext.java index 11ffac2..948e8e2 100644 --- a/src/main/java/im/zhaojun/zfile/context/DriveContext.java +++ b/src/main/java/im/zhaojun/zfile/context/DriveContext.java @@ -12,35 +12,49 @@ import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** - * 驱动器上下文环境 + * 每个驱动器对应一个 Service, 其中初始化好了与对象存储的连接信息. + * 此驱动器上下文环境用户缓存每个 Service, 避免重复创建连接. * @author zhaojun */ @Component @DependsOn("springContextHolder") public class DriveContext implements ApplicationContextAware { + /** + * Map + * Map<驱动器 ID, 驱动器连接 Service> + */ private static Map drivesServiceMap = new ConcurrentHashMap<>(); - private static Map> storageTypeEnumClassMap = new ConcurrentHashMap<>(); - @Resource private DriveConfigService driveConfigService; + /** + * 项目启动时, 自动调用所有驱动器进行初始化. + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + List list = driveConfigService.list(); + for (DriveConfig driveConfig : list) { + init(driveConfig.getId()); + } + } + + /** * 初始化指定驱动器的 Service, 添加到上下文环境中. * * @param driveId * 驱动器 ID. */ - public void initDrive(Integer driveId) { + public void init(Integer driveId) { AbstractBaseFileService baseFileService = getBeanByDriveId(driveId); if (baseFileService != null) { baseFileService.init(driveId); @@ -57,7 +71,7 @@ public class DriveContext implements ApplicationContextAware { * * @return 驱动器对应的 Service */ - public AbstractBaseFileService getDriveService(Integer driveId) { + public AbstractBaseFileService get(Integer driveId) { return drivesServiceMap.get(driveId); } @@ -68,7 +82,7 @@ public class DriveContext implements ApplicationContextAware { * @param driveId * 驱动器 ID */ - public void destroyDrive(Integer driveId) { + public void destroy(Integer driveId) { drivesServiceMap.remove(driveId); } @@ -92,16 +106,4 @@ public class DriveContext implements ApplicationContextAware { return null; } - - /** - * 项目启动时, 自动调用所有驱动器进行初始化. - */ - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - List list = driveConfigService.list(); - for (DriveConfig driveConfig : list) { - initDrive(driveConfig.getId()); - } - } - } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/context/StorageTypeContext.java b/src/main/java/im/zhaojun/zfile/context/StorageTypeContext.java index 0b8ef1d..d8838fe 100644 --- a/src/main/java/im/zhaojun/zfile/context/StorageTypeContext.java +++ b/src/main/java/im/zhaojun/zfile/context/StorageTypeContext.java @@ -6,6 +6,7 @@ import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; + import java.util.Map; diff --git a/src/main/java/im/zhaojun/zfile/controller/PageController.java b/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java similarity index 93% rename from src/main/java/im/zhaojun/zfile/controller/PageController.java rename to src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java index 969933a..515d1e4 100644 --- a/src/main/java/im/zhaojun/zfile/controller/PageController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/DirectLinkController.java @@ -1,11 +1,11 @@ -package im.zhaojun.zfile.controller; +package im.zhaojun.zfile.controller.home; import cn.hutool.core.util.URLUtil; +import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.model.constant.ZFileConstant; import im.zhaojun.zfile.model.dto.FileItemDTO; import im.zhaojun.zfile.model.enums.FileTypeEnum; import im.zhaojun.zfile.service.base.AbstractBaseFileService; -import im.zhaojun.zfile.context.DriveContext; import org.springframework.stereotype.Controller; import org.springframework.util.AntPathMatcher; import org.springframework.web.bind.annotation.GetMapping; @@ -20,7 +20,7 @@ import java.util.Objects; * @author Zhao Jun */ @Controller -public class PageController { +public class DirectLinkController { @Resource private DriveContext driveContext; @@ -44,7 +44,7 @@ public class PageController { filePath = "/" + filePath; } - AbstractBaseFileService fileService = driveContext.getDriveService(driveId); + AbstractBaseFileService fileService = driveContext.get(driveId); FileItemDTO fileItem = fileService.getFileItem(filePath); String url = fileItem.getUrl(); @@ -67,4 +67,5 @@ public class PageController { return "redirect:" + url; } } -} + +} \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/controller/CommonController.java b/src/main/java/im/zhaojun/zfile/controller/home/FIleParseController.java similarity index 62% rename from src/main/java/im/zhaojun/zfile/controller/CommonController.java rename to src/main/java/im/zhaojun/zfile/controller/home/FIleParseController.java index b5f60e4..83bc87d 100644 --- a/src/main/java/im/zhaojun/zfile/controller/CommonController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/FIleParseController.java @@ -1,32 +1,19 @@ -package im.zhaojun.zfile.controller; +package im.zhaojun.zfile.controller.home; -import im.zhaojun.zfile.model.dto.ResultBean; -import im.zhaojun.zfile.model.enums.StorageTypeEnum; -import im.zhaojun.zfile.util.AudioHelper; +import im.zhaojun.zfile.model.support.ResultBean; +import im.zhaojun.zfile.util.AudioUtil; import im.zhaojun.zfile.util.HttpUtil; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** - * 公共 Controller + * 文件解析 Controller * @author zhaojun */ @RestController @RequestMapping("/common") -public class CommonController { - - - /** - * 返回系统支持的所有存储策略 - * - * @return 存储策略 - */ - @GetMapping("/support-strategy") - public ResultBean supportStrategy() { - return ResultBean.successData(StorageTypeEnum.values()); - } - +public class FIleParseController { /** * 获取文件内容, 仅限用于 txt, md, ini 等普通文本文件. @@ -52,7 +39,7 @@ public class CommonController { */ @GetMapping("/audio-info") public ResultBean getAudioInfo(String url) throws Exception { - return ResultBean.success(AudioHelper.getAudioInfo(url)); + return ResultBean.success(AudioUtil.getAudioInfo(url)); } } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/controller/FileController.java b/src/main/java/im/zhaojun/zfile/controller/home/FileController.java similarity index 92% rename from src/main/java/im/zhaojun/zfile/controller/FileController.java rename to src/main/java/im/zhaojun/zfile/controller/home/FileController.java index dc033c5..983b99e 100644 --- a/src/main/java/im/zhaojun/zfile/controller/FileController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/FileController.java @@ -1,14 +1,14 @@ -package im.zhaojun.zfile.controller; +package im.zhaojun.zfile.controller.home; +import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.model.constant.ZFileConstant; import im.zhaojun.zfile.model.dto.FileItemDTO; -import im.zhaojun.zfile.model.dto.ResultBean; import im.zhaojun.zfile.model.dto.SystemFrontConfigDTO; import im.zhaojun.zfile.model.support.FilePageModel; +import im.zhaojun.zfile.model.support.ResultBean; import im.zhaojun.zfile.service.DriveConfigService; import im.zhaojun.zfile.service.SystemConfigService; import im.zhaojun.zfile.service.base.AbstractBaseFileService; -import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.util.FileComparator; import im.zhaojun.zfile.util.HttpUtil; import im.zhaojun.zfile.util.StringUtils; @@ -83,8 +83,8 @@ public class FileController { @RequestParam(defaultValue = "/") String path, @RequestParam(required = false) String password, @RequestParam(defaultValue = "1") Integer page) throws Exception { - AbstractBaseFileService fileService = driveContext.getDriveService(driveId); - List fileItemList = fileService.fileList(StringUtils.removeDuplicateSeparator("/" + path + "/")); + AbstractBaseFileService fileService = driveContext.get(driveId); + List fileItemList = fileService.fileList(StringUtils.removeDuplicateSeparator(ZFileConstant.PATH_SEPARATOR + path + ZFileConstant.PATH_SEPARATOR)); for (FileItemDTO fileItemDTO : fileItemList) { if (ZFileConstant.PASSWORD_FILE_NAME.equals(fileItemDTO.getName())) { @@ -94,7 +94,7 @@ public class FileController { } catch (HttpClientErrorException httpClientErrorException) { log.debug("尝试重新获取密码文件缓存中链接后仍失败", httpClientErrorException); try { - String fullPath = StringUtils.removeDuplicateSeparator(fileItemDTO.getPath() + "/" + fileItemDTO.getName()); + String fullPath = StringUtils.removeDuplicateSeparator(fileItemDTO.getPath() + ZFileConstant.PATH_SEPARATOR + fileItemDTO.getName()); FileItemDTO fileItem = fileService.getFileItem(fullPath); expectedPasswordContent = HttpUtil.getTextContent(fileItem.getUrl()); } catch (Exception e) { @@ -128,8 +128,8 @@ public class FileController { public ResultBean getConfig(@PathVariable(name = "driveId") Integer driveId, String path) { SystemFrontConfigDTO systemConfig = systemConfigService.getSystemFrontConfig(driveId); - AbstractBaseFileService fileService = driveContext.getDriveService(driveId); - String fullPath = StringUtils.removeDuplicateSeparator(path + "/" + ZFileConstant.README_FILE_NAME); + AbstractBaseFileService fileService = driveContext.get(driveId); + String fullPath = StringUtils.removeDuplicateSeparator(path + ZFileConstant.PATH_SEPARATOR + ZFileConstant.README_FILE_NAME); try { FileItemDTO fileItem = fileService.getFileItem(fullPath); String readme = HttpUtil.getTextContent(fileItem.getUrl()); @@ -214,7 +214,8 @@ public class FileController { */ @GetMapping("/directlink/{driveId}") public ResultBean directlink(@PathVariable(name = "driveId") Integer driveId, String path) { - AbstractBaseFileService fileService = driveContext.getDriveService(driveId); + AbstractBaseFileService fileService = driveContext.get(driveId); return ResultBean.successData(fileService.getFileItem(path)); } -} + +} \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/controller/LocalController.java b/src/main/java/im/zhaojun/zfile/controller/home/LocalController.java similarity index 90% rename from src/main/java/im/zhaojun/zfile/controller/LocalController.java rename to src/main/java/im/zhaojun/zfile/controller/home/LocalController.java index 5c51395..ab09279 100644 --- a/src/main/java/im/zhaojun/zfile/controller/LocalController.java +++ b/src/main/java/im/zhaojun/zfile/controller/home/LocalController.java @@ -42,8 +42,8 @@ public class LocalController { String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); AntPathMatcher apm = new AntPathMatcher(); String filePath = apm.extractPathWithinPattern(bestMatchPattern, path); - LocalServiceImpl localService = (LocalServiceImpl) driveContext.getDriveService(driveId); - return FileUtil.export(new File(StringUtils.concatPath(localService.getFilePath(), filePath))); + LocalServiceImpl localService = (LocalServiceImpl) driveContext.get(driveId); + return FileUtil.export(new File(StringUtils.removeDuplicateSeparator(localService.getFilePath() + ZFileConstant.PATH_SEPARATOR + filePath))); } } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/controller/InstallController.java b/src/main/java/im/zhaojun/zfile/controller/install/InstallController.java similarity index 94% rename from src/main/java/im/zhaojun/zfile/controller/InstallController.java rename to src/main/java/im/zhaojun/zfile/controller/install/InstallController.java index 7384077..565a5a5 100644 --- a/src/main/java/im/zhaojun/zfile/controller/InstallController.java +++ b/src/main/java/im/zhaojun/zfile/controller/install/InstallController.java @@ -1,9 +1,9 @@ -package im.zhaojun.zfile.controller; +package im.zhaojun.zfile.controller.install; import cn.hutool.crypto.SecureUtil; import im.zhaojun.zfile.controller.admin.AdminController; -import im.zhaojun.zfile.model.dto.ResultBean; import im.zhaojun.zfile.model.dto.SystemConfigDTO; +import im.zhaojun.zfile.model.support.ResultBean; import im.zhaojun.zfile.service.StorageConfigService; import im.zhaojun.zfile.service.SystemConfigService; import org.springframework.util.StringUtils; diff --git a/src/main/java/im/zhaojun/zfile/controller/OneDriveController.java b/src/main/java/im/zhaojun/zfile/controller/onedrive/OneDriveCallbackController.java similarity index 93% rename from src/main/java/im/zhaojun/zfile/controller/OneDriveController.java rename to src/main/java/im/zhaojun/zfile/controller/onedrive/OneDriveCallbackController.java index 3f5c0e6..e5edb14 100644 --- a/src/main/java/im/zhaojun/zfile/controller/OneDriveController.java +++ b/src/main/java/im/zhaojun/zfile/controller/onedrive/OneDriveCallbackController.java @@ -1,4 +1,4 @@ -package im.zhaojun.zfile.controller; +package im.zhaojun.zfile.controller.onedrive; import im.zhaojun.zfile.model.support.OneDriveToken; import im.zhaojun.zfile.service.impl.OneDriveChinaServiceImpl; @@ -15,7 +15,7 @@ import javax.annotation.Resource; */ @Controller @RequestMapping("/onedrive") -public class OneDriveController { +public class OneDriveCallbackController { @Resource private OneDriveServiceImpl oneDriveServiceImpl; diff --git a/src/main/java/im/zhaojun/zfile/model/dto/AudioInfoDTO.java b/src/main/java/im/zhaojun/zfile/model/dto/AudioInfoDTO.java index 15123b6..dcf8577 100644 --- a/src/main/java/im/zhaojun/zfile/model/dto/AudioInfoDTO.java +++ b/src/main/java/im/zhaojun/zfile/model/dto/AudioInfoDTO.java @@ -24,4 +24,4 @@ public class AudioInfoDTO { return audioInfoDTO; } -} +} \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/model/enums/FileTypeEnum.java b/src/main/java/im/zhaojun/zfile/model/enums/FileTypeEnum.java index 4cab814..4f66a55 100644 --- a/src/main/java/im/zhaojun/zfile/model/enums/FileTypeEnum.java +++ b/src/main/java/im/zhaojun/zfile/model/enums/FileTypeEnum.java @@ -28,4 +28,5 @@ public enum FileTypeEnum { public void setValue(String value) { this.value = value; } + } \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/model/enums/StorageTypeEnum.java b/src/main/java/im/zhaojun/zfile/model/enums/StorageTypeEnum.java index 3221609..ee3da78 100644 --- a/src/main/java/im/zhaojun/zfile/model/enums/StorageTypeEnum.java +++ b/src/main/java/im/zhaojun/zfile/model/enums/StorageTypeEnum.java @@ -63,4 +63,4 @@ public enum StorageTypeEnum { return enumMap.get(value.toLowerCase()); } -} +} \ No newline at end of file diff --git a/src/main/java/im/zhaojun/zfile/model/dto/ResultBean.java b/src/main/java/im/zhaojun/zfile/model/support/ResultBean.java similarity index 98% rename from src/main/java/im/zhaojun/zfile/model/dto/ResultBean.java rename to src/main/java/im/zhaojun/zfile/model/support/ResultBean.java index e0ffab3..bf66380 100644 --- a/src/main/java/im/zhaojun/zfile/model/dto/ResultBean.java +++ b/src/main/java/im/zhaojun/zfile/model/support/ResultBean.java @@ -1,4 +1,4 @@ -package im.zhaojun.zfile.model.dto; +package im.zhaojun.zfile.model.support; import java.io.Serializable; diff --git a/src/main/java/im/zhaojun/zfile/schedule/OneDriveTokenRefreshSchedule.java b/src/main/java/im/zhaojun/zfile/schedule/OneDriveTokenRefreshSchedule.java index 0788c06..e392a03 100644 --- a/src/main/java/im/zhaojun/zfile/schedule/OneDriveTokenRefreshSchedule.java +++ b/src/main/java/im/zhaojun/zfile/schedule/OneDriveTokenRefreshSchedule.java @@ -1,12 +1,12 @@ package im.zhaojun.zfile.schedule; +import im.zhaojun.zfile.context.DriveContext; import im.zhaojun.zfile.model.entity.DriveConfig; import im.zhaojun.zfile.model.enums.StorageTypeEnum; import im.zhaojun.zfile.service.DriveConfigService; import im.zhaojun.zfile.service.base.AbstractOneDriveServiceBase; import im.zhaojun.zfile.service.impl.OneDriveChinaServiceImpl; import im.zhaojun.zfile.service.impl.OneDriveServiceImpl; -import im.zhaojun.zfile.context.DriveContext; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; @@ -54,7 +54,7 @@ public class OneDriveTokenRefreshSchedule { String name = driveConfig.getName(); try { - AbstractOneDriveServiceBase driveService = (AbstractOneDriveServiceBase) driveContext.getDriveService(driveConfig.getId()); + AbstractOneDriveServiceBase driveService = (AbstractOneDriveServiceBase) driveContext.get(driveConfig.getId()); driveService.refreshOneDriveToken(); log.info("刷新驱动器 {}, {} key 时间: {}", name, storageType.getDescription(), LocalDateTime.now()); } catch (Exception e) { diff --git a/src/main/java/im/zhaojun/zfile/security/MySecurityConfig.java b/src/main/java/im/zhaojun/zfile/security/MySecurityConfig.java index ac7f2dd..2723ac9 100644 --- a/src/main/java/im/zhaojun/zfile/security/MySecurityConfig.java +++ b/src/main/java/im/zhaojun/zfile/security/MySecurityConfig.java @@ -1,7 +1,7 @@ package im.zhaojun.zfile.security; import com.fasterxml.jackson.databind.ObjectMapper; -import im.zhaojun.zfile.model.dto.ResultBean; +import im.zhaojun.zfile.model.support.ResultBean; import org.springframework.context.annotation.Bean; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.BadCredentialsException; diff --git a/src/main/java/im/zhaojun/zfile/service/DriveConfigService.java b/src/main/java/im/zhaojun/zfile/service/DriveConfigService.java index 69676b8..9a66f3e 100644 --- a/src/main/java/im/zhaojun/zfile/service/DriveConfigService.java +++ b/src/main/java/im/zhaojun/zfile/service/DriveConfigService.java @@ -181,9 +181,9 @@ public class DriveConfigService { } storageConfigRepository.saveAll(storageConfigList); - driveContext.initDrive(driveConfig.getId()); + driveContext.init(driveConfig.getId()); - AbstractBaseFileService driveService = driveContext.getDriveService(driveConfig.getId()); + AbstractBaseFileService driveService = driveContext.get(driveConfig.getId()); if (driveService.getIsUnInitialized()) { throw new InitializeException("初始化异常, 请检查配置是否正确."); } @@ -200,7 +200,7 @@ public class DriveConfigService { public void deleteById(Integer id) { driverConfigRepository.deleteById(id); storageConfigRepository.deleteByDriveId(id); - driveContext.destroyDrive(id); + driveContext.destroy(id); } @@ -282,7 +282,7 @@ public class DriveConfigService { */ public void refreshCache(Integer driveId, String key) throws Exception { zFileCache.remove(driveId, key); - AbstractBaseFileService baseFileService = driveContext.getDriveService(driveId); + AbstractBaseFileService baseFileService = driveContext.get(driveId); baseFileService.fileList(key); } diff --git a/src/main/java/im/zhaojun/zfile/service/base/AbstractBaseFileService.java b/src/main/java/im/zhaojun/zfile/service/base/AbstractBaseFileService.java index 88bca56..e0168e2 100644 --- a/src/main/java/im/zhaojun/zfile/service/base/AbstractBaseFileService.java +++ b/src/main/java/im/zhaojun/zfile/service/base/AbstractBaseFileService.java @@ -6,7 +6,6 @@ import im.zhaojun.zfile.model.entity.StorageConfig; import im.zhaojun.zfile.model.enums.StorageTypeEnum; import im.zhaojun.zfile.service.SystemConfigService; import lombok.extern.slf4j.Slf4j; -import org.springframework.aop.framework.AopContext; import org.springframework.beans.factory.annotation.Value; import javax.annotation.Resource; @@ -120,7 +119,7 @@ public abstract class AbstractBaseFileService implements BaseFileService { /** - * 获取初始化当前存储策略, 所需要的参数信息 (表单填写) + * 获取初始化当前存储策略, 所需要的参数信息 (用于表单填写) * * @return 初始化所需的参数列表 */ diff --git a/src/main/java/im/zhaojun/zfile/service/base/AbstractOneDriveServiceBase.java b/src/main/java/im/zhaojun/zfile/service/base/AbstractOneDriveServiceBase.java index c2e0bf0..aab9e31 100644 --- a/src/main/java/im/zhaojun/zfile/service/base/AbstractOneDriveServiceBase.java +++ b/src/main/java/im/zhaojun/zfile/service/base/AbstractOneDriveServiceBase.java @@ -20,7 +20,6 @@ import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; diff --git a/src/main/java/im/zhaojun/zfile/service/base/AbstractS3BaseFileService.java b/src/main/java/im/zhaojun/zfile/service/base/AbstractS3BaseFileService.java index b4ed994..69bcbd0 100644 --- a/src/main/java/im/zhaojun/zfile/service/base/AbstractS3BaseFileService.java +++ b/src/main/java/im/zhaojun/zfile/service/base/AbstractS3BaseFileService.java @@ -7,6 +7,7 @@ import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.S3ObjectSummary; import im.zhaojun.zfile.exception.NotExistFileException; +import im.zhaojun.zfile.model.constant.ZFileConstant; import im.zhaojun.zfile.model.dto.FileItemDTO; import im.zhaojun.zfile.model.enums.FileTypeEnum; import im.zhaojun.zfile.service.StorageConfigService; @@ -94,7 +95,7 @@ public abstract class AbstractS3BaseFileService extends AbstractBaseFileService */ public String s3ObjectUrl(String path) { basePath = basePath == null ? "" : basePath; - String fullPath = StringUtils.removeFirstSeparator(StringUtils.removeDuplicateSeparator(basePath + "/" + path)); + String fullPath = StringUtils.removeFirstSeparator(StringUtils.removeDuplicateSeparator(basePath + ZFileConstant.PATH_SEPARATOR + path)); // 如果不是私有空间, 且指定了加速域名, 则直接返回下载地址. if (BooleanUtil.isFalse(isPrivate) && StringUtils.isNotNullOrEmpty(domain)) { diff --git a/src/main/java/im/zhaojun/zfile/service/impl/LocalServiceImpl.java b/src/main/java/im/zhaojun/zfile/service/impl/LocalServiceImpl.java index 76d1001..0c56c48 100644 --- a/src/main/java/im/zhaojun/zfile/service/impl/LocalServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/service/impl/LocalServiceImpl.java @@ -3,6 +3,7 @@ package im.zhaojun.zfile.service.impl; import im.zhaojun.zfile.exception.NotExistFileException; import im.zhaojun.zfile.model.constant.StorageConfigConstant; import im.zhaojun.zfile.model.constant.SystemConfigConstant; +import im.zhaojun.zfile.model.constant.ZFileConstant; import im.zhaojun.zfile.model.dto.FileItemDTO; import im.zhaojun.zfile.model.entity.StorageConfig; import im.zhaojun.zfile.model.entity.SystemConfig; @@ -63,6 +64,7 @@ public class LocalServiceImpl extends AbstractBaseFileService implements BaseFil } } + @Override public List fileList(String path) throws FileNotFoundException { List fileItemList = new ArrayList<>(); @@ -99,7 +101,7 @@ public class LocalServiceImpl extends AbstractBaseFileService implements BaseFil @Override public String getDownloadUrl(String path) { SystemConfig usernameConfig = systemConfigRepository.findByKey(SystemConfigConstant.DOMAIN); - return StringUtils.removeDuplicateSeparator(usernameConfig.getValue() + "/file/" + driveId + "/" + path); + return StringUtils.removeDuplicateSeparator(usernameConfig.getValue() + "/file/" + driveId + ZFileConstant.PATH_SEPARATOR + path); } public String getFilePath() { diff --git a/src/main/java/im/zhaojun/zfile/service/impl/UpYunServiceImpl.java b/src/main/java/im/zhaojun/zfile/service/impl/UpYunServiceImpl.java index 1f05649..374a3bb 100644 --- a/src/main/java/im/zhaojun/zfile/service/impl/UpYunServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/service/impl/UpYunServiceImpl.java @@ -6,6 +6,7 @@ import com.UpYun; import com.upyun.UpException; import im.zhaojun.zfile.exception.NotExistFileException; import im.zhaojun.zfile.model.constant.StorageConfigConstant; +import im.zhaojun.zfile.model.constant.ZFileConstant; import im.zhaojun.zfile.model.dto.FileItemDTO; import im.zhaojun.zfile.model.entity.StorageConfig; import im.zhaojun.zfile.model.enums.FileTypeEnum; @@ -122,7 +123,7 @@ public class UpYunServiceImpl extends AbstractBaseFileService implements BaseFil int lastDelimiterIndex = path.lastIndexOf("/"); String name = path.substring(lastDelimiterIndex + 1); - Map fileInfo = upYun.getFileInfo(StringUtils.removeDuplicateSeparator(basePath + "/" + path)); + Map fileInfo = upYun.getFileInfo(StringUtils.removeDuplicateSeparator(basePath + ZFileConstant.PATH_SEPARATOR + path)); if (fileInfo == null) { throw new NotExistFileException(); @@ -138,7 +139,7 @@ public class UpYunServiceImpl extends AbstractBaseFileService implements BaseFil fileItemDTO.setType(FileTypeEnum.FOLDER); } else { fileItemDTO.setType(FileTypeEnum.FILE); - fileItemDTO.setUrl(getDownloadUrl(StringUtils.removeDuplicateSeparator(basePath + "/" + path))); + fileItemDTO.setUrl(getDownloadUrl(StringUtils.removeDuplicateSeparator(basePath + ZFileConstant.PATH_SEPARATOR + path))); } return fileItemDTO; } catch (IOException | UpException e) { diff --git a/src/main/java/im/zhaojun/zfile/util/AudioHelper.java b/src/main/java/im/zhaojun/zfile/util/AudioUtil.java similarity index 98% rename from src/main/java/im/zhaojun/zfile/util/AudioHelper.java rename to src/main/java/im/zhaojun/zfile/util/AudioUtil.java index 1466775..c67b087 100644 --- a/src/main/java/im/zhaojun/zfile/util/AudioHelper.java +++ b/src/main/java/im/zhaojun/zfile/util/AudioUtil.java @@ -24,9 +24,9 @@ import java.net.URL; * 音频解析工具类 * @author zhaojun */ -public class AudioHelper { +public class AudioUtil { - private static final Logger log = LoggerFactory.getLogger(AudioHelper.class); + private static final Logger log = LoggerFactory.getLogger(AudioUtil.class); public static AudioInfoDTO getAudioInfo(String url) throws Exception { String query = new URL(URLUtil.decode(url)).getQuery(); diff --git a/src/main/java/im/zhaojun/zfile/util/StringUtils.java b/src/main/java/im/zhaojun/zfile/util/StringUtils.java index 074e241..686adb9 100644 --- a/src/main/java/im/zhaojun/zfile/util/StringUtils.java +++ b/src/main/java/im/zhaojun/zfile/util/StringUtils.java @@ -1,6 +1,7 @@ package im.zhaojun.zfile.util; import cn.hutool.core.util.ObjectUtil; +import im.zhaojun.zfile.model.constant.ZFileConstant; /** * @author zhaojun @@ -98,6 +99,6 @@ public class StringUtils { public static String getFullPath(String basePath, String path) { basePath = ObjectUtil.defaultIfNull(basePath, ""); path = ObjectUtil.defaultIfNull(path, ""); - return StringUtils.removeDuplicateSeparator(basePath + "/" + path); + return StringUtils.removeDuplicateSeparator(basePath + ZFileConstant.PATH_SEPARATOR + path); } }