From b63a53834daba207722c22bdf029a30696d84754 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=A9=AC=E8=B6=85?= <1162714483@qq.com>
Date: Tue, 31 Jan 2023 13:44:36 +0800
Subject: [PATCH] =?UTF-8?q?feat(office=E6=96=87=E4=BB=B6=E9=A2=84=E8=A7=88?=
=?UTF-8?q?):=20=E9=AB=98=E7=89=88=E6=9C=AC=E6=9D=83=E9=99=90=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=E9=80=82=E9=85=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 11 +
.../file/controller/FileController.java | 2 +-
.../qiwenshare/file/office/entities/User.java | 2 +-
.../file/service/OfficeConverterService.java | 252 --------------
.../com/qiwenshare/file/util/FileModel.java | 313 ------------------
src/main/resources/config/settings.properties | 2 +-
6 files changed, 14 insertions(+), 568 deletions(-)
delete mode 100644 src/main/java/com/qiwenshare/file/service/OfficeConverterService.java
delete mode 100644 src/main/java/com/qiwenshare/file/util/FileModel.java
diff --git a/pom.xml b/pom.xml
index ca0a9f0..521a4f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,17 @@
jaudiotagger
+
+ com.inversoft
+ prime-jwt
+ 2.0.0
+
+
+ org.modelmapper
+ modelmapper
+ 2.4.2
+
+
diff --git a/src/main/java/com/qiwenshare/file/controller/FileController.java b/src/main/java/com/qiwenshare/file/controller/FileController.java
index e366f0b..299cae0 100644
--- a/src/main/java/com/qiwenshare/file/controller/FileController.java
+++ b/src/main/java/com/qiwenshare/file/controller/FileController.java
@@ -418,7 +418,7 @@ public class FileController {
String md5Str = fileDealComp.getIdentifierByFile(fileUrl, fileBean.getStorageType());
- fileService.updateFileDetail(userFile.getUserFileId(), md5Str, fileSize, sessionUserBean.getUserId());
+ fileService.updateFileDetail(userFile.getUserFileId(), md5Str, fileSize);
} catch (Exception e) {
diff --git a/src/main/java/com/qiwenshare/file/office/entities/User.java b/src/main/java/com/qiwenshare/file/office/entities/User.java
index 645661f..7f11b6c 100644
--- a/src/main/java/com/qiwenshare/file/office/entities/User.java
+++ b/src/main/java/com/qiwenshare/file/office/entities/User.java
@@ -42,7 +42,7 @@ public class User extends AbstractEntity {
public User(){}
public User(UserBean userBean) {
- this.id = userBean.getUserId();
+ this.id = String.valueOf(userBean.getUserId());
this.name = userBean.getUsername();
this.group = "";
diff --git a/src/main/java/com/qiwenshare/file/service/OfficeConverterService.java b/src/main/java/com/qiwenshare/file/service/OfficeConverterService.java
deleted file mode 100644
index 3986b39..0000000
--- a/src/main/java/com/qiwenshare/file/service/OfficeConverterService.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/**
- *
- * (c) Copyright Ascensio System SIA 2021
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.qiwenshare.file.service;
-
-import com.alibaba.fastjson2.JSONObject;
-import com.google.gson.Gson;
-import com.qiwenshare.file.component.JwtComp;
-import com.qiwenshare.file.helper.ConfigManager;
-import com.qiwenshare.file.helper.DocumentManager;
-import com.qiwenshare.file.helper.FileUtility;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.io.*;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-
-@Component
-public class OfficeConverterService
-{
- @Resource
- private JwtComp jwtComp;
- private static int ConvertTimeout = 120000;
- private static final String DocumentConverterUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.converter");
- private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
-
- public static class ConvertBody
- {
- public String url;
- public String outputtype;
- public String filetype;
- public String title;
- public String key;
- public Boolean async;
- public String token;
- public String password;
- }
-
- static
- {
- try
- {
- int timeout = Integer.parseInt(ConfigManager.GetProperty("files.docservice.timeout"));
- if (timeout > 0)
- {
- ConvertTimeout = timeout;
- }
- }
- catch (Exception ex)
- {
- }
- }
-
- public String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync) throws Exception
- {
- fromExtension = fromExtension == null || fromExtension.isEmpty() ? FileUtility.GetFileExtension(documentUri) : fromExtension;
-
- String title = FileUtility.GetFileName(documentUri);
- title = title == null || title.isEmpty() ? UUID.randomUUID().toString() : title;
-
- documentRevisionId = documentRevisionId == null || documentRevisionId.isEmpty() ? documentUri : documentRevisionId;
-
- documentRevisionId = GenerateRevisionId(documentRevisionId);
-
- ConvertBody body = new ConvertBody();
- body.url = documentUri;
- body.outputtype = toExtension.replace(".", "");
- body.filetype = fromExtension.replace(".", "");
- body.title = title;
- body.key = documentRevisionId;
- body.password = filePass;
- if (isAsync)
- body.async = true;
-
- String headerToken = "";
- if (DocumentManager.TokenEnabled())
- {
- HashMap map = new HashMap();
- map.put("url", body.url);
- map.put("outputtype", body.outputtype);
- map.put("filetype", body.filetype);
- map.put("title", body.title);
- map.put("key", body.key);
- map.put("password", body.password);
- if (isAsync)
- map.put("async", body.async);
-
- String token = jwtComp.createJWT(map);
- body.token = token;
-
- Map payloadMap = new HashMap();
- payloadMap.put("payload", map);
- headerToken = jwtComp.createJWT(payloadMap);
- }
-
- Gson gson = new Gson();
- String bodyString = gson.toJson(body);
-
- byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);
-
- URL url = new URL(DocumentConverterUrl);
- java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- connection.setDoOutput(true);
- connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
- connection.setFixedLengthStreamingMode(bodyByte.length);
- connection.setRequestProperty("Accept", "application/json");
- connection.setConnectTimeout(ConvertTimeout);
-
- if (DocumentManager.TokenEnabled())
- {
- connection.setRequestProperty(DocumentJwtHeader.equals("") ? "Authorization" : DocumentJwtHeader, "Bearer " + headerToken);
- }
-
- connection.connect();
- try (OutputStream os = connection.getOutputStream()) {
- os.write(bodyByte);
- }
-
- InputStream stream = connection.getInputStream();
-
- if (stream == null)
- throw new Exception("Could not get an answer");
-
- String jsonString = ConvertStreamToString(stream);
-
- connection.disconnect();
-
- return GetResponseUri(jsonString);
- }
-
- public static String GenerateRevisionId(String expectedKey)
- {
- if (expectedKey.length() > 20)
- expectedKey = Integer.toString(expectedKey.hashCode());
-
- String key = expectedKey.replace("[^0-9-.a-zA-Z_=]", "_");
-
- return key.substring(0, Math.min(key.length(), 20));
- }
-
- private static void ProcessConvertServiceResponceError(int errorCode) throws Exception
- {
- String errorMessage = "";
- String errorMessageTemplate = "Error occurred in the ConvertService: ";
-
- switch (errorCode)
- {
- case -8:
- errorMessage = errorMessageTemplate + "Error document VKey";
- break;
- case -7:
- errorMessage = errorMessageTemplate + "Error document request";
- break;
- case -6:
- errorMessage = errorMessageTemplate + "Error database";
- break;
- case -5:
- errorMessage = errorMessageTemplate + "Incorrect password";
- break;
- case -4:
- errorMessage = errorMessageTemplate + "Error download error";
- break;
- case -3:
- errorMessage = errorMessageTemplate + "Error convertation error";
- break;
- case -2:
- errorMessage = errorMessageTemplate + "Error convertation timeout";
- break;
- case -1:
- errorMessage = errorMessageTemplate + "Error convertation unknown";
- break;
- case 0:
- break;
- default:
- errorMessage = "ErrorCode = " + errorCode;
- break;
- }
-
- throw new Exception(errorMessage);
- }
-
- private static String GetResponseUri(String jsonString) throws Exception
- {
- JSONObject jsonObj = ConvertStringToJSON(jsonString);
-
- Object error = jsonObj.get("error");
- if (error != null)
- ProcessConvertServiceResponceError(Math.toIntExact((long)error));
-
- Boolean isEndConvert = (Boolean) jsonObj.get("endConvert");
-
- Long resultPercent = 0l;
- String responseUri = null;
-
- if (isEndConvert)
- {
- resultPercent = 100l;
- responseUri = (String) jsonObj.get("fileUrl");
- }
- else
- {
- resultPercent = (Long) jsonObj.get("percent");
- resultPercent = resultPercent >= 100l ? 99l : resultPercent;
- }
-
- return resultPercent >= 100l ? responseUri : "";
- }
-
- public static String ConvertStreamToString(InputStream stream) throws IOException
- {
- InputStreamReader inputStreamReader = new InputStreamReader(stream);
- StringBuilder stringBuilder = new StringBuilder();
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String line = bufferedReader.readLine();
-
- while (line != null)
- {
- stringBuilder.append(line);
- line = bufferedReader.readLine();
- }
-
- String result = stringBuilder.toString();
-
- return result;
- }
-
- public static JSONObject ConvertStringToJSON(String jsonString)
- {
- return JSONObject.parseObject(jsonString);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/qiwenshare/file/util/FileModel.java b/src/main/java/com/qiwenshare/file/util/FileModel.java
deleted file mode 100644
index 5f297b5..0000000
--- a/src/main/java/com/qiwenshare/file/util/FileModel.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/**
- *
- * (c) Copyright Ascensio System SIA 2021
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.qiwenshare.file.util;
-
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import com.qiwenshare.file.helper.DocumentManager;
-import com.qiwenshare.file.helper.FileUtility;
-import lombok.Data;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-
-@Data
-public class FileModel
-{
- public String type = "desktop";
- public String mode = "edit";
- public String documentType;
- public Document document;
- public EditorConfig editorConfig;
- public String token;
-
- public FileModel(String userFileId, String fileName, String fileUrl, String fileModifyTime, String uid, String uname, String callbackUrl, String mode)
- {
- if (fileName == null) fileName = "";
- fileName = fileName.trim();
-
- documentType = FileUtility.GetFileType(fileName).toString().toLowerCase();
-
- document = new Document();
- document.title = fileName;
- document.url = fileUrl;
-// document.urlUser = DocumentManager.GetFileUri(fileName, false);
- document.fileType = FileUtility.GetFileExtension(fileName).replace(".", "");
- document.key = Base64.getEncoder().encodeToString((userFileId + "_" + fileModifyTime).getBytes(StandardCharsets.UTF_8));
- document.info = new Info();
- document.info.favorite = uid != null && !uid.isEmpty() ? uid.equals("uid-2") : null;
-
- editorConfig = new EditorConfig(null);
- editorConfig.callbackUrl = callbackUrl;
-// editorConfig.lang = null;
-
- if (uid != null) editorConfig.user.id = uid;
- if (uname != null) editorConfig.user.name = uid.equals("uid-0") ? null : uname;
- if (editorConfig.user.id.equals("uid-2")) editorConfig.user.group = "group-2";
- if (editorConfig.user.id.equals("uid-3")) editorConfig.user.group = "group-3";
-
-// editorConfig.customization.goback.url = DocumentManager.GetServerUrl(false) + "/IndexServlet";
-
- changeType(mode, type);
- }
-
- public void changeType(String _mode, String _type)
- {
- if (_mode != null) mode = _mode;
- if (_type != null) type = _type;
-
- Boolean canEdit = DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(document.title));
- editorConfig.customization.submitForm = canEdit && (mode.equals("edit") || mode.equals("fillForms"));
- editorConfig.mode = canEdit && !mode.equals("view") ? "edit" : "view";
-
- document.permissions = new Permissions(mode, type, canEdit);
-
- if (type.equals("embedded")) InitDesktop();
- }
-
- public void InitDesktop()
- {
- editorConfig.InitDesktop(document.urlUser);
- }
-
-// public void BuildToken()
-// {
-// Map map = new HashMap<>();
-// map.put("type", type);
-// map.put("documentType", documentType);
-// map.put("document", document);
-// map.put("editorConfig", editorConfig);
-//
-// token = jwtComp.createJWT(map);
-// }
-
-// public String[] GetHistory()
-// {
-// String histDir = DocumentManager.HistoryDir(DocumentManager.StoragePath(document.title, null));
-// if (DocumentManager.GetFileVersion(histDir) > 0) {
-// Integer curVer = DocumentManager.GetFileVersion(histDir);
-//
-// List