package cn.lili.controller.lmk;
|
|
import cn.lili.base.Result;
|
import cn.lili.modules.lmk.domain.form.FileKey;
|
import cn.lili.modules.lmk.service.LmkFileService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import org.apache.ibatis.annotations.Delete;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
|
/**
|
* 文件信息 前端控制器
|
*
|
* @author xp
|
* @since 2025-05-19
|
*/
|
@Validated
|
@RequiredArgsConstructor
|
@Api(value = "文件管理", tags = "文件管理")
|
@RestController("lmkFileController")
|
@RequestMapping("/common/lmk/file")
|
public class LmkFileController {
|
|
private final LmkFileService lmkFileService;
|
|
/**
|
* 单文件上传(返回有过期时间的链接)
|
*
|
* @param file
|
* @return
|
*/
|
@PostMapping("/upload")
|
@ApiOperation(value = "单文件上传(返回有过期时间的链接)")
|
public Result upload(@RequestPart("file") @NotNull MultipartFile file) {
|
return lmkFileService.uploadObject(file);
|
}
|
|
|
/**
|
* 多文件上传
|
*
|
* @param files
|
* @return
|
*/
|
@PostMapping("/multi/upload")
|
@ApiOperation(value = "多文件上传(返回有过期时间的链接)")
|
public Result uploads(@RequestPart("files") @NotEmpty List<MultipartFile> files) {
|
return lmkFileService.uploadObjects(files);
|
}
|
|
/**
|
* 删除某个文件
|
*
|
* @param fileKey oss文件名
|
* @return
|
*/
|
@Delete("/delete}")
|
@ApiOperation(value = "删除某个文件")
|
public Result deleteObject(@RequestBody FileKey fileKey) {
|
return lmkFileService.deleteObject(fileKey.getFileKey());
|
}
|
|
/**
|
* 批量删除文件
|
*
|
* @param fileKeys
|
* @return
|
*/
|
@Delete("/delete/files")
|
@ApiOperation(value = "批量删除文件")
|
public Result deleteObjects(@RequestBody @NotEmpty List<String> fileKeys) {
|
return lmkFileService.deleteObjects(fileKeys);
|
}
|
|
/**
|
* 下载文件
|
*
|
* @param fileKey
|
* @return
|
*/
|
@PostMapping("/download")
|
@ApiOperation(value = "下载文件")
|
public void downloadFile(@RequestBody FileKey fileKey, HttpServletResponse response) {
|
lmkFileService.downloadObject(fileKey.getFileKey(), response);
|
}
|
|
/**
|
* 预览文件
|
*
|
* @param fileKey
|
* @return
|
*/
|
@PostMapping("/preview")
|
@ApiOperation(value = "获取文件预览url(链接存在时效)")
|
public Result getPreviewUrl(@RequestBody FileKey fileKey) {
|
return Result.ok().data(lmkFileService.getPreviewUrl(fileKey.getFileKey()));
|
}
|
|
|
@GetMapping("/sts")
|
@ApiOperation(value = "获取STS访问令牌", notes = "前端做直传")
|
public Result getSTSToken() {
|
return Result.ok().data(lmkFileService.getSTSToken());
|
}
|
}
|