mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
✨ 新增自定义直链名称功能功能
This commit is contained in:
@@ -45,7 +45,7 @@ public class DirectLinkController {
|
||||
*
|
||||
* @return 重定向至文件直链
|
||||
*/
|
||||
@GetMapping("/directlink/{driveId}/**")
|
||||
@GetMapping("/${zfile.directLinkPrefix}/{driveId}/**")
|
||||
public String directlink(@PathVariable("driveId") Integer driveId,
|
||||
final HttpServletRequest request,
|
||||
final HttpServletResponse response) throws IOException {
|
||||
|
||||
@@ -6,6 +6,7 @@ import im.zhaojun.zfile.context.DriveContext;
|
||||
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.DriveListDTO;
|
||||
import im.zhaojun.zfile.model.dto.FileItemDTO;
|
||||
import im.zhaojun.zfile.model.dto.FileListDTO;
|
||||
import im.zhaojun.zfile.model.dto.SystemFrontConfigDTO;
|
||||
@@ -118,9 +119,9 @@ public class FileController {
|
||||
throw new NotEnabledDriveException();
|
||||
}
|
||||
|
||||
|
||||
systemConfig.setDebugMode(debug);
|
||||
systemConfig.setDefaultSwitchToImgMode(driveConfig.getDefaultSwitchToImgMode());
|
||||
systemConfig.setDirectLinkPrefix(ZFileConstant.DIRECT_LINK_PREFIX);
|
||||
|
||||
// 如果不是 FTP 模式,则尝试获取当前文件夹中的 README 文件,有则读取,没有则停止
|
||||
if (!Objects.equals(driveConfig.getType(), StorageTypeEnum.FTP)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package im.zhaojun.zfile.controller.home;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import im.zhaojun.zfile.model.constant.ZFileConstant;
|
||||
import im.zhaojun.zfile.model.dto.SystemConfigDTO;
|
||||
import im.zhaojun.zfile.model.entity.ShortLinkConfig;
|
||||
import im.zhaojun.zfile.model.support.ResultBean;
|
||||
@@ -36,7 +37,7 @@ public class ShortLinkController {
|
||||
SystemConfigDTO systemConfig = systemConfigService.getSystemConfig();
|
||||
String domain = systemConfig.getDomain();
|
||||
// 拼接直链地址.
|
||||
String fullPath = StringUtils.removeDuplicateSeparator("/directlink/" + driveId + path);
|
||||
String fullPath = StringUtils.concatUrl(StringUtils.DELIMITER_STR, ZFileConstant.DIRECT_LINK_PREFIX, driveId, path);
|
||||
ShortLinkConfig shortLinkConfig = shortLinkConfigService.findByUrl(fullPath);
|
||||
|
||||
if (shortLinkConfig == null) {
|
||||
|
||||
@@ -16,6 +16,10 @@ public class ZFileConstant {
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
|
||||
/**
|
||||
* 直链前缀名称
|
||||
*/
|
||||
public static String DIRECT_LINK_PREFIX = "directlink";
|
||||
|
||||
/**
|
||||
* 系统产生的临时文件路径
|
||||
@@ -68,5 +72,9 @@ public class ZFileConstant {
|
||||
ZFileConstant.TEXT_MAX_FILE_SIZE_KB = maxFileSizeKb;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setDirectLinkPrefix(@Value("${zfile.directLinkPrefix}") String directLinkPrefix) {
|
||||
ZFileConstant.DIRECT_LINK_PREFIX = directLinkPrefix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,4 +50,7 @@ public class SystemFrontConfigDTO {
|
||||
private Boolean showShortLink;
|
||||
|
||||
private Boolean showPathLink;
|
||||
|
||||
private String directLinkPrefix;
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package im.zhaojun.zfile.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import im.zhaojun.zfile.cache.ZFileCache;
|
||||
import im.zhaojun.zfile.context.DriveContext;
|
||||
import im.zhaojun.zfile.context.StorageTypeContext;
|
||||
import im.zhaojun.zfile.exception.InitializeDriveException;
|
||||
import im.zhaojun.zfile.model.constant.StorageConfigConstant;
|
||||
import im.zhaojun.zfile.model.constant.ZFileConstant;
|
||||
import im.zhaojun.zfile.model.dto.CacheInfoDTO;
|
||||
import im.zhaojun.zfile.model.dto.DriveConfigDTO;
|
||||
import im.zhaojun.zfile.model.dto.StorageStrategyConfig;
|
||||
@@ -18,6 +18,7 @@ import im.zhaojun.zfile.repository.FilterConfigRepository;
|
||||
import im.zhaojun.zfile.repository.ShortLinkConfigRepository;
|
||||
import im.zhaojun.zfile.repository.StorageConfigRepository;
|
||||
import im.zhaojun.zfile.service.base.AbstractBaseFileService;
|
||||
import im.zhaojun.zfile.util.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Example;
|
||||
@@ -259,7 +260,12 @@ public class DriveConfigService {
|
||||
driverConfigRepository.updateId(updateId, newId);
|
||||
storageConfigRepository.updateDriveId(updateId, newId);
|
||||
filterConfigRepository.updateDriveId(updateId, newId);
|
||||
shortLinkConfigRepository.updateUrlDriveId("/directlink/" + updateId, "/directlink/" + newId);
|
||||
|
||||
|
||||
String updateSubPath = StringUtils.concatUrl(StringUtils.DELIMITER_STR, ZFileConstant.DIRECT_LINK_PREFIX, String.valueOf(updateId));
|
||||
String newSubPath = StringUtils.concatUrl(StringUtils.DELIMITER_STR, ZFileConstant.DIRECT_LINK_PREFIX, String.valueOf(newId));
|
||||
|
||||
shortLinkConfigRepository.updateUrlDriveId(updateSubPath, newSubPath);
|
||||
driveContext.updateDriveId(updateId, newId);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ public class StringUtils {
|
||||
|
||||
public static final char DELIMITER = '/';
|
||||
|
||||
public static final String DELIMITER_STR = "/";
|
||||
|
||||
public static final String HTTP_PROTOCAL = "http://";
|
||||
|
||||
public static final String HTTPS_PROTOCAL = "https://";
|
||||
@@ -141,6 +143,6 @@ public class StringUtils {
|
||||
public static String generatorLink(Integer driveId, String fullPath) {
|
||||
SystemConfigService systemConfigService = SpringContextHolder.getBean(SystemConfigService.class);
|
||||
String domain = systemConfigService.getDomain();
|
||||
return concatUrl(domain, "directlink", String.valueOf(driveId), fullPath);
|
||||
return concatUrl(domain, ZFileConstant.DIRECT_LINK_PREFIX, String.valueOf(driveId), fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user