|
@@ -2,6 +2,7 @@ package thyyxxk.webserver.service.archive;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.format.FastDateFormat;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.crypto.asymmetric.KeyType;
|
|
|
import cn.hutool.crypto.asymmetric.RSA;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.dtflys.forest.Forest;
|
|
|
import com.dtflys.forest.http.ForestRequest;
|
|
|
import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -22,9 +24,14 @@ import thyyxxk.webserver.service.externalhttp.WebSocketService;
|
|
|
import thyyxxk.webserver.service.redislike.RedisLikeService;
|
|
|
import thyyxxk.webserver.utils.*;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ArchiveServer {
|
|
|
private static ArchiveConfig archiveData;
|
|
@@ -221,5 +228,70 @@ public class ArchiveServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public UploadResult uploadFileByStr(String data, String path, boolean isTest, String userCode) {
|
|
|
+ JSONObject execute;
|
|
|
+
|
|
|
+ Map<String, Object> body = new HashMap<>();
|
|
|
+ body.put("data", data);
|
|
|
+ body.put("path", path);
|
|
|
+ body.put("isTest", isTest);
|
|
|
+
|
|
|
+ try {
|
|
|
+ execute = sendApi("/uploadByStr", userCode)
|
|
|
+ .addHeader("content-type", "application/json")
|
|
|
+ .addBody(body)
|
|
|
+ .execute(JSONObject.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "上传文件错误:" + e.getMessage());
|
|
|
+ }
|
|
|
+ Integer code = execute.getInteger("code");
|
|
|
+
|
|
|
+ if (ExceptionEnum.SUCCESS.getCode() != code) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "上传文件错误:" + execute.getString("message"));
|
|
|
+ }
|
|
|
+ return execute.getObject("data", UploadResult.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public UploadResult uploadFileByStr(String data, String path, boolean isTest) {
|
|
|
+ return uploadFileByStr(data, path, isTest, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UploadResult uploadFileByStr(String data, String path) {
|
|
|
+ return uploadFileByStr(data, path, !isProd, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UploadResult uploadFileByBytes(byte[] data, String path, boolean isTest, String userCode) {
|
|
|
+ JSONObject execute;
|
|
|
+
|
|
|
+ Map<String, Object> body = new HashMap<>();
|
|
|
+ body.put("data", data);
|
|
|
+ body.put("path", path);
|
|
|
+ body.put("isTest", isTest);
|
|
|
+
|
|
|
+ try {
|
|
|
+ execute = sendApi("/uploadByByte", userCode)
|
|
|
+ .addHeader("content-type", "application/json")
|
|
|
+ .addBody(body)
|
|
|
+ .execute(JSONObject.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "上传文件错误:" + e.getMessage());
|
|
|
+ }
|
|
|
+ Integer code = execute.getInteger("code");
|
|
|
+
|
|
|
+ if (ExceptionEnum.SUCCESS.getCode() != code) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "上传文件错误:" + execute.getString("message"));
|
|
|
+ }
|
|
|
+ return execute.getObject("data", UploadResult.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UploadResult uploadFileByBytes(byte[] data, String path, boolean isTest) {
|
|
|
+ return uploadFileByBytes(data, path, isTest, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public UploadResult uploadFileByBytes(byte[] data, String path) {
|
|
|
+ return uploadFileByBytes(data, path, !isProd, null);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|