diff --git a/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java b/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java index f60caae906..702d579f58 100644 --- a/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java +++ b/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java @@ -9,12 +9,21 @@ import io.dataease.utils.BeanUtils; import io.dataease.utils.FileUtils; import io.dataease.utils.IDUtils; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.FileOutputStream; +import jakarta.servlet.ServletOutputStream; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.core.io.ResourceLoader; + +import java.io.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -25,6 +34,8 @@ public class FontManage { private static String path = "/opt/dataease2.0/data/font/"; @Resource private CoreFontMapper coreFontMapper; + @Autowired + private ResourceLoader resourceLoader; public List list(FontDto fontDto) { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -82,6 +93,38 @@ public class FontManage { return saveFile(file, fileUuid); } + public void download(Long id, HttpServletResponse response) { + CoreFont coreFont = coreFontMapper.selectById(id); + try { + response.setContentType("application/x-download"); + response.setHeader("Content-Disposition", "attachment;filename=" + coreFont.getFileTransName()); + try (ServletOutputStream out = response.getOutputStream(); + InputStream stream = new FileInputStream(path + coreFont.getFileTransName())) { + byte buff[] = new byte[1024]; + int length; + while ((length = stream.read(buff)) > 0) { + out.write(buff, 0, length); + } + out.flush(); + } + } catch (IOException e) { + DEException.throwException(e.getMessage()); + } + } + + public List defaultFont() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("isDefault", 1); + List coreFonts = coreFontMapper.selectList(queryWrapper); + List fontDtos = new ArrayList<>(); + for (CoreFont coreFont : coreFonts) { + FontDto dto = new FontDto(); + BeanUtils.copyBean(dto, coreFont); + fontDtos.add(dto); + } + return fontDtos; + } + private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException { String fileTransName = ""; try { diff --git a/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java b/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java index b43b23b09a..422fa19cfa 100644 --- a/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java +++ b/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java @@ -5,6 +5,7 @@ import io.dataease.api.font.dto.FontDto; import io.dataease.exception.DEException; import jakarta.annotation.Resource; import io.dataease.font.manage.FontManage; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -47,4 +48,14 @@ public class FontServer implements FontApi { public String upload(MultipartFile file) throws DEException { return fontManage.upload(file); } + + @Override + public void download(Long id, HttpServletResponse response) throws DEException { + fontManage.download(id, response); + } + + @Override + public List defaultFont() throws DEException { + return fontManage.defaultFont(); + } } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/font/api/FontApi.java b/sdk/api/api-base/src/main/java/io/dataease/api/font/api/FontApi.java index 33eac1ce6d..f69135e28b 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/font/api/FontApi.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/font/api/FontApi.java @@ -7,10 +7,8 @@ import io.dataease.api.font.dto.FontDto; import io.dataease.exception.DEException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -46,4 +44,9 @@ public interface FontApi { @PostMapping("/uploadFile") String upload(@RequestParam("file") MultipartFile file) throws DEException; + @GetMapping("/download/{id}") + void download(@PathVariable("id") Long id, HttpServletResponse response) throws DEException;\ + + @GetMapping("/defaultFont") + List defaultFont() throws DEException; } diff --git a/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java b/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java index 0a132228a1..9c5668fa87 100644 --- a/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java +++ b/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java @@ -68,6 +68,7 @@ public class WhitelistUtils { || StringUtils.startsWithAny(requestURI, "/geo/") || StringUtils.startsWithAny(requestURI, "/websocket") || StringUtils.startsWithAny(requestURI, "/map/") + || StringUtils.startsWithAny(requestURI, "/typeface/download") || StringUtils.startsWithAny(requestURI, "/communicate/down/"); } }