🔊 优化日志输出, 完善日志信息, 便于调试.

This commit is contained in:
zhaojun1998
2020-06-26 21:35:08 +08:00
parent c1d29a46f5
commit 766a047ee1
33 changed files with 143 additions and 141 deletions

View File

@@ -27,18 +27,29 @@ public class MyTimedCache<K, V> extends TimedCache<K, V> {
@Override
protected void onRemove(K key, V cachedObject) {
log.debug("尝试刷新缓存: " + key);
if (driveContext == null) {
driveContext = SpringContextHolder.getBean(DriveContext.class);
}
DriveCacheKey cacheKey = (DriveCacheKey) key;
AbstractBaseFileService baseFileService = driveContext.get(cacheKey.getDriveId());
if (log.isDebugEnabled()) {
log.debug("尝试刷新缓存: {}", cacheKey);
}
if (baseFileService == null) {
log.error("尝试刷新缓存: {}, 时出现异常, 驱动器已不存在", cacheKey);
return;
}
try {
baseFileService.fileList(cacheKey.getKey());
} catch (Exception e) {
log.error("尝试刷新驱动器 {} 的 {} 失败, ", cacheKey.getDriveId(), cacheKey.getKey());
log.error("尝试刷新缓存 {} 失败", cacheKey);
e.printStackTrace();
}
}
}

View File

@@ -7,6 +7,7 @@ import im.zhaojun.zfile.model.dto.FileItemDTO;
import im.zhaojun.zfile.model.dto.SystemConfigDTO;
import im.zhaojun.zfile.model.entity.DriveConfig;
import im.zhaojun.zfile.repository.DriverConfigRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -26,8 +27,12 @@ import java.util.concurrent.ConcurrentMap;
* @author zhaojun
*/
@Component
@Slf4j
public class ZFileCache {
@Resource
private DriverConfigRepository driverConfigRepository;
/**
* 缓存过期时间
*/
@@ -40,7 +45,6 @@ public class ZFileCache {
@Value("${zfile.cache.auto-refresh.interval}")
private long autoRefreshInterval;
/**
* 文件/文件对象缓存.
*
@@ -58,9 +62,6 @@ public class ZFileCache {
*/
private SystemConfigDTO systemConfigCache;
@Resource
private DriverConfigRepository driverConfigRepository;
/**
* 写入缓存
@@ -102,6 +103,9 @@ public class ZFileCache {
* 驱动器 ID
*/
public void clear(Integer driveId) {
if (log.isDebugEnabled()) {
log.debug("清空驱动器所有缓存, driveId: {}", driveId);
}
getCacheByDriveId(driveId).clear();
}
@@ -286,12 +290,15 @@ public class ZFileCache {
/**
* 开启缓存自动刷新, 仅当数据库设置为开启时, 才会真正开启缓存自动刷新.
* 开启缓存自动刷新
*
* @param driveId
* 驱动器 ID
*/
public void startAutoCacheRefresh(Integer driveId) {
if (log.isDebugEnabled()) {
log.debug("开启缓存自动刷新 driveId: {}", driveId);
}
DriveConfig driveConfig = driverConfigRepository.findById(driveId).get();
Boolean autoRefreshCache = driveConfig.getAutoRefreshCache();
if (autoRefreshCache != null && autoRefreshCache) {
@@ -312,6 +319,9 @@ public class ZFileCache {
* 驱动器 ID
*/
public void stopAutoCacheRefresh(Integer driveId) {
if (log.isDebugEnabled()) {
log.debug("停止缓存自动刷新 driveId: {}", driveId);
}
MyTimedCache<DriveCacheKey, List<FileItemDTO>> driveCache = drivesCache.get(driveId);
if (driveCache != null) {
driveCache.cancelPruneSchedule();

View File

@@ -31,4 +31,4 @@ public class ZFileConfiguration {
return restTemplate;
}
}
}

View File

@@ -1,5 +1,6 @@
package im.zhaojun.zfile.context;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.exception.InvalidDriveException;
import im.zhaojun.zfile.model.entity.DriveConfig;
import im.zhaojun.zfile.model.enums.StorageTypeEnum;
@@ -40,7 +41,7 @@ public class DriveContext implements ApplicationContextAware {
/**
* 项目启动时, 自动调用所有驱动器进行初始化.
* 项目启动时, 自动调用数据库已存储的所有驱动器进行初始化.
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -48,8 +49,10 @@ public class DriveContext implements ApplicationContextAware {
for (DriveConfig driveConfig : list) {
try {
init(driveConfig.getId());
log.info("启动时初始化驱动器成功, 驱动器信息: {}", JSON.toJSONString(driveConfig));
throw new RuntimeException("xx");
} catch (Exception e) {
log.debug(driveConfig.getName() + " 初始化异常, 已跳过", e);
log.error("启动时初始化驱动器失败, 驱动器信息: {}", JSON.toJSONString(driveConfig), e);
}
}
}
@@ -64,7 +67,13 @@ public class DriveContext implements ApplicationContextAware {
public void init(Integer driveId) {
AbstractBaseFileService baseFileService = getBeanByDriveId(driveId);
if (baseFileService != null) {
if (log.isDebugEnabled()) {
log.debug("尝试初始化驱动器, driveId: {}", driveId);
}
baseFileService.init(driveId);
if (log.isDebugEnabled()) {
log.debug("初始化驱动器成功, driveId: {}", driveId);
}
drivesServiceMap.put(driveId, baseFileService);
}
}
@@ -94,6 +103,9 @@ public class DriveContext implements ApplicationContextAware {
* 驱动器 ID
*/
public void destroy(Integer driveId) {
if (log.isDebugEnabled()) {
log.debug("清理驱动器上下文对象, driveId: {}", driveId);
}
drivesServiceMap.remove(driveId);
}

View File

@@ -3,7 +3,6 @@ package im.zhaojun.zfile.controller.admin;
import im.zhaojun.zfile.model.dto.SystemConfigDTO;
import im.zhaojun.zfile.model.support.ResultBean;
import im.zhaojun.zfile.service.SystemConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -17,7 +16,6 @@ import javax.annotation.Resource;
*/
@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {
@Resource

View File

@@ -4,7 +4,6 @@ import im.zhaojun.zfile.model.dto.DriveConfigDTO;
import im.zhaojun.zfile.model.entity.DriveConfig;
import im.zhaojun.zfile.model.support.ResultBean;
import im.zhaojun.zfile.service.DriveConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -22,7 +21,6 @@ import java.util.List;
*/
@RestController
@RequestMapping("/admin")
@Slf4j
public class DriveController {
@Resource

View File

@@ -27,6 +27,9 @@ public class LogController {
*/
@GetMapping("/log")
public ResponseEntity<Object> downloadLog(HttpServletResponse response) {
if (log.isDebugEnabled()) {
log.debug("下载诊断日志");
}
String userHome = System.getProperty("user.home");
File fileZip = ZipUtil.zip(userHome + "/.zfile/logs");
String currentDate = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");

View File

@@ -5,7 +5,6 @@ import im.zhaojun.zfile.model.entity.StorageConfig;
import im.zhaojun.zfile.model.enums.StorageTypeEnum;
import im.zhaojun.zfile.model.support.ResultBean;
import im.zhaojun.zfile.service.base.AbstractBaseFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -18,7 +17,6 @@ import java.util.List;
*/
@RestController
@RequestMapping("/admin")
@Slf4j
public class MateDataController {
/**

View File

@@ -2,7 +2,6 @@ package im.zhaojun.zfile.controller.admin;
import im.zhaojun.zfile.model.support.ResultBean;
import im.zhaojun.zfile.model.support.SystemMonitorInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -13,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/admin")
@Slf4j
public class MonitorController {

View File

@@ -1,5 +1,6 @@
package im.zhaojun.zfile.controller.home;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.context.DriveContext;
import im.zhaojun.zfile.model.constant.ZFileConstant;
import im.zhaojun.zfile.model.dto.FileItemDTO;
@@ -84,7 +85,8 @@ public class FileController {
@RequestParam(required = false) String password,
@RequestParam(defaultValue = "1") Integer page) throws Exception {
AbstractBaseFileService fileService = driveContext.get(driveId);
List<FileItemDTO> fileItemList = fileService.fileList(StringUtils.removeDuplicateSeparator(ZFileConstant.PATH_SEPARATOR + path + ZFileConstant.PATH_SEPARATOR));
List<FileItemDTO> fileItemList =
fileService.fileList(StringUtils.removeDuplicateSeparator(ZFileConstant.PATH_SEPARATOR + path + ZFileConstant.PATH_SEPARATOR));
for (FileItemDTO fileItemDTO : fileItemList) {
if (ZFileConstant.PASSWORD_FILE_NAME.equals(fileItemDTO.getName())) {
@@ -92,13 +94,14 @@ public class FileController {
try {
expectedPasswordContent = HttpUtil.getTextContent(fileItemDTO.getUrl());
} catch (HttpClientErrorException httpClientErrorException) {
log.debug("尝试重新获取密码文件缓存中链接后仍失败", httpClientErrorException);
log.error("尝试重新获取密码文件缓存中链接后仍失败, driveId: {}, path: {}, inputPassword: {}, passwordFile:{} ",
driveId, path, password, JSON.toJSONString(fileItemDTO), httpClientErrorException);
try {
String fullPath = StringUtils.removeDuplicateSeparator(fileItemDTO.getPath() + ZFileConstant.PATH_SEPARATOR + fileItemDTO.getName());
FileItemDTO fileItem = fileService.getFileItem(fullPath);
expectedPasswordContent = HttpUtil.getTextContent(fileItem.getUrl());
} catch (Exception e) {
log.debug("尝试重新获取密码文件链接后仍失败, 已暂时取消密码", e);
log.error("尝试重新获取密码文件链接后仍失败, 已暂时取消密码", e);
break;
}
}
@@ -130,12 +133,13 @@ public class FileController {
AbstractBaseFileService fileService = driveContext.get(driveId);
String fullPath = StringUtils.removeDuplicateSeparator(path + ZFileConstant.PATH_SEPARATOR + ZFileConstant.README_FILE_NAME);
FileItemDTO fileItem = null;
try {
FileItemDTO fileItem = fileService.getFileItem(fullPath);
fileItem = fileService.getFileItem(fullPath);
String readme = HttpUtil.getTextContent(fileItem.getUrl());
systemConfig.setReadme(readme);
} catch (Exception e) {
// ignore
log.error("获取 README 文件异常, fullPath: {}, fileItem: {}", fullPath, JSON.toJSONString(fileItem), e);
}
return ResultBean.successData(systemConfig);

View File

@@ -38,8 +38,7 @@ public class LocalController {
@GetMapping("/file/{driveId}/**")
@ResponseBody
public ResponseEntity<Object> downAttachment(@PathVariable("driveId") Integer driveId, final HttpServletRequest request) {
String path = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
AntPathMatcher apm = new AntPathMatcher();
String filePath = apm.extractPathWithinPattern(bestMatchPattern, path);

View File

@@ -20,17 +20,6 @@ public class GlobleExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobleExceptionHandler.class);
@ExceptionHandler
@ResponseBody
@ResponseStatus
public ResultBean searchDisableExceptionHandler(StorageStrategyUninitializedException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
return ResultBean.error(e.getMessage());
}
/**
* 不存在的文件异常
*/
@@ -76,15 +65,11 @@ public class GlobleExceptionHandler {
}
@ExceptionHandler
@ResponseBody
@ResponseStatus(code= HttpStatus.INTERNAL_SERVER_ERROR)
public ResultBean searchDisableExceptionHandler(Exception e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
log.error(e.getMessage(), e);
if (e.getClass() == Exception.class) {
return ResultBean.error("系统异常, 请联系管理员");

View File

@@ -0,0 +1,29 @@
package im.zhaojun.zfile.exception;
/**
* 刷新缓存时出现的异常信息
*
* @author zhaojun
*/
public class RefreshCacheException extends RuntimeException {
public RefreshCacheException() {
}
public RefreshCacheException(String message) {
super(message);
}
public RefreshCacheException(String message, Throwable cause) {
super(message, cause);
}
public RefreshCacheException(Throwable cause) {
super(cause);
}
public RefreshCacheException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -26,4 +26,5 @@ public class StorageStrategyUninitializedException extends RuntimeException {
public StorageStrategyUninitializedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
}

View File

@@ -1,5 +1,6 @@
package im.zhaojun.zfile.schedule;
import com.alibaba.fastjson.JSON;
import im.zhaojun.zfile.context.DriveContext;
import im.zhaojun.zfile.model.entity.DriveConfig;
import im.zhaojun.zfile.model.enums.StorageTypeEnum;
@@ -11,7 +12,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -48,15 +48,15 @@ public class OneDriveTokenRefreshSchedule {
try {
AbstractOneDriveServiceBase driveService = (AbstractOneDriveServiceBase) driveContext.get(driveConfig.getId());
driveService.refreshOneDriveToken();
log.info("刷新驱动器 {}, {} key 时间: {}", name, storageType.getDescription(), LocalDateTime.now());
log.info("尝试刷新 OneDrive Token, DriveInfo: {}", JSON.toJSONString(driveConfig));
} catch (Exception e) {
log.debug("刷新驱动器 " + name + " Token 失败.", e);
log.error("刷新 OneDrive Token 失败, DriveInfo: {}", JSON.toJSONString(driveConfig), e);
}
});
} catch (Throwable e) {
log.debug("尝试调用 OneDrive 自动刷新 AccessToken 定时任务出现未知异常", e);
log.error("尝试调用 OneDrive 自动刷新 AccessToken 定时任务出现未知异常", e);
}
}

View File

@@ -101,9 +101,7 @@ public class DriveConfigService {
declaredField.set(storageStrategyConfig, value);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
if (log.isDebugEnabled()) {
log.debug("通过反射, 将字段 {" + key + "}注入 DriveConfigDTO 时出现异常:", e);
}
log.error("通过反射, 将字段 {} 注入 DriveConfigDTO 时出现异常:", key, e);
}
}
@@ -142,12 +140,6 @@ public class DriveConfigService {
BeanUtils.copyProperties(driveConfigDTO, driveConfig);
driverConfigRepository.save(driveConfig);
if (driveConfig.getAutoRefreshCache()) {
startAutoCacheRefresh(driveConfig.getId());
} else {
stopAutoCacheRefresh(driveConfig.getId());
}
// 保存存储策略设置.
StorageStrategyConfig storageStrategyConfig = driveConfigDTO.getStorageStrategyConfig();
@@ -172,9 +164,7 @@ public class DriveConfigService {
storageConfig.setType(storageType);
storageConfig.setDriveId(driveConfig.getId());
} catch (IllegalAccessException | NoSuchFieldException e) {
if (log.isDebugEnabled()) {
log.debug("通过反射, 从 StorageStrategyConfig 中获取字段 {" + key + "} 时出现异常:", e);
}
log.error("通过反射, 从 StorageStrategyConfig 中获取字段 {} 时出现异常:", key, e);
}
}
@@ -186,6 +176,13 @@ public class DriveConfigService {
if (driveService.getIsUnInitialized()) {
throw new InitializeDriveException("初始化异常, 请检查配置是否正确.");
}
if (driveConfig.getAutoRefreshCache()) {
startAutoCacheRefresh(driveConfig.getId());
} else if (updateFlag){
stopAutoCacheRefresh(driveConfig.getId());
}
}
@@ -197,9 +194,20 @@ public class DriveConfigService {
*/
@Transactional(rollbackFor = Exception.class)
public void deleteById(Integer id) {
if (log.isDebugEnabled()) {
log.debug("尝试删除驱动器, driveId: {}", id);
}
DriveConfig driveConfig = driverConfigRepository.getOne(id);
driverConfigRepository.deleteById(id);
storageConfigRepository.deleteByDriveId(id);
if (driveConfig.getEnableCache()) {
zFileCache.stopAutoCacheRefresh(id);
zFileCache.clear(id);
}
driveContext.destroy(id);
if (log.isDebugEnabled()) {
log.debug("尝试删除驱动器成功, 已清理相关数据, driveId: {}", id);
}
}
@@ -267,7 +275,6 @@ public class DriveConfigService {
}
/**
* 刷新指定 key 的缓存:
* 1. 清空此 key 的缓存.
@@ -280,15 +287,17 @@ public class DriveConfigService {
* 缓存 key (文件夹名称)
*/
public void refreshCache(Integer driveId, String key) throws Exception {
if (log.isDebugEnabled()) {
log.debug("手动刷新缓存 driveId: {}, key: {}", driveId, key);
}
zFileCache.remove(driveId, key);
AbstractBaseFileService baseFileService = driveContext.get(driveId);
baseFileService.fileList(key);
}
/**
* 开启缓存自动刷新, 仅当数据库设置为开启时, 才会真正开启缓存自动刷新.
* 开启缓存自动刷新
*
* @param driveId
* 驱动器 ID
@@ -324,5 +333,4 @@ public class DriveConfigService {
zFileCache.clear(driveId);
}
}

View File

@@ -61,9 +61,7 @@ public class SystemConfigService {
Object convertVal = Convert.convert(field.getType(), strVal);
field.set(systemConfigDTO, convertVal);
} catch (NoSuchFieldException | IllegalAccessException e) {
if (log.isDebugEnabled()) {
log.debug("通过反射, 将字段 {" + key + "}注入 SystemConfigDTO 时出现异常:", e);
}
log.error("通过反射, 将字段 {} 注入 SystemConfigDTO 时出现异常:", key, e);
}
}
@@ -93,9 +91,7 @@ public class SystemConfigService {
try {
val = field.get(systemConfigDTO);
} catch (IllegalAccessException e) {
if (log.isDebugEnabled()) {
log.debug("通过反射, 从 SystemConfigDTO 获取字段 {" + key + "} 时出现异常:", e);
}
log.error("通过反射, 从 SystemConfigDTO 获取字段 {} 时出现异常:", key, e);
}
if (val != null) {

View File

@@ -1,69 +0,0 @@
// package im.zhaojun.zfile.service;
//
// import im.zhaojun.zfile.model.constant.ZFileConstant;
// import im.zhaojun.zfile.model.dto.FileItemDTO;
// import im.zhaojun.zfile.model.dto.SiteConfigDTO;
// import im.zhaojun.zfile.model.enums.StorageTypeEnum;
// import im.zhaojun.zfile.service.base.AbstractBaseFileService;
// import im.zhaojun.zfile.context.DriveContext;
// import im.zhaojun.zfile.util.HttpUtil;
// import im.zhaojun.zfile.util.StringUtils;
// import lombok.extern.slf4j.Slf4j;
// import org.springframework.stereotype.Service;
// import org.springframework.web.client.HttpClientErrorException;
//
// import javax.annotation.Resource;
// import java.util.ArrayList;
// import java.util.List;
// import java.util.Objects;
//
// /**
// * @author zhaojun
// */
// @Slf4j
// @Service
// public class SystemService {
//
// @Resource
// private DriveContext driveContext;
//
// /**
// * 构建指定路径下标题, 页面文档信息
// * @param path 路径
// */
// public SiteConfigDTO getConfig(Integer driveId, String path) throws Exception {
//
// SiteConfigDTO siteConfigDTO = new SiteConfigDTO();
//
// AbstractBaseFileService fileService = driveContext.getDriveService(driveId);
//
// List<FileItemDTO> fileItemList;
//
// if (Objects.equals(fileService.getStorageTypeEnum(), StorageTypeEnum.FTP)) {
// fileItemList = new ArrayList<>();
// } else {
// fileItemList = fileService.fileList(path);
// }
//
// for (FileItemDTO fileItemDTO : fileItemList) {
// if (ZFileConstant.README_FILE_NAME.equalsIgnoreCase(fileItemDTO.getName())) {
// String textContent = null;
// try {
// textContent = HttpUtil.getTextContent(fileItemDTO.getUrl());
// } catch (HttpClientErrorException httpClientErrorException) {
// log.debug("尝试重新获取文档区缓存中链接后仍失败", httpClientErrorException);
// try {
// String fullPath = StringUtils.removeDuplicateSeparator(fileItemDTO.getPath() + "/" + fileItemDTO.getName());
// FileItemDTO fileItem = fileService.getFileItem(fullPath);
// textContent = HttpUtil.getTextContent(fileItem.getUrl());
// } catch (Exception e) {
// log.debug("尝试重新获取文档区链接后仍失败, 已置为空", e);
// }
// }
// siteConfigDTO.setReadme(textContent);
// }
// }
// return siteConfigDTO;
// }
//
// }

View File

@@ -135,7 +135,7 @@ public abstract class AbstractOneDriveServiceBase extends AbstractBaseFileServic
try {
root = oneDriveRestTemplate.exchange(requestUrl, HttpMethod.GET, entity, JSONObject.class, getGraphEndPoint(), fullPath).getBody();
} catch (HttpClientErrorException e) {
log.debug("调用 OneDrive 时出现了网络异常: {} , 已尝试重新刷新 token 后再试.", e.getMessage());
log.debug("调用 OneDrive 时出现了网络异常, 已尝试重新刷新 token 后再试.", e);
refreshOneDriveToken();
root = oneDriveRestTemplate.exchange(requestUrl, HttpMethod.GET, entity, JSONObject.class, getGraphEndPoint(), fullPath).getBody();
}

View File

@@ -44,12 +44,14 @@ public abstract class AbstractS3BaseFileService extends AbstractBaseFileService
return s3FileList(path);
}
@Override
public String getDownloadUrl(String path) {
this.path = path;
return s3ObjectUrl(path);
}
/**
* 获取 S3 指定目录下的对象列表
* @param path 路径
@@ -89,6 +91,7 @@ public abstract class AbstractS3BaseFileService extends AbstractBaseFileService
return fileItemList;
}
/**
* 获取对象的访问链接, 如果指定了域名, 则替换为自定义域名.
* @return S3 对象访问地址
@@ -112,6 +115,7 @@ public abstract class AbstractS3BaseFileService extends AbstractBaseFileService
return URLUtil.decode(defaultUrl);
}
@Override
public FileItemDTO getFileItem(String path) {
List<FileItemDTO> list;
@@ -131,4 +135,5 @@ public abstract class AbstractS3BaseFileService extends AbstractBaseFileService
throw new NotExistFileException();
}
}

View File

@@ -17,6 +17,7 @@ public interface BaseFileService {
*/
List<FileItemDTO> fileList(String path) throws Exception;
/**
* 获取文件下载地址
* @param path 文件路径
@@ -24,4 +25,4 @@ public interface BaseFileService {
*/
String getDownloadUrl(String path);
}
}

View File

@@ -54,6 +54,7 @@ public class AliyunServiceImpl extends AbstractS3BaseFileService implements Base
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "oss")).build();
testConnection();
isInitialized = true;
}
}

View File

@@ -68,6 +68,7 @@ public class FtpServiceImpl extends AbstractBaseFileService implements BaseFileS
ftp.getClient().configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
ftp.getClient().type(FTP.BINARY_FILE_TYPE);
testConnection();
isInitialized = true;
}
}
@@ -140,4 +141,5 @@ public class FtpServiceImpl extends AbstractBaseFileService implements BaseFileS
add(new StorageConfig("basePath", "基路径"));
}};
}
}

View File

@@ -54,6 +54,7 @@ public class HuaweiServiceImpl extends AbstractS3BaseFileService implements Base
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "obs")).build();
testConnection();
isInitialized = true;
}
}
@@ -75,5 +76,4 @@ public class HuaweiServiceImpl extends AbstractS3BaseFileService implements Base
}};
}
}

View File

@@ -64,6 +64,7 @@ public class LocalServiceImpl extends AbstractBaseFileService implements BaseFil
throw new InitializeDriveException("文件路径: \"" + file.getAbsolutePath() + "\"不存在, 请检查是否填写正确.");
} else {
testConnection();
isInitialized = true;
}
}
@@ -149,4 +150,5 @@ public class LocalServiceImpl extends AbstractBaseFileService implements BaseFil
add(new StorageConfig("filePath", "文件路径"));
}};
}
}

View File

@@ -53,6 +53,7 @@ public class MinIOServiceImpl extends AbstractS3BaseFileService implements BaseF
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "minio")).build();
testConnection();
isInitialized = true;
}
}

View File

@@ -54,6 +54,7 @@ public class OneDriveChinaServiceImpl extends AbstractOneDriveServiceBase implem
} else {
refreshOneDriveToken();
testConnection();
isInitialized = true;
}
}

View File

@@ -54,6 +54,7 @@ public class OneDriveServiceImpl extends AbstractOneDriveServiceBase implements
} else {
refreshOneDriveToken();
testConnection();
isInitialized = true;
}
}
@@ -96,4 +97,5 @@ public class OneDriveServiceImpl extends AbstractOneDriveServiceBase implements
public String getScope() {
return scope;
}
}

View File

@@ -54,6 +54,7 @@ public class QiniuServiceImpl extends AbstractS3BaseFileService implements BaseF
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "kodo")).build();
testConnection();
isInitialized = true;
}
}

View File

@@ -59,6 +59,7 @@ public class S3ServiceImpl extends AbstractS3BaseFileService implements BaseFile
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "")).build();
testConnection();
isInitialized = true;
}
}
@@ -80,4 +81,5 @@ public class S3ServiceImpl extends AbstractS3BaseFileService implements BaseFile
add(new StorageConfig("isPrivate", "是否是私有空间"));
}};
}
}

View File

@@ -53,6 +53,7 @@ public class TencentServiceImpl extends AbstractS3BaseFileService implements Bas
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "cos")).build();
testConnection();
isInitialized = true;
}
}
@@ -74,4 +75,5 @@ public class TencentServiceImpl extends AbstractS3BaseFileService implements Bas
add(new StorageConfig("isPrivate", "是否是私有空间"));
}};
}
}

View File

@@ -17,4 +17,4 @@ public class UFileServiceImpl extends UpYunServiceImpl {
return StorageTypeEnum.UFILE;
}
}
}

View File

@@ -66,6 +66,7 @@ public class UpYunServiceImpl extends AbstractBaseFileService implements BaseFil
} else {
upYun = new UpYun(bucketName, username, password);
testConnection();
isInitialized = true;
}
}