|
|
@@ -0,0 +1,526 @@
|
|
|
+package cn.reghao.oss.sdk;
|
|
|
+
|
|
|
+import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
+import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
+import cn.reghao.oss.api.dto.DownloadUrl;
|
|
|
+import cn.reghao.oss.api.dto.ObjectInfo;
|
|
|
+import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
+import cn.reghao.oss.api.dto.media.*;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
+
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.http.HttpClient;
|
|
|
+import java.net.http.HttpRequest;
|
|
|
+import java.net.http.HttpResponse;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2024-02-23 21:47:39
|
|
|
+ */
|
|
|
+public class OssClient {
|
|
|
+ private final String endpoint;
|
|
|
+ private final HttpClient httpClient;
|
|
|
+
|
|
|
+ public OssClient(String endpoint) {
|
|
|
+ this.endpoint = endpoint;
|
|
|
+ this.httpClient = HttpClient.newBuilder().build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ServerInfo getServerInfo(long userId, int channelId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/server/info?userId=%s&channelId=%s", endpoint, userId, channelId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return webResult.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ObjectInfo getObjectInfo(String objectId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/object/info?objectId=%s", endpoint, objectId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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, int channelId, long userId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/object/url?objectId=%s&channelId=%s&userId=%s", endpoint, objectId, channelId, userId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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 convertVideo(String videoFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/convert/video/%s", endpoint, videoFileId);
|
|
|
+ convert(api);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void convertAudio(String audioFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/convert/audio/%s", endpoint, audioFileId);
|
|
|
+ convert(api);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void convert(String api) throws Exception {
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
+ public void setVideoScope(String videoFileId, int scope) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/scope/video", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("videoId", videoFileId);
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
+ public void setAudioScope(String audioFileId, int scope) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/scope/audio", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("audioFileId", audioFileId);
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
+ public void setImagesScope(Set<String> imageFileIds, int scope) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/scope/image", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("imageFileIds", imageFileIds.toString());
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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 void setObjectScope(int scope, String objectId, int contentType) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/scope/object", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+ publisher.addPart("objectId", objectId);
|
|
|
+ publisher.addPart("contentType", contentType+"");
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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 void setObjectsScope(int scope, List<String> objectIds, int contentType) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/scope/objects", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("scope", scope+"");
|
|
|
+ publisher.addPart("objectIds", objectIds.toString());
|
|
|
+ publisher.addPart("contentType", contentType+"");
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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 AudioInfo getAudioInfo(String audioFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/audio/info/%s", endpoint, audioFileId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<AudioUrl> getAudioUrls(String audioFileId, long loginUser) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/audio/url?audioFileId=%s&userId=%s", endpoint, audioFileId, loginUser);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return webResult.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByObjectNames(List<String> objectNames) throws Exception {
|
|
|
+ String api = String.format("%s/api/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();
|
|
|
+ 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 void deleteByImageFileIds(List<String> imageFileIds) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/image/delete/id", endpoint);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+
|
|
|
+ MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
+ publisher.addPart("imageFileIds", imageFileIds.toString());
|
|
|
+
|
|
|
+ HttpRequest httpRequest = builder.POST(publisher.build()).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 ImageUrlDto getImageUrl(int channelId, String imageFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/image/url?channelId=%s&imageFileId=%s", endpoint, channelId, imageFileId);
|
|
|
+ //String api = String.format("%s/api/media/image/url?channelId=%s&imageFileId=%s&loginUser=%s", endpoint, channelId, imageFileId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<ImageUrlDto>>(){}.getType();
|
|
|
+ WebResult<ImageUrlDto> 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 ImageUrlDto getImageUrl(String imageFileId, long loginUser, int channelId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/image/url?channelId=%s&imageFileId=%s&loginUser=%s", endpoint, channelId, imageFileId, loginUser);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<ImageUrlDto>>(){}.getType();
|
|
|
+ WebResult<ImageUrlDto> 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 List<ImageUrlDto> getImageUrls(Set<String> imageFileIds) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/image/urls?imageFileIds=%s", endpoint, imageFileIds.toString());
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return webResult.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSignedUrl(String url, long loginUser, int channelId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/image/signedurl?channelId=%s&url=%s&loginUser=%s", endpoint, channelId, url, loginUser);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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 deleteVideoFile(String videoFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/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();
|
|
|
+ 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 VideoInfo getVideoInfo(String videoFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/video/info/%s", endpoint, videoFileId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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 List<VideoUrlDto> getVideoUrls(String videoFileId, long loginUser) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/video/url?videoFileId=%s&userId=%s", endpoint, videoFileId, loginUser);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return webResult.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public LocalDateTime getCreateTime(String videoFileId) throws Exception {
|
|
|
+ String api = String.format("%s/api/media/video/time/%s", endpoint, videoFileId);
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
+ HttpRequest httpRequest = builder.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<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();
|
|
|
+ }
|
|
|
+}
|