|
|
@@ -0,0 +1,115 @@
|
|
|
+package cn.reghao.oss.console.app.controller;
|
|
|
+
|
|
|
+import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
+import cn.reghao.oss.api.dto.ObjectInfo;
|
|
|
+import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
+import cn.reghao.oss.api.iface.ConsoleService;
|
|
|
+import cn.reghao.oss.api.iface.StoreServiceWrapper;
|
|
|
+import cn.reghao.oss.api.util.AuthContext;
|
|
|
+import cn.reghao.oss.api.dto.media.*;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2024-02-23 09:05:58
|
|
|
+ */
|
|
|
+@Api(tags = "视频文件接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/oss")
|
|
|
+public class OssController {
|
|
|
+ private final ConsoleService consoleService;
|
|
|
+ private final StoreServiceWrapper storeServiceWrapper;
|
|
|
+
|
|
|
+ public OssController(ConsoleService consoleService, StoreServiceWrapper storeServiceWrapper) {
|
|
|
+ this.consoleService = consoleService;
|
|
|
+ this.storeServiceWrapper = storeServiceWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取 oss-store 节点")
|
|
|
+ @GetMapping(value = "/upload/store", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getUploadStore(@RequestParam("channelId") int channelId) {
|
|
|
+ int loginUser = AuthContext.getUserId();
|
|
|
+ ServerInfo serverInfo = consoleService.getUploadStore(channelId, loginUser);
|
|
|
+ return WebResult.success(serverInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取 channel 可见范围")
|
|
|
+ @PostMapping(value = "/channel/scope", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getChannelScope(int channelId) throws Exception {
|
|
|
+ int scope = storeServiceWrapper.getChannelScope(channelId);
|
|
|
+ return WebResult.success(scope);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "设置对象可见范围")
|
|
|
+ @PostMapping(value = "/object/scope", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String setObjectScope(int channelId, String objectId, int scope) {
|
|
|
+ storeServiceWrapper.setObjectScope(channelId, objectId, scope);
|
|
|
+ return WebResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据 object_id 删除对象")
|
|
|
+ @PostMapping(value = "/object/delete/id", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String deleteByObjectId(@RequestParam("channelId") int channelId,
|
|
|
+ @RequestParam("objectId") String objectId) {
|
|
|
+ storeServiceWrapper.deleteByObjectId(channelId, objectId);
|
|
|
+ return WebResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据 object_url 删除对象")
|
|
|
+ @PostMapping(value = "/object/delete/url", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String deleteByObjectUrl(@RequestParam("objectUrl") String objectUrl) {
|
|
|
+ storeServiceWrapper.deleteByObjectUrl(objectUrl);
|
|
|
+ return WebResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取对象信息")
|
|
|
+ @GetMapping(value = "/object/info", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getObjectInfo(@RequestParam("channelId") int channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ ObjectInfo objectInfo = storeServiceWrapper.getObjectInfo(channelId, objectId);
|
|
|
+ return WebResult.success(objectInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取对象签名 url")
|
|
|
+ @GetMapping(value = "/object/url", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getSignedUrl(@RequestParam("channelId") Integer channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ String signedUrl = storeServiceWrapper.getSignedUrl(channelId, objectId);
|
|
|
+ return WebResult.success(signedUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取视频文件信息")
|
|
|
+ @GetMapping(value = "/object/video/info", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getVideoInfo(@RequestParam("channelId") Integer channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ VideoInfo videoInfo = storeServiceWrapper.getVideoInfo(channelId, objectId);
|
|
|
+ return WebResult.success(videoInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取图片文件信息")
|
|
|
+ @GetMapping(value = "/object/image/info", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getImagesInfo(@RequestParam("channelId") Integer channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ ImageInfo imageInfo = storeServiceWrapper.getImageInfo(channelId, objectId);
|
|
|
+ return WebResult.success(imageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取 webp 图片文件信息")
|
|
|
+ @PostMapping(value = "/object/image/webp", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getWebpInfo(@RequestParam("channelId") Integer channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ ConvertedImageInfo convertedImageInfo = storeServiceWrapper.getWebpInfo(channelId, objectId);
|
|
|
+ return WebResult.success(convertedImageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取音频文件信息")
|
|
|
+ @GetMapping(value = "/media/audio/info", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String getAudioInfo(@RequestParam("channelId") Integer channelId,
|
|
|
+ @RequestParam("objectId") String objectId) throws Exception {
|
|
|
+ AudioInfo audioInfo = storeServiceWrapper.getAudioInfo(channelId, objectId);
|
|
|
+ return WebResult.success(audioInfo);
|
|
|
+ }
|
|
|
+}
|