feat: 完善框架
This commit is contained in:
parent
0ba4b08b79
commit
bf3c20f937
@ -49,7 +49,7 @@ public class MediaController {
|
||||
|
||||
@GetMapping("/**")
|
||||
public Mono<Void> downloadMedia(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
String path = StringUtils.substringAfter(request.getURI().getPath(), "/media");
|
||||
String path = StringUtils.substringAfter(request.getURI().getPath(), "/medias");
|
||||
return DownloadUtils.download(configuration.getLocalPath() + path, response);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ package com.flyfish.framework.file.service;
|
||||
import com.flyfish.framework.file.domain.Attachment;
|
||||
import com.flyfish.framework.file.utils.FileSizeUtils;
|
||||
import com.flyfish.framework.service.impl.BaseServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
@ -24,6 +25,16 @@ public class AttachmentService extends BaseServiceImpl<Attachment> {
|
||||
* @return 结果
|
||||
*/
|
||||
public Mono<Attachment> upload(FilePart part) {
|
||||
return upload(part, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传媒体文件
|
||||
*
|
||||
* @param part 文件
|
||||
* @return 结果
|
||||
*/
|
||||
public Mono<Attachment> upload(FilePart part, String name) {
|
||||
return fileService.saveLocal(part)
|
||||
.map(path -> {
|
||||
Attachment attachment = Attachment.builder()
|
||||
@ -31,7 +42,7 @@ public class AttachmentService extends BaseServiceImpl<Attachment> {
|
||||
.path(path)
|
||||
.url(URL + path)
|
||||
.build();
|
||||
attachment.setName(part.filename());
|
||||
attachment.setName(StringUtils.isNotBlank(name) ? name : part.filename());
|
||||
return create(attachment);
|
||||
});
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import java.io.IOException;
|
||||
@Slf4j
|
||||
public class MediaService {
|
||||
|
||||
private static String URL = "/api/media/";
|
||||
private static String URL = "/api/medias/";
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
@Resource
|
||||
|
Loading…
Reference in New Issue
Block a user