File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
continew-module-system/src/main/java/top/continew/admin/system
continew-webapi/src/main/java/top/continew/admin/controller/common Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 2020import cn .hutool .core .util .ClassUtil ;
2121import cn .hutool .core .util .EscapeUtil ;
2222import cn .hutool .core .util .StrUtil ;
23+ import com .baomidou .mybatisplus .core .incrementer .IdentifierGenerator ;
2324import lombok .RequiredArgsConstructor ;
2425import lombok .extern .slf4j .Slf4j ;
2526import org .dromara .x .file .storage .core .FileInfo ;
@@ -49,10 +50,14 @@ public class FileRecorderImpl implements FileRecorder {
4950
5051 private final FileMapper fileMapper ;
5152 private final StorageMapper storageMapper ;
53+ private final IdentifierGenerator identifierGenerator ;
5254
5355 @ Override
5456 public boolean save (FileInfo fileInfo ) {
5557 FileDO file = new FileDO ();
58+ Number id = identifierGenerator .nextId (fileInfo );
59+ file .setId (id .longValue ());
60+ fileInfo .setId (id .longValue () + "" );
5661 String originalFilename = EscapeUtil .unescape (fileInfo .getOriginalFilename ());
5762 file .setName (StrUtil .contains (originalFilename , StringConstants .DOT )
5863 ? StrUtil .subBefore (originalFilename , StringConstants .DOT , true )
Original file line number Diff line number Diff line change 2222
2323import java .io .Serial ;
2424import java .io .Serializable ;
25+ import java .util .Map ;
2526
2627/**
2728 * 文件上传响应信息
@@ -37,9 +38,27 @@ public class FileUploadResp implements Serializable {
3738 @ Serial
3839 private static final long serialVersionUID = 1L ;
3940
41+ /**
42+ * 文件 id
43+ */
44+ @ Schema (description = "文件 id" , example = "1897293810343682049" )
45+ private String id ;
46+
4047 /**
4148 * 文件 URL
4249 */
4350 @ Schema (description = "文件 URL" , example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg" )
4451 private String url ;
52+
53+ /**
54+ * 缩略图文件 URL
55+ */
56+ @ Schema (description = "缩略图文件 URL" , example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg" )
57+ private String thUrl ;
58+
59+ /**
60+ * 元数据
61+ */
62+ @ Schema (description = "元数据" )
63+ private Map <String , String > metadata ;
4564}
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ public void finish() {
120120 FileInfo fileInfo = uploadPretreatment .upload ();
121121 String domain = StrUtil .appendIfMissing (storage .getDomain (), StringConstants .SLASH );
122122 fileInfo .setUrl (URLUtil .normalize (domain + fileInfo .getPath () + fileInfo .getFilename ()));
123+ fileInfo .setThUrl (URLUtil .normalize (domain + fileInfo .getPath () + fileInfo .getThFilename ()));
123124 return fileInfo ;
124125 }
125126
Original file line number Diff line number Diff line change @@ -69,7 +69,12 @@ public class CommonController {
6969 public FileUploadResp upload (@ NotNull (message = "文件不能为空" ) MultipartFile file ) {
7070 ValidationUtils .throwIf (file ::isEmpty , "文件不能为空" );
7171 FileInfo fileInfo = fileService .upload (file );
72- return FileUploadResp .builder ().url (fileInfo .getUrl ()).build ();
72+ return FileUploadResp .builder ()
73+ .id (fileInfo .getId ())
74+ .url (fileInfo .getUrl ())
75+ .thUrl (fileInfo .getThUrl ())
76+ .metadata (fileInfo .getMetadata ())
77+ .build ();
7378 }
7479
7580 @ Operation (summary = "查询部门树" , description = "查询树结构的部门列表" )
You can’t perform that action at this time.
0 commit comments