|
|
@@ -8,11 +8,15 @@ import com.google.gson.reflect.TypeToken;
|
|
|
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.net.URI;
|
|
|
+import java.net.URLEncoder;
|
|
|
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;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
@@ -239,22 +243,23 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public void convertVideo(String videoFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/convert/video/%s", endpoint, videoFileId);
|
|
|
- convert(api);
|
|
|
- }
|
|
|
+ public void setObjectScope(int scope, String objectId, int contentType) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/media/scope/object", endpoint);
|
|
|
+ /*MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+ publisher.addPart("objectId", objectId);
|
|
|
+ publisher.addPart("contentType", contentType+"");*/
|
|
|
|
|
|
- public void convertAudio(String audioFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/convert/audio/%s", endpoint, audioFileId);
|
|
|
- convert(api);
|
|
|
- }
|
|
|
+ Map<String, String> formData = new HashMap<>();
|
|
|
+ formData.put("scope", scope+"");
|
|
|
+ formData.put("objectId", objectId);
|
|
|
+ formData.put("contentType", contentType+"");
|
|
|
|
|
|
- private void convert(String api) throws Exception {
|
|
|
- MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
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(publisher.build())
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
.build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
|
@@ -272,11 +277,12 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void setObjectScope(int scope, String objectId, int contentType) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/scope/object", endpoint);
|
|
|
+ public void setObjectsScope(int scope, List<String> objectIds, int contentType) throws Exception {
|
|
|
+ String objectIdsStr = objectIds.toString().replace("[", "").replace("]", "");
|
|
|
+ String api = String.format("%s/api/oss/media/scope/objects", endpoint);
|
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
publisher.addPart("scope", scope+"");
|
|
|
- publisher.addPart("objectId", objectId);
|
|
|
+ publisher.addPart("objectIds", objectIdsStr);
|
|
|
publisher.addPart("contentType", contentType+"");
|
|
|
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
@@ -300,18 +306,28 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void setObjectsScope(int scope, List<String> objectIds, int contentType) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/scope/objects", endpoint);
|
|
|
+ private String getFormDataAsString(Map<String, String> formData) {
|
|
|
+ StringBuilder formBodyBuilder = new StringBuilder();
|
|
|
+ for (Map.Entry<String, String> singleEntry : formData.entrySet()) {
|
|
|
+ if (formBodyBuilder.length() > 0) {
|
|
|
+ formBodyBuilder.append("&");
|
|
|
+ }
|
|
|
+ formBodyBuilder.append(URLEncoder.encode(singleEntry.getKey(), StandardCharsets.UTF_8));
|
|
|
+ formBodyBuilder.append("=");
|
|
|
+ formBodyBuilder.append(URLEncoder.encode(singleEntry.getValue(), StandardCharsets.UTF_8));
|
|
|
+ }
|
|
|
+ return formBodyBuilder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByObjectNames(List<String> objectNames) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/media/image/delete/name", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ String objectNamesStr = objectNames.toString().replace("[", "").replace("]", "");
|
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
- publisher.addPart("scope", scope+"");
|
|
|
- publisher.addPart("objectIds", objectIds.toString());
|
|
|
- publisher.addPart("contentType", contentType+"");
|
|
|
+ publisher.addPart("objectNames", objectNamesStr);
|
|
|
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(publisher.build())
|
|
|
- .build();
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
|
String body = httpResponse.body();
|
|
|
@@ -328,8 +344,11 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public AudioInfo getAudioInfo(String audioFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/audio/info/%s", endpoint, audioFileId);
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ // 视频文件相关接口
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ 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)
|
|
|
@@ -343,8 +362,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<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);
|
|
|
@@ -353,8 +372,8 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public List<AudioUrl> getAudioUrls(String audioFileId, int loginUser) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/audio/url?audioFileId=%s&userId=%s", endpoint, audioFileId, loginUser);
|
|
|
+ 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)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
@@ -368,8 +387,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
|
}
|
|
|
|
|
|
- Type type = new TypeToken<WebResult<List<AudioUrl>>>(){}.getType();
|
|
|
- WebResult<List<AudioUrl>> 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);
|
|
|
@@ -378,14 +397,14 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public void deleteByObjectNames(List<String> objectNames) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/image/delete/name", endpoint);
|
|
|
- HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
-
|
|
|
- MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
- publisher.addPart("objectNames", objectNames.toString());
|
|
|
-
|
|
|
- HttpRequest httpRequest = builder.POST(publisher.build()).build();
|
|
|
+ @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);
|
|
|
+ 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();
|
|
|
@@ -394,20 +413,26 @@ 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<LocalDateTime>>(){}.getType();
|
|
|
+ WebResult<LocalDateTime> 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", imageFileIds.toString());
|
|
|
+ publisher.addPart("imageFileIds", imageFileIdsStr);
|
|
|
|
|
|
HttpRequest httpRequest = builder.POST(publisher.build()).build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
@@ -426,8 +451,9 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public List<ImageUrlDto> getImageUrls(Set<String> imageFileIds) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/image/urls?imageFileIds=%s", endpoint, imageFileIds.toString());
|
|
|
+ public List<ImageUrlDto> getImageUrls(int channelId, Set<String> imageFileIds) throws Exception {
|
|
|
+ String imageFileIdsStr = imageFileIds.toString().replace("[", "").replace("]", "");
|
|
|
+ String api = String.format("%s/api/oss/media/image/urls?channelId=%s&imageFileIds=%s", endpoint, channelId, imageFileIdsStr);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
@@ -471,8 +497,11 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public VideoInfo getVideoInfo(String videoFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/video/info/%s", endpoint, videoFileId);
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ // 音频文件相关接口
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ 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)
|
|
|
@@ -486,8 +515,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<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);
|
|
|
@@ -496,8 +525,8 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public List<VideoUrlDto> getVideoUrls(String videoFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/video/url?videoFileId=%s", endpoint, videoFileId);
|
|
|
+ public List<AudioUrl> getAudioUrls(String audioFileId, int loginUser) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/media/audio/url?audioFileId=%s&userId=%s", endpoint, audioFileId, loginUser);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
@@ -511,8 +540,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<List<AudioUrl>>>(){}.getType();
|
|
|
+ WebResult<List<AudioUrl>> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
|
@@ -521,13 +550,25 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- @Deprecated
|
|
|
- public LocalDateTime getCreateTime(String videoFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/media/video/time/%s", endpoint, videoFileId);
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ // 音视频转码相关接口
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ public void convertAudio(String audioFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/media/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);
|
|
|
+ convert(api);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convert(String api) throws Exception {
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
+ .POST(publisher.build())
|
|
|
.build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
|
@@ -537,13 +578,11 @@ 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();
|
|
|
}
|
|
|
}
|