mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +08:00 
			
		
		
		
	feat: 图片文件支持缩略图 (#63)
This commit is contained in:
		| @@ -17,6 +17,7 @@ | ||||
| package top.continew.admin.system.config.file; | ||||
|  | ||||
| import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.core.util.ClassUtil; | ||||
| import cn.hutool.core.util.EscapeUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| @@ -60,7 +61,9 @@ public class FileRecorderImpl implements FileRecorder { | ||||
|         file.setUrl(fileInfo.getUrl()); | ||||
|         file.setExtension(fileInfo.getExt()); | ||||
|         file.setType(FileTypeEnum.getByExtension(file.getExtension())); | ||||
|         StorageDO storage = storageMapper.lambdaQuery().eq(StorageDO::getCode, fileInfo.getPlatform()).one(); | ||||
|         file.setThumbnailUrl(fileInfo.getThUrl()); | ||||
|         file.setThumbnailSize(fileInfo.getThSize()); | ||||
|         StorageDO storage = (StorageDO)fileInfo.getAttr().get(ClassUtil.getClassName(StorageDO.class, false)); | ||||
|         file.setStorageId(storage.getId()); | ||||
|         file.setCreateTime(DateUtil.toLocalDateTime(fileInfo.getCreateTime())); | ||||
|         file.setUpdateUser(LoginHelper.getUserId()); | ||||
|   | ||||
| @@ -70,6 +70,16 @@ public class FileDO extends BaseDO { | ||||
|      */ | ||||
|     private FileTypeEnum type; | ||||
|  | ||||
|     /** | ||||
|      * 缩略图大小(字节) | ||||
|      */ | ||||
|     private Long thumbnailSize; | ||||
|  | ||||
|     /** | ||||
|      * 缩略图URL | ||||
|      */ | ||||
|     private String thumbnailUrl; | ||||
|  | ||||
|     /** | ||||
|      * 存储 ID | ||||
|      */ | ||||
|   | ||||
| @@ -69,6 +69,18 @@ public class FileResp extends BaseDetailResp { | ||||
|         "5"}, example = "2") | ||||
|     private FileTypeEnum type; | ||||
|  | ||||
|     /** | ||||
|      * 缩略图大小(字节) | ||||
|      */ | ||||
|     @Schema(description = "缩略图大小(字节)", example = "1024") | ||||
|     private Long thumbnailSize; | ||||
|  | ||||
|     /** | ||||
|      * 缩略图URL | ||||
|      */ | ||||
|     @Schema(description = "缩略图URL", example = "https://examplebucket.oss-cn-hangzhou.aliyuncs.com/example/example.jpg.min.jpg") | ||||
|     private String thumbnailUrl; | ||||
|  | ||||
|     /** | ||||
|      * 存储 ID | ||||
|      */ | ||||
|   | ||||
| @@ -17,8 +17,7 @@ | ||||
| package top.continew.admin.system.service.impl; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.hutool.core.util.URLUtil; | ||||
| import cn.hutool.core.util.*; | ||||
| import jakarta.annotation.Resource; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| @@ -85,7 +84,11 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes | ||||
|             storage = storageService.getByCode(storageCode); | ||||
|             CheckUtils.throwIfNotExists(storage, "StorageDO", "Code", storageCode); | ||||
|         } | ||||
|         UploadPretreatment uploadPretreatment = fileStorageService.of(file).setPlatform(storage.getCode()); | ||||
|  | ||||
|         UploadPretreatment uploadPretreatment = fileStorageService.of(file) | ||||
|             .thumbnail(img -> img.size(100, 100)) | ||||
|             .setPlatform(storage.getCode()) | ||||
|             .putAttr(ClassUtil.getClassName(StorageDO.class, false), storage); | ||||
|         uploadPretreatment.setProgressMonitor(new ProgressListener() { | ||||
|             @Override | ||||
|             public void start() { | ||||
| @@ -133,7 +136,12 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes | ||||
|         super.fill(obj); | ||||
|         if (obj instanceof FileResp fileResp && !URLUtils.isHttpUrl(fileResp.getUrl())) { | ||||
|             StorageDO storage = storageService.getById(fileResp.getStorageId()); | ||||
|             fileResp.setUrl(URLUtil.normalize(storage.getDomain() + StringConstants.SLASH + fileResp.getUrl())); | ||||
|             String url = URLUtil.normalize(storage.getDomain() + StringConstants.SLASH + fileResp.getUrl()); | ||||
|             fileResp.setUrl(url); | ||||
|             String thumbnailUrl = StrUtil.isBlank(fileResp.getThumbnailUrl()) | ||||
|                 ? url | ||||
|                 : URLUtil.normalize(storage.getDomain() + StringConstants.SLASH + fileResp.getThumbnailUrl()); | ||||
|             fileResp.setThumbnailUrl(thumbnailUrl); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 kils
					kils