xiangpei
2025-05-22 0d9214d780c5093165f566f3e6f0c60f5d8aead7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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());
    }
}