mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
@@ -20,6 +20,7 @@ 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 com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
@@ -49,10 +50,14 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
|
||||
private final FileMapper fileMapper;
|
||||
private final StorageMapper storageMapper;
|
||||
private final IdentifierGenerator identifierGenerator;
|
||||
|
||||
@Override
|
||||
public boolean save(FileInfo fileInfo) {
|
||||
FileDO file = new FileDO();
|
||||
Number id = identifierGenerator.nextId(fileInfo);
|
||||
file.setId(id.longValue());
|
||||
fileInfo.setId(id.longValue() + "");
|
||||
String originalFilename = EscapeUtil.unescape(fileInfo.getOriginalFilename());
|
||||
file.setName(StrUtil.contains(originalFilename, StringConstants.DOT)
|
||||
? StrUtil.subBefore(originalFilename, StringConstants.DOT, true)
|
||||
|
@@ -22,6 +22,7 @@ import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件上传响应信息
|
||||
@@ -37,9 +38,27 @@ public class FileUploadResp implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 文件 id
|
||||
*/
|
||||
@Schema(description = "文件 id", example = "1897293810343682049")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 文件 URL
|
||||
*/
|
||||
@Schema(description = "文件 URL", example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 缩略图文件 URL
|
||||
*/
|
||||
@Schema(description = "缩略图文件 URL", example = "http://localhost:8000/file/65e87dc3fb377a6fb58bdece.jpg")
|
||||
private String thUrl;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Schema(description = "元数据")
|
||||
private Map<String, String> metadata;
|
||||
}
|
||||
|
@@ -120,6 +120,7 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
FileInfo fileInfo = uploadPretreatment.upload();
|
||||
String domain = StrUtil.appendIfMissing(storage.getDomain(), StringConstants.SLASH);
|
||||
fileInfo.setUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getFilename()));
|
||||
fileInfo.setThUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getThFilename()));
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user