Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.Serial;
import java.io.Serializable;
import java.util.Map;

/**
* 文件上传响应信息
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void finish() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public class CommonController {
public FileUploadResp upload(@NotNull(message = "文件不能为空") MultipartFile file) {
ValidationUtils.throwIf(file::isEmpty, "文件不能为空");
FileInfo fileInfo = fileService.upload(file);
return FileUploadResp.builder().url(fileInfo.getUrl()).build();
return FileUploadResp.builder()
.id(fileInfo.getId())
.url(fileInfo.getUrl())
.thUrl(fileInfo.getThUrl())
.metadata(fileInfo.getMetadata())
.build();
}

@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
Expand Down
Loading