Feat: 实现用户模块和文件模块
This commit is contained in:
parent
470683473d
commit
a43d773d9c
@ -0,0 +1,70 @@
|
||||
package com.flyfish.framework.file.controller;
|
||||
|
||||
import com.flyfish.framework.bean.Result;
|
||||
import com.flyfish.framework.file.config.UploadConfiguration;
|
||||
import com.flyfish.framework.file.domain.Media;
|
||||
import com.flyfish.framework.file.service.MediaService;
|
||||
import com.flyfish.framework.file.utils.DownloadUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 媒体上传
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/media")
|
||||
public class MediaController {
|
||||
|
||||
@Resource
|
||||
private MediaService mediaService;
|
||||
@Resource
|
||||
private UploadConfiguration configuration;
|
||||
|
||||
/**
|
||||
* 上传媒体,支持多个同时上传
|
||||
*
|
||||
* @param files 文件
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("")
|
||||
public Mono<Result<List<Media>>> uploadMedia(@RequestPart("file") Flux<FilePart> files) {
|
||||
return files.flatMap(part -> part.filename().endsWith("m3u8") || part.filename().endsWith("m3u") ? mediaService.slice(part) : mediaService.upload(part))
|
||||
.reduce(Result.accept(new ArrayList<>()), ((listResult, media) -> {
|
||||
listResult.getData().add(media);
|
||||
return listResult;
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping("/**")
|
||||
public Mono<Void> downloadMedia(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
String path = StringUtils.substringAfter(request.getURI().getPath(), "/media");
|
||||
return DownloadUtils.download(configuration.getLocalPath() + path, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传hls切片内容
|
||||
*
|
||||
* @param files 文件们
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("hls")
|
||||
public Mono<Result<List<Media>>> uploadHls(@RequestPart("file") Flux<FilePart> files) {
|
||||
return files.flatMap(mediaService::slice)
|
||||
.reduce(Result.accept(new ArrayList<>()), ((listResult, media) -> {
|
||||
listResult.getData().add(media);
|
||||
return listResult;
|
||||
}));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user