| | |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | return R.ok(types); |
| | | } |
| | | |
| | | @PostMapping("/config/uploadLogo/auth") |
| | | @ManagerAuth |
| | | public R uploadLogo(@RequestParam("file") MultipartFile file) { |
| | | if (file == null || file.isEmpty()) { |
| | | return R.error("请选择文件"); |
| | | } |
| | | String originalName = file.getOriginalFilename(); |
| | | if (originalName == null) { |
| | | return R.error("文件名为空"); |
| | | } |
| | | String ext = originalName.contains(".") ? originalName.substring(originalName.lastIndexOf(".") + 1).toLowerCase() : ""; |
| | | String mimeType; |
| | | switch (ext) { |
| | | case "png": mimeType = "image/png"; break; |
| | | case "jpg": |
| | | case "jpeg": mimeType = "image/jpeg"; break; |
| | | case "svg": mimeType = "image/svg+xml"; break; |
| | | case "ico": mimeType = "image/x-icon"; break; |
| | | default: return R.error("仅支持 png/jpg/jpeg/svg/ico 格式"); |
| | | } |
| | | try { |
| | | String base64 = Base64.getEncoder().encodeToString(file.getBytes()); |
| | | String dataUri = "data:" + mimeType + ";base64," + base64; |
| | | configService.saveConfigValue("system.logo", dataUri); |
| | | Parameter.reset(); |
| | | configService.refreshSystemConfigCache(); |
| | | return R.ok().add(dataUri); |
| | | } catch (IOException e) { |
| | | return R.error("上传失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | private static boolean checkJson(String val){ |
| | | Object parse = null; |