@@ -126,11 +126,11 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义异常 PiscesException
|
||||
* 自定义异常 DiyFileException
|
||||
*/
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = DiyFileException.class)
|
||||
public CommonResult<?> piscesExceptionHandler(DiyFileException ex) {
|
||||
public CommonResult<?> diyFileExceptionHandler(DiyFileException ex) {
|
||||
log.info("自定义异常.[异常原因={}]", ex.getMessage(), ex);
|
||||
return CommonResult.failed(ex.getCode(), ex.getMessage(), null);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,8 @@ import lombok.EqualsAndHashCode;
|
||||
@Builder
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class LocalParam extends FileInitParam {
|
||||
|
||||
/** 代理访问域名 */
|
||||
private String domain;
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class ParamUtils {
|
||||
} else if (Objects.equals(storage.getType(), StorageTypeEnum.LOCAL.getValue())) {
|
||||
LocalParam param = LocalParam.builder()
|
||||
.build();
|
||||
param.setDomain(Optional.ofNullable(configMap.get("domain")).orElse(""));
|
||||
param.setMountPath(configMap.get("mount_path"));
|
||||
return param;
|
||||
} else if (Objects.equals(storage.getType(), StorageTypeEnum.AMAZON_S3.getValue())) {
|
||||
|
||||
@@ -20,7 +20,7 @@ public class OpenApiConfiguration {
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("DiyFile")
|
||||
.description("一款好看的在线文件列表程序")
|
||||
.version("v0.5.1")
|
||||
.version("v0.5.2")
|
||||
.license(new License().name("MIT license").url("https://github.com/besscroft/diyfile/blob/main/LICENSE")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("DiyFile 文档")
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.besscroft.diyfile.common.constant.FileConstants;
|
||||
import com.besscroft.diyfile.common.enums.StorageTypeEnum;
|
||||
import com.besscroft.diyfile.common.exception.DiyFileException;
|
||||
import com.besscroft.diyfile.common.param.storage.init.LocalParam;
|
||||
import com.besscroft.diyfile.common.util.PathUtils;
|
||||
import com.besscroft.diyfile.common.vo.FileInfoVo;
|
||||
import com.besscroft.diyfile.storage.service.base.AbstractFileBaseService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -91,8 +92,8 @@ public class LocalServiceImpl extends AbstractFileBaseService<LocalParam> {
|
||||
fileInfoVo.setSize(file.length());
|
||||
fileInfoVo.setPath(file.getPath());
|
||||
fileInfoVo.setLastModifiedDateTime(LocalDateTimeUtil.of(file.lastModified()));
|
||||
// TODO 代理链接生成
|
||||
fileInfoVo.setUrl(file.getAbsolutePath());
|
||||
// 代理链接生成
|
||||
fileInfoVo.setUrl(getFileDomainUrl(file.getPath()));
|
||||
fileInfoVo.setType(FileConstants.FILE);
|
||||
fileInfoVo.setFile(null);
|
||||
}
|
||||
@@ -139,24 +140,24 @@ public class LocalServiceImpl extends AbstractFileBaseService<LocalParam> {
|
||||
List<FileInfoVo> fileInfoVoList = new ArrayList<>();
|
||||
for (File file : fileList) {
|
||||
if (file.isDirectory()) {
|
||||
// TODO 处理文件夹
|
||||
// 处理文件夹
|
||||
FileInfoVo fileInfoVo = new FileInfoVo();
|
||||
fileInfoVo.setName(file.getName());
|
||||
fileInfoVo.setSize(file.length());
|
||||
fileInfoVo.setPath(file.getPath());
|
||||
fileInfoVo.setLastModifiedDateTime(LocalDateTimeUtil.of(file.lastModified()));
|
||||
fileInfoVo.setUrl(file.getAbsolutePath());
|
||||
fileInfoVo.setUrl(getFileDomainUrl(file.getPath()));
|
||||
fileInfoVo.setType(FileConstants.FOLDER);
|
||||
fileInfoVo.setFile(null);
|
||||
fileInfoVoList.add(fileInfoVo);
|
||||
} else {
|
||||
// TODO 处理文件
|
||||
// 处理文件
|
||||
FileInfoVo fileInfoVo = new FileInfoVo();
|
||||
fileInfoVo.setName(file.getName());
|
||||
fileInfoVo.setSize(file.length());
|
||||
fileInfoVo.setPath(file.getPath());
|
||||
fileInfoVo.setLastModifiedDateTime(LocalDateTimeUtil.of(file.lastModified()));
|
||||
fileInfoVo.setUrl(file.getAbsolutePath());
|
||||
fileInfoVo.setUrl(getFileDomainUrl(file.getPath()));
|
||||
fileInfoVo.setType(FileConstants.FILE);
|
||||
fileInfoVo.setFile(null);
|
||||
fileInfoVoList.add(fileInfoVo);
|
||||
@@ -165,4 +166,16 @@ public class LocalServiceImpl extends AbstractFileBaseService<LocalParam> {
|
||||
return fileInfoVoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件预览路径
|
||||
* @param pathAndName 文件路径和名称
|
||||
* @return 文件预览路径
|
||||
*/
|
||||
private String getFileDomainUrl(String pathAndName) {
|
||||
if (StrUtil.isBlank(initParam.getDomain())) {
|
||||
return "/@api" + "/" + PathUtils.removeLeadingSlash(pathAndName);
|
||||
}
|
||||
return PathUtils.removeTrailingSlash(initParam.getDomain()) + "/" + PathUtils.removeLeadingSlash(pathAndName.replace(initParam.getMountPath(), ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
<version>3.1.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@@ -17,20 +17,20 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<revision>0.5.1</revision>
|
||||
<revision>0.5.2</revision>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>3.0.6</spring-boot.version>
|
||||
<spring-boot.version>3.1.0</spring-boot.version>
|
||||
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
||||
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
|
||||
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||
<springdoc.version>2.1.0</springdoc.version>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
<hutool-all.version>5.8.18</hutool-all.version>
|
||||
<hutool-all.version>5.8.19</hutool-all.version>
|
||||
<pagehelper.version>1.4.6</pagehelper.version>
|
||||
<oshi.version>6.4.1</oshi.version>
|
||||
<okhttps.version>3.5.3</okhttps.version>
|
||||
|
||||
Reference in New Issue
Block a user