Browse Source

对应 oss-store 中接口的修改

reghao 2 năm trước cách đây
mục cha
commit
96b2c01fbe

+ 0 - 44
oss-console/src/main/java/cn/reghao/oss/console/app/controller/AudioFileController.java

@@ -1,44 +0,0 @@
-package cn.reghao.oss.console.app.controller;
-
-import cn.reghao.jutil.jdk.result.WebResult;
-import cn.reghao.oss.store.api.dto.media.AudioInfo;
-import cn.reghao.oss.store.api.dto.media.AudioUrl;
-import cn.reghao.oss.console.app.rpc.AudioService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-02-23 09:27:21
- */
-@Api(tags = "音频文件接口")
-@RestController
-@RequestMapping("/api/oss/media/audio")
-public class AudioFileController {
-    private final AudioService audioService;
-
-    public AudioFileController(AudioService audioService) {
-        this.audioService = audioService;
-    }
-
-    @ApiOperation(value = "获取音频文件信息")
-    @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getAudioInfo(@RequestParam("audioFileId") String audioFileId) {
-        AudioInfo audioInfo = audioService.getAudioInfo(audioFileId);
-        return WebResult.success(audioInfo);
-    }
-
-    @ApiOperation(value = "获取音频文件 url")
-    @GetMapping(value = "/url", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getImageUrls(@RequestParam("audioFileId") String audioFileId) {
-        List<AudioUrl> list = audioService.getAudioUrls(audioFileId);
-        return WebResult.success(list);
-    }
-}

+ 0 - 42
oss-console/src/main/java/cn/reghao/oss/console/app/controller/ImageFileController.java

@@ -1,42 +0,0 @@
-package cn.reghao.oss.console.app.controller;
-
-import cn.reghao.jutil.jdk.result.WebResult;
-import cn.reghao.oss.console.app.model.dto.GetImageUrls;
-import cn.reghao.oss.store.api.dto.media.ImageUrlDto;
-import cn.reghao.oss.console.app.rpc.ImageService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author reghao
- * @date 2024-02-23 09:27:15
- */
-@Api(tags = "图片文件接口")
-@RestController
-@RequestMapping("/api/oss/media/image")
-public class ImageFileController {
-    private final ImageService imageService;
-
-    public ImageFileController(ImageService imageService) {
-        this.imageService = imageService;
-    }
-
-    @ApiOperation(value = "根据 image_file_id 删除图片文件")
-    @PostMapping(value = "/delete/id", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String deleteByImageIds(@RequestParam("imageFileIds") List<String> imageFileIds) throws Exception {
-        imageService.deleteByImageFileIds(imageFileIds);
-        return WebResult.success();
-    }
-
-    @ApiOperation(value = "获取图片文件 url")
-    @PostMapping(value = "/urls", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getImageUrls(GetImageUrls getImageUrls) throws Exception {
-        List<ImageUrlDto> list = imageService.getImageUrls(getImageUrls.getChannelId(), getImageUrls.getImageFileIds());
-        return WebResult.success(list);
-    }
-}

+ 81 - 0
oss-console/src/main/java/cn/reghao/oss/console/app/controller/MediaController.java

@@ -0,0 +1,81 @@
+package cn.reghao.oss.console.app.controller;
+
+import cn.reghao.jutil.jdk.result.WebResult;
+import cn.reghao.oss.console.app.model.dto.GetImageUrls;
+import cn.reghao.oss.store.api.dto.MediaDeleteDto;
+import cn.reghao.oss.store.api.dto.MediaScopeDto;
+import cn.reghao.oss.console.app.rpc.MediaRpcService;
+import cn.reghao.oss.store.api.dto.media.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-02-23 09:05:58
+ */
+@Api(tags = "视频文件接口")
+@RestController
+@RequestMapping("/api/oss/media")
+public class MediaController {
+    private final MediaRpcService mediaRpcService;
+
+    public MediaController(MediaRpcService mediaRpcService) {
+        this.mediaRpcService = mediaRpcService;
+    }
+
+    @ApiOperation(value = "设置媒体文件可见范围")
+    @PostMapping(value = "/scope", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String setMediaFileScope(MediaScopeDto mediaScopeDto) throws Exception {
+        mediaRpcService.setMediaFileScope(mediaScopeDto);
+        return WebResult.success();
+    }
+
+    @ApiOperation(value = "删除媒体文件")
+    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String deleteMediaFile(MediaDeleteDto mediaDeleteDto) throws Exception {
+        mediaRpcService.deleteMediaFile(mediaDeleteDto);
+        return WebResult.success();
+    }
+
+    @ApiOperation(value = "获取视频文件URL")
+    @GetMapping(value = "/video/url", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getVideoUrl(@RequestParam("channelId") Integer channelId, @RequestParam("videoFileId") String videoFileId) throws Exception {
+        List<VideoUrlDto> list = mediaRpcService.getVideoUrls(channelId, videoFileId);
+        return WebResult.success(list);
+    }
+
+    @ApiOperation(value = "获取视频文件信息")
+    @GetMapping(value = "/video/info", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getVideoInfo(@RequestParam("channelId") Integer channelId,
+                               @RequestParam("videoFileId") String videoFileId) throws Exception {
+        VideoInfo videoInfo = mediaRpcService.getVideoInfo(channelId, videoFileId);
+        return WebResult.success(videoInfo);
+    }
+
+    @ApiOperation(value = "获取图片文件 url")
+    @PostMapping(value = "/image/urls", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getImageUrls(GetImageUrls getImageUrls) throws Exception {
+        List<ImageUrlDto> list = mediaRpcService.getImageUrls(getImageUrls.getChannelId(), getImageUrls.getImageFileIds());
+        return WebResult.success(list);
+    }
+
+    @ApiOperation(value = "获取音频文件 url")
+    @GetMapping(value = "/audio/url", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getImageUrls(@RequestParam("channelId") Integer channelId,
+                               @RequestParam("audioFileId") String audioFileId) throws Exception {
+        List<AudioUrl> list = mediaRpcService.getAudioUrls(channelId, audioFileId);
+        return WebResult.success(list);
+    }
+
+    @ApiOperation(value = "获取音频文件信息")
+    @GetMapping(value = "/auduio/info", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getAudioInfo(@RequestParam("channelId") Integer channelId,
+                               @RequestParam("audioFileId") String audioFileId) throws Exception {
+        AudioInfo audioInfo = mediaRpcService.getAudioInfo(channelId, audioFileId);
+        return WebResult.success(audioInfo);
+    }
+}

+ 21 - 4
oss-console/src/main/java/cn/reghao/oss/console/app/controller/OssObjectController.java → oss-console/src/main/java/cn/reghao/oss/console/app/controller/ObjectController.java

@@ -4,6 +4,8 @@ import cn.reghao.jutil.jdk.result.WebResult;
 import cn.reghao.oss.console.app.model.dto.ObjectsScopeDto;
 import cn.reghao.oss.console.app.model.dto.SetScopeDto;
 import cn.reghao.oss.console.app.rpc.OssObjectService;
+import cn.reghao.oss.store.api.dto.DownloadUrl;
+import cn.reghao.oss.store.api.dto.ObjectInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.http.MediaType;
@@ -15,13 +17,13 @@ import java.util.List;
  * @author reghao
  * @date 2024-02-23 09:27:28
  */
-@Api(tags = "媒体接口")
+@Api(tags = "对象接口")
 @RestController
-@RequestMapping("/api/oss/media")
-public class OssObjectController {
+@RequestMapping("/api/oss/object")
+public class ObjectController {
     private final OssObjectService ossObjectService;
 
-    public OssObjectController(OssObjectService ossObjectService) {
+    public ObjectController(OssObjectService ossObjectService) {
         this.ossObjectService = ossObjectService;
     }
 
@@ -44,4 +46,19 @@ public class OssObjectController {
         ossObjectService.deleteByObjectNames(objectNames);
         return WebResult.success();
     }
+
+    @ApiOperation(value = "获取对象 url")
+    @GetMapping(value = "/url", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getObjectUrl(@RequestParam("objectId") String objectId) {
+        DownloadUrl downloadUrl = ossObjectService.getDownloadUrl(objectId);
+        return WebResult.success(downloadUrl);
+    }
+
+    @ApiOperation(value = "获取对象信息")
+    @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getObjectInfo(@RequestParam("channelId") int channelId,
+                                @RequestParam("objectId") String objectId) throws Exception {
+        ObjectInfo objectInfo = ossObjectService.getObjectInfo(channelId, objectId);
+        return WebResult.success(objectInfo);
+    }
 }

+ 4 - 25
oss-console/src/main/java/cn/reghao/oss/console/app/controller/OssServerController.java

@@ -1,12 +1,9 @@
 package cn.reghao.oss.console.app.controller;
 
 import cn.reghao.jutil.jdk.result.WebResult;
-import cn.reghao.oss.console.app.rpc.OssObjectService;
 import cn.reghao.oss.console.app.service.UploadChannelService;
 import cn.reghao.oss.console.util.AuthKeyContext;
-import cn.reghao.oss.store.api.dto.DownloadUrl;
 import cn.reghao.oss.store.api.dto.ObjectChannel;
-import cn.reghao.oss.store.api.dto.ObjectInfo;
 import cn.reghao.oss.store.api.dto.ServerInfo;
 import cn.reghao.oss.console.app.rpc.OssService;
 import io.swagger.annotations.Api;
@@ -23,46 +20,28 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @Api(tags = "OSS 接口")
 @RestController
-@RequestMapping("/api/oss")
+@RequestMapping("/api/oss/server")
 public class OssServerController {
     private final OssService ossService;
-    private final OssObjectService ossObjectService;
     private final UploadChannelService uploadChannelService;
 
-    public OssServerController(OssService ossService, OssObjectService ossObjectService,
-                               UploadChannelService uploadChannelService) {
+    public OssServerController(OssService ossService, UploadChannelService uploadChannelService) {
         this.ossService = ossService;
-        this.ossObjectService = ossObjectService;
         this.uploadChannelService = uploadChannelService;
     }
 
     @ApiOperation(value = "获取 oss-store 节点")
-    @GetMapping(value = "/server/info", produces = MediaType.APPLICATION_JSON_VALUE)
+    @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getServerInfo(@RequestParam("channelId") int channelId) throws Exception {
         ServerInfo serverInfo = ossService.getServerInfo(channelId);
         return WebResult.success(serverInfo);
     }
 
     @ApiOperation(value = "根据 channel_id 获取 UploadChannel")
-    @GetMapping(value = "/server/channel", produces = MediaType.APPLICATION_JSON_VALUE)
+    @GetMapping(value = "/channel", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getChannel(@RequestParam("channelId") int channelId) {
         int loginUser = AuthKeyContext.getUser();
         ObjectChannel objectChannel = uploadChannelService.getObjectChannelByChannelId(channelId, loginUser);
         return WebResult.success(objectChannel);
     }
-
-    @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 = ossObjectService.getObjectInfo(channelId, objectId);
-        return WebResult.success(objectInfo);
-    }
-
-    @ApiOperation(value = "获取对象 url")
-    @GetMapping(value = "/object/url", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getObjectUrl(@RequestParam("objectId") String objectId) {
-        DownloadUrl downloadUrl = ossObjectService.getDownloadUrl(objectId);
-        return WebResult.success(downloadUrl);
-    }
 }

+ 0 - 57
oss-console/src/main/java/cn/reghao/oss/console/app/controller/VideoFileController.java

@@ -1,57 +0,0 @@
-package cn.reghao.oss.console.app.controller;
-
-import cn.reghao.jutil.jdk.result.WebResult;
-import cn.reghao.oss.store.api.dto.media.VideoInfo;
-import cn.reghao.oss.store.api.dto.media.VideoUrlDto;
-import cn.reghao.oss.console.app.rpc.VideoService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
-
-import java.time.LocalDateTime;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-02-23 09:05:58
- */
-@Api(tags = "视频文件接口")
-@RestController
-@RequestMapping("/api/oss/media/video")
-public class VideoFileController {
-    private final VideoService videoService;
-
-    public VideoFileController(VideoService videoService) {
-        this.videoService = videoService;
-    }
-
-    @ApiOperation(value = "删除视频文件")
-    @DeleteMapping(value = "/delete/{videoFileId}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String deleteVideoFile(@PathVariable("videoFileId") String videoFileId) throws Exception {
-        videoService.deleteVideoFile(videoFileId);
-        return WebResult.success();
-    }
-
-    @ApiOperation(value = "获取视频文件信息")
-    @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getVideoInfo(@RequestParam("channelId") Integer channelId,
-                               @RequestParam("videoFileId") String videoFileId) throws Exception {
-        VideoInfo videoInfo = videoService.getVideoInfo(channelId, videoFileId);
-        return WebResult.success(videoInfo);
-    }
-
-    @ApiOperation(value = "获取视频文件URL")
-    @GetMapping(value = "/url", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getVideoUrl(@RequestParam("channelId") Integer channelId, @RequestParam("videoFileId") String videoFileId) throws Exception {
-        List<VideoUrlDto> list = videoService.getVideoUrls(channelId, videoFileId);
-        return WebResult.success(list);
-    }
-
-    @ApiOperation(value = "获取视频文件创建时间")
-    @GetMapping(value = "/time", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getVideoCreateTime(@RequestParam("channelId") Integer channelId, @RequestParam("videoFileId") String videoFileId) throws Exception {
-        LocalDateTime localDateTime = videoService.getCreateTime(channelId, videoFileId);
-        return WebResult.success(localDateTime);
-    }
-}

+ 0 - 36
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/AudioService.java

@@ -1,36 +0,0 @@
-package cn.reghao.oss.console.app.rpc;
-
-import cn.reghao.oss.store.api.dto.media.AudioInfo;
-import cn.reghao.oss.store.api.dto.media.AudioUrl;
-import cn.reghao.oss.store.api.iface.media.AudioFileService;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-02-23 09:10:38
- */
-@Service
-public class AudioService {
-    private AudioFileService audioFileService;
-
-    public AudioInfo getAudioInfo(String audioFileId) {
-        RemoteService<AudioFileService> remoteService = new RemoteService<>();
-        String host = "";
-        int port = -1;
-        AudioFileService audioFileService = remoteService.getService(host, port, AudioFileService.class);
-
-        return audioFileService.getAudioInfo(audioFileId);
-    }
-
-    public List<AudioUrl> getAudioUrls(String audioFileId) {
-        RemoteService<AudioFileService> remoteService = new RemoteService<>();
-        String host = "";
-        int port = -1;
-        AudioFileService audioFileService = remoteService.getService(host, port, AudioFileService.class);
-
-        int expireSecond = 3600;
-        return audioFileService.getAudioUrls(audioFileId, expireSecond);
-    }
-}

+ 0 - 50
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/ImageService.java

@@ -1,50 +0,0 @@
-package cn.reghao.oss.console.app.rpc;
-
-import cn.reghao.oss.console.app.model.po.StoreNode;
-import cn.reghao.oss.console.app.service.UploadChannelService;
-import cn.reghao.oss.store.api.dto.media.ImageUrlDto;
-import cn.reghao.oss.store.api.iface.media.ImageFileService;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author reghao
- * @date 2024-02-23 09:10:44
- */
-@Service
-public class ImageService {
-    private ImageFileService imageFileService;
-    private final UploadChannelService uploadChannelService;
-
-    public ImageService(UploadChannelService uploadChannelService) {
-        this.uploadChannelService = uploadChannelService;
-    }
-
-    public void deleteByImageFileIds(List<String> imageFileIds) throws Exception {
-        int channelId = 1;
-        ImageFileService imageFileService = getImageFileService(channelId);
-
-        imageFileService.deleteByImageFileIds(imageFileIds);
-    }
-
-    public List<ImageUrlDto> getImageUrls(int channelId, Set<String> imageFileIds) throws Exception {
-        ImageFileService imageFileService = getImageFileService(channelId);
-
-        return imageFileService.getImageUrls(imageFileIds);
-    }
-
-    private ImageFileService getImageFileService(int channelId) throws Exception {
-        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
-        if (storeNode == null) {
-            String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
-            throw new Exception(errMsg);
-        }
-
-        RemoteService<ImageFileService> remoteService = new RemoteService<>();
-        String host = storeNode.getNodeAddr();
-        int port = storeNode.getRpcPort();
-        return remoteService.getService(host, port, ImageFileService.class);
-    }
-}

+ 80 - 0
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/MediaRpcService.java

@@ -0,0 +1,80 @@
+package cn.reghao.oss.console.app.rpc;
+
+import cn.reghao.oss.console.app.model.po.StoreNode;
+import cn.reghao.oss.console.app.service.UploadChannelService;
+import cn.reghao.oss.console.util.AuthKeyContext;
+import cn.reghao.oss.store.api.dto.MediaDeleteDto;
+import cn.reghao.oss.store.api.dto.MediaScopeDto;
+import cn.reghao.oss.store.api.dto.media.*;
+import cn.reghao.oss.store.api.iface.MediaService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author reghao
+ * @date 2024-03-07 09:47:12
+ */
+@Service
+public class MediaRpcService {
+    private final UploadChannelService uploadChannelService;
+
+    public MediaRpcService(UploadChannelService uploadChannelService) {
+        this.uploadChannelService = uploadChannelService;
+    }
+
+    public void  setMediaFileScope(MediaScopeDto mediaScopeDto) throws Exception {
+        int channelId = mediaScopeDto.getChannelId();
+        MediaService mediaService = getMediaService(channelId);
+        mediaService.setMediaFileScope(mediaScopeDto);
+    }
+
+    public void deleteMediaFile(MediaDeleteDto mediaDeleteDto) throws Exception {
+        int channelId = mediaDeleteDto.getChannelId();
+        MediaService mediaService = getMediaService(channelId);
+        mediaService.deleteMediaFile(mediaDeleteDto);
+    }
+
+    public List<VideoUrlDto> getVideoUrls(int channelId, String videoFileId) throws Exception {
+        int loginUser = AuthKeyContext.getUser();
+        MediaService mediaService = getMediaService(channelId);
+
+        int expireSecond = 3600;
+        return mediaService.getVideoUrls(loginUser, videoFileId, expireSecond);
+    }
+
+    public VideoInfo getVideoInfo(int channelId, String videoFileId) throws Exception {
+        MediaService mediaService = getMediaService(channelId);
+        return mediaService.getVideoInfo(videoFileId);
+    }
+
+    public List<ImageUrlDto> getImageUrls(int channelId, Set<String> imageFileIds) throws Exception {
+        MediaService mediaService = getMediaService(channelId);
+        return mediaService.getImageUrls(imageFileIds);
+    }
+
+    public List<AudioUrl> getAudioUrls(int channelId, String audioFileId) throws Exception {
+        MediaService mediaService = getMediaService(channelId);
+        int expireSecond = 3600;
+        return mediaService.getAudioUrls(audioFileId, expireSecond);
+    }
+
+    public AudioInfo getAudioInfo(int channelId, String audioFileId) throws Exception {
+        MediaService mediaService = getMediaService(channelId);
+        return mediaService.getAudioInfo(audioFileId);
+    }
+
+    private MediaService getMediaService(int channelId) throws Exception {
+        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
+        if (storeNode == null) {
+            String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
+            throw new Exception(errMsg);
+        }
+
+        RemoteService<MediaService> remoteService = new RemoteService<>();
+        String host = storeNode.getNodeAddr();
+        int port = storeNode.getRpcPort();
+        return remoteService.getService(host, port, MediaService.class);
+    }
+}

+ 0 - 68
oss-console/src/main/java/cn/reghao/oss/console/app/rpc/VideoService.java

@@ -1,68 +0,0 @@
-package cn.reghao.oss.console.app.rpc;
-
-import cn.reghao.oss.console.account.service.UserContext;
-import cn.reghao.oss.console.app.model.po.StoreNode;
-import cn.reghao.oss.console.app.service.UploadChannelService;
-import cn.reghao.oss.console.util.AuthKeyContext;
-import cn.reghao.oss.store.api.dto.media.VideoInfo;
-import cn.reghao.oss.store.api.dto.media.VideoUrlDto;
-import cn.reghao.oss.store.api.iface.media.ImageFileService;
-import cn.reghao.oss.store.api.iface.media.VideoFileService;
-import org.springframework.stereotype.Service;
-
-import java.time.LocalDateTime;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2024-02-23 08:55:03
- */
-@Service
-public class VideoService {
-    private VideoFileService videoFileService;
-    private final UploadChannelService uploadChannelService;
-
-    public VideoService(UploadChannelService uploadChannelService) {
-        this.uploadChannelService = uploadChannelService;
-    }
-
-    public void deleteVideoFile(String videoFileId) {
-        RemoteService<VideoFileService> remoteService = new RemoteService<>();
-        String host = "";
-        int port = -1;
-        VideoFileService videoFileService = remoteService.getService(host, port, VideoFileService.class);
-
-        videoFileService.deleteVideoFile(videoFileId);
-    }
-
-    public VideoInfo getVideoInfo(int channelId, String videoFileId) throws Exception {
-        VideoFileService videoFileService = getVideoFileService(channelId);
-        return videoFileService.getVideoInfo(videoFileId);
-    }
-
-    public List<VideoUrlDto> getVideoUrls(int channelId, String videoFileId) throws Exception {
-        int loginUser = AuthKeyContext.getUser();
-        VideoFileService videoFileService = getVideoFileService(channelId);
-
-        int expireSecond = 3600;
-        return videoFileService.getVideoUrls(loginUser, videoFileId, expireSecond);
-    }
-
-    public LocalDateTime getCreateTime(int channelId, String videoFileId) throws Exception {
-        VideoFileService videoFileService = getVideoFileService(channelId);
-        return videoFileService.getCreateTime(videoFileId);
-    }
-
-    private VideoFileService getVideoFileService(int channelId) throws Exception {
-        StoreNode storeNode = uploadChannelService.getStoreNodeByChannelId(channelId);
-        if (storeNode == null) {
-            String errMsg = String.format("channel_id %s not associate with any store_node", channelId);
-            throw new Exception(errMsg);
-        }
-
-        RemoteService<VideoFileService> remoteService = new RemoteService<>();
-        String host = storeNode.getNodeAddr();
-        int port = storeNode.getRpcPort();
-        return remoteService.getService(host, port, VideoFileService.class);
-    }
-}

+ 102 - 113
oss-sdk/src/main/java/cn/reghao/oss/sdk/OssConsoleClient.java

@@ -13,7 +13,6 @@ import java.net.http.HttpClient;
 import java.net.http.HttpRequest;
 import java.net.http.HttpResponse;
 import java.nio.charset.StandardCharsets;
-import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,6 +36,9 @@ public class OssConsoleClient {
         this.endpoint = endpoint;
     }
 
+    // ****************************************************************************************************************
+    // oss-console 认证接口
+    // ****************************************************************************************************************
     private void auth(String accessKeyId, String accessKeySecret) throws Exception {
         MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
                 .addPart("accessKeyId", accessKeyId)
@@ -167,7 +169,7 @@ public class OssConsoleClient {
     }
 
     // ****************************************************************************************************************
-    // Object 相关接口
+    // oss-store 相关接口
     // ****************************************************************************************************************
     public ServerInfo getServerInfo(int channelId) throws Exception {
         String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
@@ -194,68 +196,21 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public ObjectInfo getObjectInfo(int channelId, String objectId) throws Exception {
-        String api = String.format("%s/api/oss/object/info?channelId=%s&objectId=%s", endpoint, channelId, objectId);
-        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
-                .header("authorization", "Bearer " + token)
-                .version(HttpClient.Version.HTTP_1_1)
-                .GET()
-                .build();
-        HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
-        int statusCode = httpResponse.statusCode();
-        String body = httpResponse.body();
-        if (statusCode != 200) {
-            String errMsg = String.format("%s -> %s", statusCode, body);
-            throw new Exception(errMsg);
-        }
-
-        Type type = new TypeToken<WebResult<ObjectInfo>>(){}.getType();
-        WebResult<ObjectInfo> webResult = JsonConverter.jsonToObject(body, type);
-        if (webResult.getCode() != 0) {
-            String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
-            throw new Exception(errMsg);
-        }
-
-        return webResult.getData();
-    }
-
-    public DownloadUrl getDownloadUrl(String objectId) throws Exception {
-        String api = String.format("%s/api/oss/object/url?objectId=%s", endpoint, objectId);
-        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
-                .header("authorization", "Bearer " + token)
-                .version(HttpClient.Version.HTTP_1_1)
-                .GET()
-                .build();
-        HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
-        int statusCode = httpResponse.statusCode();
-        String body = httpResponse.body();
-        if (statusCode != 200) {
-            String errMsg = String.format("%s -> %s", statusCode, body);
-            throw new Exception(errMsg);
-        }
-
-        Type type = new TypeToken<WebResult<DownloadUrl>>(){}.getType();
-        WebResult<DownloadUrl> webResult = JsonConverter.jsonToObject(body, type);
-        if (webResult.getCode() != 0) {
-            String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
-            throw new Exception(errMsg);
-        }
-
-        return webResult.getData();
-    }
-
-    public void setObjectScope(int scope, String objectId, int contentType) throws Exception {
-        String api = String.format("%s/api/oss/media/scope/object", endpoint);
+    // ****************************************************************************************************************
+    // Object 相关接口
+    // ****************************************************************************************************************
+    public void setObjectScope(int channelId, String objectId, int scope) throws Exception {
         /*MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
         publisher.addPart("scope", scope+"");
         publisher.addPart("objectId", objectId);
         publisher.addPart("contentType", contentType+"");*/
 
         Map<String, String> formData = new HashMap<>();
-        formData.put("scope", scope+"");
+        formData.put("channelId", channelId+"");
         formData.put("objectId", objectId);
-        formData.put("contentType", contentType+"");
+        formData.put("scope", scope+"");
 
+        String api = String.format("%s/api/oss/object/scope/object", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .headers("content-type", "application/x-www-form-urlencoded")
@@ -285,7 +240,7 @@ public class OssConsoleClient {
         formData.put("scope", scope+"");
         formData.put("objectNames", objectNamesStr);
 
-        String api = String.format("%s/api/oss/media/scope/objects", endpoint);
+        String api = String.format("%s/api/oss/object/scope/objects", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .headers("content-type", "application/x-www-form-urlencoded")
@@ -322,7 +277,7 @@ public class OssConsoleClient {
     }
 
     public void deleteByObjectNames(List<String> objectNames) throws Exception {
-        String api = String.format("%s/api/oss/media/image/delete/name", endpoint);
+        String api = String.format("%s/api/oss/object/delete/name", endpoint);
         HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
 
         String objectNamesStr = objectNames.toString().replace("[", "").replace("]", "");
@@ -346,11 +301,8 @@ public class OssConsoleClient {
         }
     }
 
-    // ****************************************************************************************************************
-    // 视频文件相关接口
-    // ****************************************************************************************************************
-    public VideoInfo getVideoInfo(int channelId, String videoFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/video/info?channelId=%s&videoFileId=%s", endpoint, channelId, videoFileId);
+    public DownloadUrl getDownloadUrl(String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/url?objectId=%s", endpoint, objectId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .version(HttpClient.Version.HTTP_1_1)
@@ -364,8 +316,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<VideoInfo>>(){}.getType();
-        WebResult<VideoInfo> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<DownloadUrl>>(){}.getType();
+        WebResult<DownloadUrl> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -374,8 +326,8 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public List<VideoUrlDto> getVideoUrls(int channelId, String videoFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/video/url?channelId=%s&videoFileId=%s", endpoint, channelId, videoFileId);
+    public ObjectInfo getObjectInfo(int channelId, String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/info?channelId=%s&objectId=%s", endpoint, channelId, objectId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .version(HttpClient.Version.HTTP_1_1)
@@ -389,8 +341,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<List<VideoUrlDto>>>(){}.getType();
-        WebResult<List<VideoUrlDto>> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<ObjectInfo>>(){}.getType();
+        WebResult<ObjectInfo> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -399,13 +351,23 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    @Deprecated
-    public LocalDateTime getCreateTime(int channelId, String videoFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/video/time?channelId=%s&videoFileId=%s", endpoint, channelId, videoFileId);
+    // ****************************************************************************************************************
+    // 媒体文件相关接口
+    // ****************************************************************************************************************
+    public void setMediaScope(int channelId, int contentType, List<String> mediaIds, int scope) throws Exception {
+        String mediaIdsStr = mediaIds.toString().replace("[", "").replace("]", "");
+        Map<String, String> formData = new HashMap<>();
+        formData.put("channelId", channelId+"");
+        formData.put("contentType", contentType+"");
+        formData.put("mediaIds", mediaIdsStr);
+        formData.put("scope", scope+"");
+
+        String api = String.format("%s/api/oss/media/scope", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
+                .headers("content-type", "application/x-www-form-urlencoded")
                 .version(HttpClient.Version.HTTP_1_1)
-                .GET()
+                .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
                 .build();
         HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
         int statusCode = httpResponse.statusCode();
@@ -415,28 +377,28 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<LocalDateTime>>(){}.getType();
-        WebResult<LocalDateTime> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<String>>(){}.getType();
+        WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
         }
-
-        return webResult.getData();
     }
 
-    // ****************************************************************************************************************
-    // 图片文件相关接口
-    // ****************************************************************************************************************
-    public void deleteByImageFileIds(List<String> imageFileIds) throws Exception {
-        String api = String.format("%s/api/oss/media/image/delete/id", endpoint);
-        HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
-
-        String imageFileIdsStr = imageFileIds.toString().replace("[", "").replace("]", "");
-        MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
-        publisher.addPart("imageFileIds", imageFileIdsStr);
+    public void deleteMediaFile(int channelId, int contentType, List<String> mediaIds) throws Exception {
+        String mediaIdsStr = mediaIds.toString().replace("[", "").replace("]", "");
+        Map<String, String> formData = new HashMap<>();
+        formData.put("channelId", channelId+"");
+        formData.put("contentType", contentType+"");
+        formData.put("mediaIds", mediaIdsStr);
 
-        HttpRequest httpRequest = builder.POST(publisher.build()).build();
+        String api = String.format("%s/api/oss/media/delete", endpoint);
+        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
+                .header("authorization", "Bearer " + token)
+                .headers("content-type", "application/x-www-form-urlencoded")
+                .version(HttpClient.Version.HTTP_1_1)
+                .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
+                .build();
         HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
         int statusCode = httpResponse.statusCode();
         String body = httpResponse.body();
@@ -453,18 +415,12 @@ public class OssConsoleClient {
         }
     }
 
-    public List<ImageUrlDto> getImageUrls(int channelId, Set<String> imageFileIds) throws Exception {
-        String imageFileIdsStr = imageFileIds.toString().replace("[", "").replace("]", "");
-        Map<String, String> formData = new HashMap<>();
-        formData.put("channelId", channelId+"");
-        formData.put("imageFileIds", imageFileIdsStr);
-
-        String api = String.format("%s/api/oss/media/image/urls", endpoint);
+    public List<VideoUrlDto> getVideoUrls(int channelId, String videoFileId) throws Exception {
+        String api = String.format("%s/api/oss/media/video/url?channelId=%s&videoFileId=%s", endpoint, channelId, videoFileId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
-                .headers("content-type", "application/x-www-form-urlencoded")
                 .version(HttpClient.Version.HTTP_1_1)
-                .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
+                .GET()
                 .build();
         HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
         int statusCode = httpResponse.statusCode();
@@ -474,8 +430,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<List<ImageUrlDto>>>(){}.getType();
-        WebResult<List<ImageUrlDto>> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<List<VideoUrlDto>>>(){}.getType();
+        WebResult<List<VideoUrlDto>> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -484,10 +440,13 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public void deleteVideoFile(String videoFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/video/delete/%s", endpoint, videoFileId);
-        HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
-        HttpRequest httpRequest = builder.DELETE().build();
+    public VideoInfo getVideoInfo(int channelId, String videoFileId) throws Exception {
+        String api = String.format("%s/api/oss/media/video/info?channelId=%s&videoFileId=%s", endpoint, channelId, videoFileId);
+        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
+                .header("authorization", "Bearer " + token)
+                .version(HttpClient.Version.HTTP_1_1)
+                .GET()
+                .build();
         HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
         int statusCode = httpResponse.statusCode();
         String body = httpResponse.body();
@@ -496,23 +455,28 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<String>>(){}.getType();
-        WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<VideoInfo>>(){}.getType();
+        WebResult<VideoInfo> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
         }
+
+        return webResult.getData();
     }
 
-    // ****************************************************************************************************************
-    // 音频文件相关接口
-    // ****************************************************************************************************************
-    public AudioInfo getAudioInfo(String audioFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/audio/info/%s", endpoint, audioFileId);
+    public List<ImageUrlDto> getImageUrls(int channelId, Set<String> imageFileIds) throws Exception {
+        String imageFileIdsStr = imageFileIds.toString().replace("[", "").replace("]", "");
+        Map<String, String> formData = new HashMap<>();
+        formData.put("channelId", channelId+"");
+        formData.put("imageFileIds", imageFileIdsStr);
+
+        String api = String.format("%s/api/oss/media/image/urls", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
+                .headers("content-type", "application/x-www-form-urlencoded")
                 .version(HttpClient.Version.HTTP_1_1)
-                .GET()
+                .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
                 .build();
         HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
         int statusCode = httpResponse.statusCode();
@@ -522,8 +486,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<AudioInfo>>(){}.getType();
-        WebResult<AudioInfo> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<List<ImageUrlDto>>>(){}.getType();
+        WebResult<List<ImageUrlDto>> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -557,6 +521,31 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
+    public AudioInfo getAudioInfo(String audioFileId) throws Exception {
+        String api = String.format("%s/api/oss/media/audio/info/%s", endpoint, audioFileId);
+        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
+                .header("authorization", "Bearer " + token)
+                .version(HttpClient.Version.HTTP_1_1)
+                .GET()
+                .build();
+        HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
+        int statusCode = httpResponse.statusCode();
+        String body = httpResponse.body();
+        if (statusCode != 200) {
+            String errMsg = String.format("%s -> %s", statusCode, body);
+            throw new Exception(errMsg);
+        }
+
+        Type type = new TypeToken<WebResult<AudioInfo>>(){}.getType();
+        WebResult<AudioInfo> webResult = JsonConverter.jsonToObject(body, type);
+        if (webResult.getCode() != 0) {
+            String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
+            throw new Exception(errMsg);
+        }
+
+        return webResult.getData();
+    }
+
     // ****************************************************************************************************************
     // 音视频转码相关接口
     // ****************************************************************************************************************