|
@@ -13,7 +13,6 @@ import java.net.http.HttpClient;
|
|
|
import java.net.http.HttpRequest;
|
|
import java.net.http.HttpRequest;
|
|
|
import java.net.http.HttpResponse;
|
|
import java.net.http.HttpResponse;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -37,6 +36,9 @@ public class OssConsoleClient {
|
|
|
this.endpoint = endpoint;
|
|
this.endpoint = endpoint;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ****************************************************************************************************************
|
|
|
|
|
+ // oss-console 认证接口
|
|
|
|
|
+ // ****************************************************************************************************************
|
|
|
private void auth(String accessKeyId, String accessKeySecret) throws Exception {
|
|
private void auth(String accessKeyId, String accessKeySecret) throws Exception {
|
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
|
|
|
.addPart("accessKeyId", accessKeyId)
|
|
.addPart("accessKeyId", accessKeyId)
|
|
@@ -167,7 +169,7 @@ public class OssConsoleClient {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ****************************************************************************************************************
|
|
// ****************************************************************************************************************
|
|
|
- // Object 相关接口
|
|
|
|
|
|
|
+ // oss-store 相关接口
|
|
|
// ****************************************************************************************************************
|
|
// ****************************************************************************************************************
|
|
|
public ServerInfo getServerInfo(int channelId) throws Exception {
|
|
public ServerInfo getServerInfo(int channelId) throws Exception {
|
|
|
String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
|
|
String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
|
|
@@ -194,68 +196,21 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
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();
|
|
/*MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
publisher.addPart("scope", scope+"");
|
|
publisher.addPart("scope", scope+"");
|
|
|
publisher.addPart("objectId", objectId);
|
|
publisher.addPart("objectId", objectId);
|
|
|
publisher.addPart("contentType", contentType+"");*/
|
|
publisher.addPart("contentType", contentType+"");*/
|
|
|
|
|
|
|
|
Map<String, String> formData = new HashMap<>();
|
|
Map<String, String> formData = new HashMap<>();
|
|
|
- formData.put("scope", scope+"");
|
|
|
|
|
|
|
+ formData.put("channelId", channelId+"");
|
|
|
formData.put("objectId", objectId);
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
.headers("content-type", "application/x-www-form-urlencoded")
|
|
.headers("content-type", "application/x-www-form-urlencoded")
|
|
@@ -285,7 +240,7 @@ public class OssConsoleClient {
|
|
|
formData.put("scope", scope+"");
|
|
formData.put("scope", scope+"");
|
|
|
formData.put("objectNames", objectNamesStr);
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
.headers("content-type", "application/x-www-form-urlencoded")
|
|
.headers("content-type", "application/x-www-form-urlencoded")
|
|
@@ -322,7 +277,7 @@ public class OssConsoleClient {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void deleteByObjectNames(List<String> objectNames) throws Exception {
|
|
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);
|
|
HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
|
|
|
|
|
String objectNamesStr = objectNames.toString().replace("[", "").replace("]", "");
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
@@ -364,8 +316,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
throw new Exception(errMsg);
|
|
@@ -374,8 +326,8 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
@@ -389,8 +341,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
throw new Exception(errMsg);
|
|
@@ -399,13 +351,23 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
|
|
+ .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
.build();
|
|
.build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
int statusCode = httpResponse.statusCode();
|
|
@@ -415,28 +377,28 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
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());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
int statusCode = httpResponse.statusCode();
|
|
|
String body = httpResponse.body();
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
|
|
|
|
+ .GET()
|
|
|
.build();
|
|
.build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
int statusCode = httpResponse.statusCode();
|
|
@@ -474,8 +430,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
throw new Exception(errMsg);
|
|
@@ -484,10 +440,13 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
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());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
int statusCode = httpResponse.statusCode();
|
|
|
String body = httpResponse.body();
|
|
String body = httpResponse.body();
|
|
@@ -496,23 +455,28 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
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))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("authorization", "Bearer " + token)
|
|
.header("authorization", "Bearer " + token)
|
|
|
|
|
+ .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
|
|
|
|
+ .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
.build();
|
|
.build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
int statusCode = httpResponse.statusCode();
|
|
int statusCode = httpResponse.statusCode();
|
|
@@ -522,8 +486,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
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) {
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
throw new Exception(errMsg);
|
|
@@ -557,6 +521,31 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
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();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ****************************************************************************************************************
|
|
// ****************************************************************************************************************
|
|
|
// 音视频转码相关接口
|
|
// 音视频转码相关接口
|
|
|
// ****************************************************************************************************************
|
|
// ****************************************************************************************************************
|