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