mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Merge pull request #114 from ONLYOFFICE/feature/fix-history
Feature/fix history
This commit is contained in:
@ -320,7 +320,7 @@ public class IndexServlet extends HttpServlet
|
||||
try
|
||||
{
|
||||
String histDir = DocumentManager.HistoryDir(storagePath);
|
||||
String versionDir = DocumentManager.VersionDir(histDir, DocumentManager.GetFileVersion(histDir) + 1);
|
||||
String versionDir = DocumentManager.VersionDir(histDir, DocumentManager.GetFileVersion(histDir));
|
||||
File ver = new File(versionDir);
|
||||
File toSave = new File(storagePath);
|
||||
|
||||
|
||||
@ -20,11 +20,7 @@ package entities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import helpers.DocumentManager;
|
||||
import helpers.ServiceConverter;
|
||||
@ -110,13 +106,13 @@ public class FileModel
|
||||
if (DocumentManager.GetFileVersion(histDir) > 0) {
|
||||
Integer curVer = DocumentManager.GetFileVersion(histDir);
|
||||
|
||||
Set<Object> hist = new HashSet<Object>();
|
||||
List<Object> hist = new ArrayList<>();
|
||||
Map<String, Object> histData = new HashMap<String, Object>();
|
||||
|
||||
for (Integer i = 0; i <= curVer; i++) {
|
||||
for (Integer i = 1; i <= curVer; i++) {
|
||||
Map<String, Object> obj = new HashMap<String, Object>();
|
||||
Map<String, Object> dataObj = new HashMap<String, Object>();
|
||||
String verDir = DocumentManager.VersionDir(histDir, i + 1);
|
||||
String verDir = DocumentManager.VersionDir(histDir, i);
|
||||
|
||||
try {
|
||||
String key = null;
|
||||
@ -126,7 +122,7 @@ public class FileModel
|
||||
obj.put("key", key);
|
||||
obj.put("version", i);
|
||||
|
||||
if (i == 0) {
|
||||
if (i == 1) {
|
||||
String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json"));
|
||||
JSONObject json = (JSONObject) parser.parse(createdInfo);
|
||||
|
||||
@ -141,8 +137,8 @@ public class FileModel
|
||||
dataObj.put("url", i == curVer ? document.url : DocumentManager.GetPathUri(verDir + File.separator + "prev" + FileUtility.GetFileExtension(document.title)));
|
||||
dataObj.put("version", i);
|
||||
|
||||
if (i > 0) {
|
||||
JSONObject changes = (JSONObject) parser.parse(readFileToEnd(new File(DocumentManager.VersionDir(histDir, i) + File.separator + "changes.json")));
|
||||
if (i > 1) {
|
||||
JSONObject changes = (JSONObject) parser.parse(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"));
|
||||
@ -150,12 +146,12 @@ public class FileModel
|
||||
obj.put("created", change.get("created"));
|
||||
obj.put("user", change.get("user"));
|
||||
|
||||
Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 1));
|
||||
Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2));
|
||||
Map<String, Object> prevInfo = new HashMap<String, Object>();
|
||||
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) + File.separator + "diff.zip"));
|
||||
dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip"));
|
||||
}
|
||||
|
||||
if (DocumentManager.TokenEnabled())
|
||||
@ -164,7 +160,7 @@ public class FileModel
|
||||
}
|
||||
|
||||
hist.add(obj);
|
||||
histData.put(Integer.toString(i), dataObj);
|
||||
histData.put(Integer.toString(i - 1), dataObj);
|
||||
|
||||
} catch (Exception ex) { }
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ public class DocumentManager
|
||||
}
|
||||
});
|
||||
|
||||
return dirs.length;
|
||||
return dirs.length + 1;
|
||||
}
|
||||
|
||||
public static int GetFileVersion(String fileName, String userAddress)
|
||||
|
||||
@ -137,7 +137,7 @@
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= historyData %>;
|
||||
docEditor.setHistoryData(histData[ver]);
|
||||
docEditor.setHistoryData(histData[ver - 1]);
|
||||
};
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
|
||||
Reference in New Issue
Block a user