reghao před 1 rokem
rodič
revize
b9eb7c687d

+ 1 - 2
oss-api/src/main/java/cn/reghao/oss/api/iface/StoreServiceWrapper.java

@@ -15,11 +15,10 @@ import cn.reghao.oss.api.dto.media.VideoInfo;
  * @date 2024-04-23 15:14:06
  */
 public interface StoreServiceWrapper {
-    int getChannelScope(int channelId);
-
     void createChannel(int channelId, String channelPrefix);
     StoreInfo getStoreInfo(int channelId);
 
+    int getChannelScope(int channelId);
     void setObjectScope(int channelId, String objectId, int scope);
     void deleteByObjectId(int channelId, String objectId);
     void deleteByObjectUrl(String objectUrl);

+ 40 - 128
oss-sdk/src/main/java/cn/reghao/oss/sdk/OssConsoleClient.java

@@ -75,57 +75,10 @@ public class OssConsoleClient {
     }
 
     // ****************************************************************************************************************
-    // oss-store 调用的接口(不需要认证)
+    // oss-store 相关接口
     // ****************************************************************************************************************
-    public void registerNode(String jsonPayload) throws Exception {
-        String api = String.format("%s/api/oss/store/register", endpoint);
-        HttpClient httpClient = HttpClient.newBuilder().build();
-        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
-                .header("content-type", "application/json")
-                .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
-                .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<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);
-        }
-    }
-
-    public List<ObjectChannel> getObjectChannels(String nodeAddr) throws Exception {
-        String api = String.format("%s/api/oss/store/channels?nodeAddr=%s", endpoint, nodeAddr);
-        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
-                .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<List<ObjectChannel>>>(){}.getType();
-        WebResult<List<ObjectChannel>> 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 ObjectChannel getObjectChannel(int channelId) throws Exception {
-        String api = String.format("%s/api/oss/server/channel?channelId=%s", endpoint, channelId);
+    public ServerInfo getUploadStore(int channelId) throws Exception {
+        String api = String.format("%s/api/oss/upload/store?channelId=%s", endpoint, channelId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .version(HttpClient.Version.HTTP_1_1)
@@ -139,32 +92,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<ObjectChannel>>(){}.getType();
-        WebResult<ObjectChannel> 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 StoreProperties getStoreProperties(String nodeAddr) throws Exception {
-        String api = String.format("%s/api/oss/store/properties?nodeAddr=%s", endpoint, nodeAddr);
-        HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
-                .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<StoreProperties>>(){}.getType();
-        WebResult<StoreProperties> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
+        WebResult<ServerInfo> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -173,11 +102,8 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    // ****************************************************************************************************************
-    // oss-store 相关接口
-    // ****************************************************************************************************************
-    public ServerInfo getServerInfo(int channelId) throws Exception {
-        String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
+    public ObjectInfo getChannelScope(int channelId) throws Exception {
+        String api = String.format("%s/api/oss/channel/scope?channelId=%s", endpoint, channelId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .version(HttpClient.Version.HTTP_1_1)
@@ -191,8 +117,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
-        WebResult<ServerInfo> 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);
@@ -201,17 +127,13 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    // ****************************************************************************************************************
-    // Object 相关接口
-    // ****************************************************************************************************************
-    public void setObjectsScope(int channelId, List<String> objectIds, int scope) throws Exception {
-        String objectIdsStr = objectIds.toString().replace("[", "").replace("]", "");
+    public void setObjectScope(int channelId, String objectId, int scope) throws Exception {
         Map<String, String> formData = new HashMap<>();
         formData.put("channelId", channelId+"");
         formData.put("scope", scope+"");
-        formData.put("objectIds", objectIdsStr);
+        formData.put("objectId", objectId);
 
-        String api = String.format("%s/api/oss/object/scope/objects", endpoint);
+        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")
@@ -247,13 +169,12 @@ public class OssConsoleClient {
         return formBodyBuilder.toString();
     }
 
-    public void deleteByObjectIds(int channelId, List<String> objectIds) throws Exception {
-        String objectIdsStr = objectIds.toString().replace("[", "").replace("]", "");
+    public void deleteByObjectId(int channelId, String objectId) throws Exception {
         Map<String, String> formData = new HashMap<>();
         formData.put("channelId", channelId+"");
-        formData.put("objectIds", objectIdsStr);
+        formData.put("objectId", objectId);
 
-        String api = String.format("%s/api/oss/object/delete/ids", endpoint);
+        String api = String.format("%s/api/oss/object/delete/id", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .headers("content-type", "application/x-www-form-urlencoded")
@@ -303,8 +224,8 @@ public class OssConsoleClient {
         }
     }
 
-    public String getSignedUrl(int channelId, String objectId) throws Exception {
-        String api = String.format("%s/api/oss/object/url?channelId=%s&objectId=%s", endpoint, channelId, objectId);
+    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)
@@ -318,8 +239,8 @@ 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<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);
@@ -328,8 +249,8 @@ 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);
+    public String getSignedUrl(int channelId, String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/url?channelId=%s&objectId=%s", endpoint, channelId, objectId);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .version(HttpClient.Version.HTTP_1_1)
@@ -343,8 +264,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<ObjectInfo>>(){}.getType();
-        WebResult<ObjectInfo> 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);
@@ -353,11 +274,8 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    // ****************************************************************************************************************
-    // 媒体文件相关接口
-    // ****************************************************************************************************************
-    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 VideoInfo getVideoInfo(int channelId, String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/video/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)
@@ -381,18 +299,13 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public List<ImageInfo> getImagesInfo(int channelId, List<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/info", endpoint);
+    public ImageInfo getImageInfo(int channelId, String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/video/image?channelId=%s&objectId=%s", endpoint, channelId, objectId);
         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();
@@ -402,8 +315,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<List<ImageInfo>>>(){}.getType();
-        WebResult<List<ImageInfo>> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<ImageInfo>>(){}.getType();
+        WebResult<ImageInfo> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -412,13 +325,12 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public List<ConvertedImageInfo> getWebpInfo(int channelId, List<String> imageFileIds) throws Exception {
-        String imageFileIdsStr = imageFileIds.toString().replace("[", "").replace("]", "");
+    public ConvertedImageInfo getWebpInfo(int channelId, String objectId) throws Exception {
         Map<String, String> formData = new HashMap<>();
         formData.put("channelId", ""+channelId);
-        formData.put("imageFileIds", imageFileIdsStr);
+        formData.put("objectId", objectId);
 
-        String api = String.format("%s/api/oss/media/image/webp", endpoint);
+        String api = String.format("%s/api/oss/object/image/webp", endpoint);
         HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
                 .header("authorization", "Bearer " + token)
                 .headers("content-type", "application/x-www-form-urlencoded")
@@ -433,8 +345,8 @@ public class OssConsoleClient {
             throw new Exception(errMsg);
         }
 
-        Type type = new TypeToken<WebResult<List<ConvertedImageInfo>>>(){}.getType();
-        WebResult<List<ConvertedImageInfo>> webResult = JsonConverter.jsonToObject(body, type);
+        Type type = new TypeToken<WebResult<ConvertedImageInfo>>(){}.getType();
+        WebResult<ConvertedImageInfo> webResult = JsonConverter.jsonToObject(body, type);
         if (webResult.getCode() != 0) {
             String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
             throw new Exception(errMsg);
@@ -443,8 +355,8 @@ public class OssConsoleClient {
         return webResult.getData();
     }
 
-    public AudioInfo getAudioInfo(int channelId, String audioFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/audio/info/?channelId=%s&audioFileId=%s", endpoint, channelId, audioFileId);
+    public AudioInfo getAudioInfo(int channelId, String objectId) throws Exception {
+        String api = String.format("%s/api/oss/object/audio/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)
@@ -472,12 +384,12 @@ public class OssConsoleClient {
     // 音视频转码相关接口
     // ****************************************************************************************************************
     public void convertAudio(String audioFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/convert/audio/%s", endpoint, audioFileId);
+        String api = String.format("%s/api/oss/object/convert/audio/%s", endpoint, audioFileId);
         convert(api);
     }
 
     public void convertVideo(String videoFileId) throws Exception {
-        String api = String.format("%s/api/oss/media/convert/video/%s", endpoint, videoFileId);
+        String api = String.format("%s/api/oss/object/convert/video/%s", endpoint, videoFileId);
         convert(api);
     }
 
@@ -505,7 +417,7 @@ public class OssConsoleClient {
     }
 
     public UploadFileRet uploadFile(int channelId, File file) throws Exception {
-        ServerInfo serverInfo = getServerInfo(channelId);
+        ServerInfo serverInfo = getUploadStore(channelId);
         if (serverInfo == null) {
             throw new Exception("获取 server_info 失败");
         }

+ 1 - 1
oss-sdk/src/test/java/OssConsoleClientTest.java

@@ -32,7 +32,7 @@ public class OssConsoleClientTest {
         OssConsoleClient ossConsoleClient = new OssConsoleClient(ossProperties);
 
         int channelId = 101;
-        ServerInfo serverInfo = ossConsoleClient.getServerInfo(channelId);
+        ServerInfo serverInfo = ossConsoleClient.getUploadStore(channelId);
         if (serverInfo == null) {
             log.info("获取 server_info 失败");
             return;