diff --git a/src/main/java/im/zhaojun/common/service/SystemConfigService.java b/src/main/java/im/zhaojun/common/service/SystemConfigService.java index 11927bf..6a13137 100644 --- a/src/main/java/im/zhaojun/common/service/SystemConfigService.java +++ b/src/main/java/im/zhaojun/common/service/SystemConfigService.java @@ -48,6 +48,9 @@ public class SystemConfigService { case SystemConfigConstant.PASSWORD: systemConfigDTO.setPassword(systemConfig.getValue()); break; + case SystemConfigConstant.DOMAIN: + systemConfigDTO.setDomain(systemConfig.getValue()); + break; default:break; } } diff --git a/src/main/java/im/zhaojun/local/controller/LocalController.java b/src/main/java/im/zhaojun/local/controller/LocalController.java index eb923c0..70b92f2 100644 --- a/src/main/java/im/zhaojun/local/controller/LocalController.java +++ b/src/main/java/im/zhaojun/local/controller/LocalController.java @@ -17,7 +17,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; -import java.nio.file.Files; import java.util.Date; @Controller @@ -39,18 +38,13 @@ public class LocalController { } private ResponseEntity export(File file) throws IOException { - // 获取文件 MIME 类型 - String fileMimeType = Files.probeContentType(file.toPath()); MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; - HttpHeaders headers = new HttpHeaders(); - if (fileMimeType == null || "".equals(fileMimeType)) { - headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); - headers.add("Content-Disposition", "attachment; filename=" + file.getName()); - } else { - mediaType = MediaType.parseMediaType(fileMimeType); - } + HttpHeaders headers = new HttpHeaders(); + headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); + headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName())); + headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); diff --git a/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java b/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java index 4edb767..3cd7242 100644 --- a/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java +++ b/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java @@ -84,7 +84,7 @@ public class LocalServiceImpl implements FileService { @Override public String getDownloadUrl(String path) throws Exception { SystemConfig usernameConfig = systemConfigRepository.findByKey(SystemConfigConstant.DOMAIN); - return StringUtils.concatPath( usernameConfig.getValue(), "file" + path); + return StringUtils.removeDuplicateSeparator(usernameConfig.getValue() + "/file/" + path); } public String getFilePath() {