forked from github/dataease
feat: 字体管理
This commit is contained in:
parent
b9124028d0
commit
adab069bb7
@ -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<FontDto> list(FontDto fontDto) {
|
||||
QueryWrapper<CoreFont> 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<FontDto> defaultFont() {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("isDefault", 1);
|
||||
List<CoreFont> coreFonts = coreFontMapper.selectList(queryWrapper);
|
||||
List<FontDto> 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 {
|
||||
|
@ -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<FontDto> defaultFont() throws DEException {
|
||||
return fontManage.defaultFont();
|
||||
}
|
||||
}
|
||||
|
@ -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<FontDto> defaultFont() throws DEException;
|
||||
}
|
||||
|
@ -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/");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user