From 7b69ca71bed16e3d6cf497de9a499f44940a873a Mon Sep 17 00:00:00 2001 From: MAC <1162714483@qq.com> Date: Sun, 15 May 2022 16:50:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=96=87=E4=BB=B6=E7=BC=96=E8=BE=91):=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BC=96=E8=BE=91=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qiwenshare/file/component/JwtComp.java | 6 +- .../file/controller/OfficeController.java | 19 +- .../file/controller/UserController.java | 10 +- .../file/helper/DocumentManager.java | 110 +++++------ .../qiwenshare/file/helper/TrackManager.java | 81 ++++---- .../OfficeConverterService.java} | 20 +- .../com/qiwenshare/file/util/FileModel.java | 176 +++++++++--------- 7 files changed, 229 insertions(+), 193 deletions(-) rename src/main/java/com/qiwenshare/file/{helper/ServiceConverter.java => service/OfficeConverterService.java} (91%) diff --git a/src/main/java/com/qiwenshare/file/component/JwtComp.java b/src/main/java/com/qiwenshare/file/component/JwtComp.java index 11a2254..a1e3b98 100644 --- a/src/main/java/com/qiwenshare/file/component/JwtComp.java +++ b/src/main/java/com/qiwenshare/file/component/JwtComp.java @@ -1,5 +1,6 @@ package com.qiwenshare.file.component; +import com.alibaba.fastjson.JSON; import com.qiwenshare.common.util.math.CalculatorUtils; import com.qiwenshare.file.config.jwt.JwtProperties; import io.jsonwebtoken.Claims; @@ -14,6 +15,7 @@ import javax.annotation.Resource; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.util.Date; +import java.util.Map; @Component public class JwtComp { @@ -32,8 +34,8 @@ public class JwtComp { } // 创建jwt - public String createJWT(String subject) throws Exception { - + public String createJWT(Map param) { + String subject = JSON.toJSONString(param); // 生成JWT的时间 long nowTime = System.currentTimeMillis(); Date nowDate = new Date(nowTime); diff --git a/src/main/java/com/qiwenshare/file/controller/OfficeController.java b/src/main/java/com/qiwenshare/file/controller/OfficeController.java index c9af9da..6a6d58c 100644 --- a/src/main/java/com/qiwenshare/file/controller/OfficeController.java +++ b/src/main/java/com/qiwenshare/file/controller/OfficeController.java @@ -147,16 +147,17 @@ public class OfficeController { UserFile userFile = userFileService.getById(previewOfficeFileDTO.getUserFileId()); String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath(); - - FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), + String query = "?type=show&token="+token; + String callbackUrl = baseUrl + "/office/IndexServlet" + query; + FileModel file = new FileModel(userFile.getUserFileId(), + userFile.getFileName() + "." + userFile.getExtendName(), previewOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), + callbackUrl, "view"); - String query = "?type=show&token="+token; - file.editorConfig.callbackUrl= baseUrl + "/office/IndexServlet" + query; JSONObject jsonObject = new JSONObject(); jsonObject.put("file",file); jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api")); @@ -185,17 +186,17 @@ public class OfficeController { String baseUrl = request.getScheme()+"://"+ deploymentHost + ":" + port + request.getContextPath(); log.info("回调地址baseUrl:" + baseUrl); + String query = "?type=edit&userFileId="+userFile.getUserFileId()+"&token="+token; + String callbackUrl = baseUrl + "/office/IndexServlet" + query; - FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), + FileModel file = new FileModel(userFile.getUserFileId(), + userFile.getFileName() + "." + userFile.getExtendName(), editOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), + callbackUrl, "edit"); - file.changeType(request.getParameter("mode"), "edit"); - - String query = "?type=edit&userFileId="+userFile.getUserFileId()+"&token="+token; - file.editorConfig.callbackUrl= baseUrl + "/office/IndexServlet" + query; JSONObject jsonObject = new JSONObject(); jsonObject.put("file",file); diff --git a/src/main/java/com/qiwenshare/file/controller/UserController.java b/src/main/java/com/qiwenshare/file/controller/UserController.java index 9b52fed..a5f4692 100644 --- a/src/main/java/com/qiwenshare/file/controller/UserController.java +++ b/src/main/java/com/qiwenshare/file/controller/UserController.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.shiro.crypto.hash.SimpleHash; import org.springframework.web.bind.annotation.*; @@ -68,7 +69,11 @@ public class UserController { @Parameter(description = "登录密码") String password){ RestResult restResult = new RestResult(); String salt = userService.getSaltByTelephone(telephone); - String hashPassword = new SimpleHash("MD5", password, salt, 1024).toHex(); +// String hashPassword = new SimpleHash("MD5", password, salt, 1024).toHex(); + String hashPassword = password + salt; + for (int i = 0; i < 1024; i++) { + hashPassword = DigestUtils.md5Hex(hashPassword); + } UserBean result = userService.selectUserByTelephoneAndPassword(telephone, hashPassword); if (result == null) { @@ -79,7 +84,7 @@ public class UserController { param.put("userId", result.getUserId()); String token = ""; try { - token = jwtComp.createJWT(JSON.toJSONString(param)); + token = jwtComp.createJWT(param); } catch (Exception e) { log.info("登录失败:{}", e); return RestResult.fail().message("创建token失败!"); @@ -98,7 +103,6 @@ public class UserController { } - @Operation(summary = "检查用户登录信息", description = "验证token的有效性", tags = {"user"}) @GetMapping("/checkuserlogininfo") @ResponseBody diff --git a/src/main/java/com/qiwenshare/file/helper/DocumentManager.java b/src/main/java/com/qiwenshare/file/helper/DocumentManager.java index 0ffdb9f..ab32ef4 100644 --- a/src/main/java/com/qiwenshare/file/helper/DocumentManager.java +++ b/src/main/java/com/qiwenshare/file/helper/DocumentManager.java @@ -19,15 +19,12 @@ package com.qiwenshare.file.helper; - import com.alibaba.fastjson.JSONObject; -import com.qiwenshare.file.constant.FileType; -import org.primeframework.jwt.Signer; -import org.primeframework.jwt.Verifier; -import org.primeframework.jwt.domain.JWT; -import org.primeframework.jwt.hmac.HMACSigner; -import org.primeframework.jwt.hmac.HMACVerifier; +import com.qiwenshare.file.component.JwtComp; +import com.qiwenshare.file.service.OfficeConverterService; +import org.springframework.stereotype.Component; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; @@ -38,8 +35,13 @@ import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; +@Component public class DocumentManager { + @Resource + private JwtComp jwtComp; + @Resource + private OfficeConverterService officeConverterService; private static HttpServletRequest request; public static void Init(HttpServletRequest req, HttpServletResponse resp) @@ -290,13 +292,13 @@ public class DocumentManager } } - public static ArrayList> GetFilesInfo(){ + public ArrayList> GetFilesInfo(){ ArrayList> files = new ArrayList<>(); for(File file : GetStoredFiles(null)){ Map map = new LinkedHashMap<>(); map.put("version", GetFileVersion(file.getName(), null)); - map.put("id", ServiceConverter.GenerateRevisionId(CurUserHostAddress(null) + "/" + file.getName() + "/" + Long.toString(new File(StoragePath(file.getName(), null)).lastModified()))); + map.put("id", officeConverterService.GenerateRevisionId(CurUserHostAddress(null) + "/" + file.getName() + "/" + Long.toString(new File(StoragePath(file.getName(), null)).lastModified()))); map.put("contentLength", new BigDecimal(String.valueOf((file.length()/1024.0))).setScale(2, RoundingMode.HALF_UP) + " KB"); map.put("pureContentLength", file.length()); map.put("title", file.getName()); @@ -307,7 +309,7 @@ public class DocumentManager return files; } - public static ArrayList> GetFilesInfo(String fileId){ + public ArrayList> GetFilesInfo(String fileId){ ArrayList> file = new ArrayList<>(); for (Map map : GetFilesInfo()){ @@ -356,50 +358,52 @@ public class DocumentManager } } - public static String GetInternalExtension(FileType fileType) - { - if (fileType.equals(FileType.Word)) - return ".docx"; +// public static String GetInternalExtension(FileType fileType) +// { +// if (fileType.equals(FileType.Word)) +// return ".docx"; +// +// if (fileType.equals(FileType.Cell)) +// return ".xlsx"; +// +// if (fileType.equals(FileType.Slide)) +// return ".pptx"; +// +// return ".docx"; +// } - if (fileType.equals(FileType.Cell)) - return ".xlsx"; - - if (fileType.equals(FileType.Slide)) - return ".pptx"; - - return ".docx"; - } - - public static String CreateToken(Map payloadClaims) - { - try - { - Signer signer = HMACSigner.newSHA256Signer(GetTokenSecret()); - JWT jwt = new JWT(); - for (String key : payloadClaims.keySet()) - { - jwt.addClaim(key, payloadClaims.get(key)); - } - return JWT.getEncoder().encode(jwt, signer); - } - catch (Exception e) - { - return ""; - } - } - - public static JWT ReadToken(String token) - { - try - { - Verifier verifier = HMACVerifier.newVerifier(GetTokenSecret()); - return JWT.getDecoder().decode(token, verifier); - } - catch (Exception exception) - { - return null; - } - } +// public static String CreateToken(Map payloadClaims) +// { +// jwtComp.createJWT(payloadClaims); +// +// try +// { +// Signer signer = HMACSigner.newSHA256Signer(GetTokenSecret()); +// JWT jwt = new JWT(); +// for (String key : payloadClaims.keySet()) +// { +// jwt.addClaim(key, payloadClaims.get(key)); +// } +// return JWT.getEncoder().encode(jwt, signer); +// } +// catch (Exception e) +// { +// return ""; +// } +// } +// +// public static JWT ReadToken(String token) +// { +// try +// { +// Verifier verifier = HMACVerifier.newVerifier(GetTokenSecret()); +// return JWT.getDecoder().decode(token, verifier); +// } +// catch (Exception exception) +// { +// return null; +// } +// } public static Boolean TokenEnabled() { diff --git a/src/main/java/com/qiwenshare/file/helper/TrackManager.java b/src/main/java/com/qiwenshare/file/helper/TrackManager.java index e4edf2f..35dab87 100644 --- a/src/main/java/com/qiwenshare/file/helper/TrackManager.java +++ b/src/main/java/com/qiwenshare/file/helper/TrackManager.java @@ -18,24 +18,33 @@ package com.qiwenshare.file.helper; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; -import org.primeframework.jwt.domain.JWT; +import com.qiwenshare.file.component.JwtComp; +import com.qiwenshare.file.service.OfficeConverterService; +import io.jsonwebtoken.Claims; +import org.springframework.stereotype.Component; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Scanner; +@Component public class TrackManager { + @Resource + private JwtComp jwtComp; + @Resource + private OfficeConverterService officeConverterService; private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header"); - public static JSONObject readBody(HttpServletRequest request, PrintWriter writer) throws Exception { + public JSONObject readBody(HttpServletRequest request, PrintWriter writer) throws Exception { String bodyString = ""; try { @@ -78,37 +87,45 @@ public class TrackManager { throw new Exception("{\"error\":1,\"message\":\"JWT expected\"}"); } - JWT jwt = DocumentManager.ReadToken(token); - if (jwt == null) { - writer.write("{\"error\":1,\"message\":\"JWT validation failed\"}"); - throw new Exception("{\"error\":1,\"message\":\"JWT validation failed\"}"); - } - - if (jwt.getObject("payload") != null) { - try { - @SuppressWarnings("unchecked") LinkedHashMap payload = - (LinkedHashMap)jwt.getObject("payload"); - - jwt.claims = payload; - } catch (Exception ex) { - writer.write("{\"error\":1,\"message\":\"Wrong payload\"}"); - throw ex; - } - } - + Claims claims = jwtComp.parseJWT(token); try { - Gson gson = new Gson(); - body = JSONObject.parseObject(gson.toJson(jwt.claims)); + body = JSONObject.parseObject(JSON.toJSONString(claims)); } catch (Exception ex) { writer.write("JSONParser.parse error:" + ex.getMessage()); throw ex; } + + + if (body == null) { + writer.write("{\"error\":1,\"message\":\"JWT validation failed\"}"); + throw new Exception("{\"error\":1,\"message\":\"JWT validation failed\"}"); + } + +// if (jwt.getObject("payload") != null) { +// try { +// @SuppressWarnings("unchecked") LinkedHashMap payload = +// (LinkedHashMap)jwt.getObject("payload"); +// +// jwt.claims = payload; +// } catch (Exception ex) { +// writer.write("{\"error\":1,\"message\":\"Wrong payload\"}"); +// throw ex; +// } +// } +// +// try { +// Gson gson = new Gson(); +// body = JSONObject.parseObject(gson.toJson(jwt.claims)); +// } catch (Exception ex) { +// writer.write("JSONParser.parse error:" + ex.getMessage()); +// throw ex; +// } } return body; } - public static void processSave(JSONObject body, String fileName, String userAddress) throws Exception { + public void processSave(JSONObject body, String fileName, String userAddress) throws Exception { String downloadUri = (String) body.get("url"); String changesUri = (String) body.get("changesurl"); String key = (String) body.get("key"); @@ -119,7 +136,7 @@ public class TrackManager { if (!curExt.equals(downloadExt)) { try { - String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false); + String newFileUri = officeConverterService.GetConvertedUri(downloadUri, downloadExt, curExt, officeConverterService.GenerateRevisionId(downloadUri), null, false); if (newFileUri.isEmpty()) { newFileName = DocumentManager.GetCorrectName(FileUtility.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress); } else { @@ -167,7 +184,7 @@ public class TrackManager { } } - public static void processForceSave(JSONObject body, String fileName, String userAddress) throws Exception { + public void processForceSave(JSONObject body, String fileName, String userAddress) throws Exception { String downloadUri = (String) body.get("url"); @@ -177,7 +194,7 @@ public class TrackManager { if (!curExt.equals(downloadExt)) { try { - String newFileUri = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), null, false); + String newFileUri = officeConverterService.GetConvertedUri(downloadUri, downloadExt, curExt, officeConverterService.GenerateRevisionId(downloadUri), null, false); if (newFileUri.isEmpty()) { newFileName = true; } else { @@ -249,7 +266,7 @@ public class TrackManager { connection.disconnect(); } - public static void commandRequest(String method, String key) throws Exception { + public void commandRequest(String method, String key) throws Exception { String DocumentCommandUrl = ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.command"); URL url = new URL(DocumentCommandUrl); @@ -264,11 +281,11 @@ public class TrackManager { { Map payloadMap = new HashMap(); payloadMap.put("payload", params); - headerToken = DocumentManager.CreateToken(payloadMap); + headerToken = jwtComp.createJWT(payloadMap); connection.setRequestProperty(DocumentJwtHeader.equals("") ? "Authorization" : DocumentJwtHeader, "Bearer " + headerToken); - String token = DocumentManager.CreateToken(params); + String token = jwtComp.createJWT(params); params.put("token", token); } @@ -290,10 +307,10 @@ public class TrackManager { if (stream == null) throw new Exception("Could not get an answer"); - String jsonString = ServiceConverter.ConvertStreamToString(stream); + String jsonString = officeConverterService.ConvertStreamToString(stream); connection.disconnect(); - JSONObject response = ServiceConverter.ConvertStringToJSON(jsonString); + JSONObject response = officeConverterService.ConvertStringToJSON(jsonString); if (!response.get("error").toString().equals("0")){ throw new Exception(response.toJSONString()); } diff --git a/src/main/java/com/qiwenshare/file/helper/ServiceConverter.java b/src/main/java/com/qiwenshare/file/service/OfficeConverterService.java similarity index 91% rename from src/main/java/com/qiwenshare/file/helper/ServiceConverter.java rename to src/main/java/com/qiwenshare/file/service/OfficeConverterService.java index f73c48a..cebfb50 100644 --- a/src/main/java/com/qiwenshare/file/helper/ServiceConverter.java +++ b/src/main/java/com/qiwenshare/file/service/OfficeConverterService.java @@ -16,10 +16,17 @@ * */ -package com.qiwenshare.file.helper; +package com.qiwenshare.file.service; import com.alibaba.fastjson.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; @@ -28,8 +35,11 @@ import java.util.Map; import java.util.UUID; -public class ServiceConverter +@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"); @@ -61,7 +71,7 @@ public class ServiceConverter } } - public static String GetConvertedUri(String documentUri, String fromExtension, String toExtension, String documentRevisionId, String filePass, Boolean isAsync) throws Exception + 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; @@ -95,12 +105,12 @@ public class ServiceConverter if (isAsync) map.put("async", body.async); - String token = DocumentManager.CreateToken(map); + String token = jwtComp.createJWT(map); body.token = token; Map payloadMap = new HashMap(); payloadMap.put("payload", map); - headerToken = DocumentManager.CreateToken(payloadMap); + headerToken = jwtComp.createJWT(payloadMap); } Gson gson = new Gson(); diff --git a/src/main/java/com/qiwenshare/file/util/FileModel.java b/src/main/java/com/qiwenshare/file/util/FileModel.java index 80b80d9..5f297b5 100644 --- a/src/main/java/com/qiwenshare/file/util/FileModel.java +++ b/src/main/java/com/qiwenshare/file/util/FileModel.java @@ -18,17 +18,15 @@ package com.qiwenshare.file.util; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.qiwenshare.file.helper.DocumentManager; import com.qiwenshare.file.helper.FileUtility; -import com.qiwenshare.file.helper.ServiceConverter; import lombok.Data; import java.io.File; import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; import java.util.*; @Data @@ -41,7 +39,7 @@ public class FileModel public EditorConfig editorConfig; public String token; - public FileModel(String fileName, String fileUrl, String fileModifyTime, String uid, String uname, String mode) + 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(); @@ -53,12 +51,12 @@ public class FileModel document.url = fileUrl; // document.urlUser = DocumentManager.GetFileUri(fileName, false); document.fileType = FileUtility.GetFileExtension(fileName).replace(".", ""); - document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + fileModifyTime); + 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 = DocumentManager.GetCallback(fileName); + editorConfig.callbackUrl = callbackUrl; // editorConfig.lang = null; if (uid != null) editorConfig.user.id = uid; @@ -90,90 +88,90 @@ public class FileModel 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); +// 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); +// } - token = DocumentManager.CreateToken(map); - } - - public String[] GetHistory() - { - String histDir = DocumentManager.HistoryDir(DocumentManager.StoragePath(document.title, null)); - if (DocumentManager.GetFileVersion(histDir) > 0) { - Integer curVer = DocumentManager.GetFileVersion(histDir); - - List hist = new ArrayList<>(); - Map histData = new HashMap(); - - for (Integer i = 1; i <= curVer; i++) { - Map obj = new HashMap(); - Map dataObj = new HashMap(); - String verDir = DocumentManager.VersionDir(histDir, i); - - try { - String key = null; - - key = i == curVer ? document.key : readFileToEnd(new File(verDir + File.separator + "key.txt")); - - obj.put("key", key); - obj.put("version", i); - - if (i == 1) { - String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json")); - JSONObject json = JSONObject.parseObject(createdInfo); - obj.put("created", json.get("created")); - Map user = new HashMap(); - user.put("id", json.get("id")); - user.put("name", json.get("name")); - obj.put("user", user); - } - - dataObj.put("key", key); - dataObj.put("url", i == curVer ? document.url : DocumentManager.GetPathUri(verDir + File.separator + "prev" + FileUtility.GetFileExtension(document.title))); - dataObj.put("version", i); - - if (i > 1) { - JSONObject changes = JSONObject.parseObject(readFileToEnd(new File(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "changes.json"))); - JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0); - - obj.put("changes", changes.get("changes")); - obj.put("serverVersion", changes.get("serverVersion")); - obj.put("created", change.get("created")); - obj.put("user", change.get("user")); - - Map prev = (Map) histData.get(Integer.toString(i - 2)); - Map prevInfo = new HashMap(); - prevInfo.put("key", prev.get("key")); - prevInfo.put("url", prev.get("url")); - dataObj.put("previous", prevInfo); - dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip")); - } - - if (DocumentManager.TokenEnabled()) - { - dataObj.put("token", DocumentManager.CreateToken(dataObj)); - } - - hist.add(obj); - histData.put(Integer.toString(i - 1), dataObj); - - } catch (Exception ex) { } - } - - Map histObj = new HashMap(); - histObj.put("currentVersion", curVer); - histObj.put("history", hist); - - Gson gson = new Gson(); - return new String[] { gson.toJson(histObj), gson.toJson(histData) }; - } - return new String[] { "", "" }; - } +// public String[] GetHistory() +// { +// String histDir = DocumentManager.HistoryDir(DocumentManager.StoragePath(document.title, null)); +// if (DocumentManager.GetFileVersion(histDir) > 0) { +// Integer curVer = DocumentManager.GetFileVersion(histDir); +// +// List hist = new ArrayList<>(); +// Map histData = new HashMap(); +// +// for (Integer i = 1; i <= curVer; i++) { +// Map obj = new HashMap(); +// Map dataObj = new HashMap(); +// String verDir = DocumentManager.VersionDir(histDir, i); +// +// try { +// String key = null; +// +// key = i == curVer ? document.key : readFileToEnd(new File(verDir + File.separator + "key.txt")); +// +// obj.put("key", key); +// obj.put("version", i); +// +// if (i == 1) { +// String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json")); +// JSONObject json = JSONObject.parseObject(createdInfo); +// obj.put("created", json.get("created")); +// Map user = new HashMap(); +// user.put("id", json.get("id")); +// user.put("name", json.get("name")); +// obj.put("user", user); +// } +// +// dataObj.put("key", key); +// dataObj.put("url", i == curVer ? document.url : DocumentManager.GetPathUri(verDir + File.separator + "prev" + FileUtility.GetFileExtension(document.title))); +// dataObj.put("version", i); +// +// if (i > 1) { +// JSONObject changes = JSONObject.parseObject(readFileToEnd(new File(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "changes.json"))); +// JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0); +// +// obj.put("changes", changes.get("changes")); +// obj.put("serverVersion", changes.get("serverVersion")); +// obj.put("created", change.get("created")); +// obj.put("user", change.get("user")); +// +// Map prev = (Map) histData.get(Integer.toString(i - 2)); +// Map prevInfo = new HashMap(); +// prevInfo.put("key", prev.get("key")); +// prevInfo.put("url", prev.get("url")); +// dataObj.put("previous", prevInfo); +// dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip")); +// } +// +// if (DocumentManager.TokenEnabled()) +// { +// dataObj.put("token", jwtComp.createJWT(dataObj)); +// } +// +// hist.add(obj); +// histData.put(Integer.toString(i - 1), dataObj); +// +// } catch (Exception ex) { } +// } +// +// Map histObj = new HashMap(); +// histObj.put("currentVersion", curVer); +// histObj.put("history", hist); +// +// Gson gson = new Gson(); +// return new String[] { gson.toJson(histObj), gson.toJson(histData) }; +// } +// return new String[] { "", "" }; +// } private String readFileToEnd(File file) { String output = "";