天天看點

ONLYOFFICE曆史版本開發技術之二

 1.它隻支援word的曆史版本,PowerPoint和Excel不支援曆史版本。

Document history

If the document has been previouslyedited using Document Editor, you can view the document history.

The history iscurrently available for text document files only.

After editing in Document Editor theinformation about the changes during the editing session is sent together withthe changed document:

history -this information allows to display the time and the author for each documentversion when you view the document history in the side panel. Must be sent as aproperty changes of the object sent as the argument to the refreshHistory method.This method must be called after the onRequestHistory events.

2.并且曆史版本隻能看,不能再次編輯。

3.但是能看到哪裡做了修改。

4.伺服器隻保留1個月内的曆史版本。

5.能下載下傳下來,可以重新上傳進去協作。這是它存在的價值。

它的原理:

當一個協作文檔,最後一個人關閉後,協作伺服器(下文簡寫OODS——onlyoffice document server)會傳回一條json資料給cms,cms獲得這條資料後,解析為結構體,然後做2件事,一個是這條資料裡保含了最新文檔在OODS中的位址(url),cms根據這個url把文檔下載下傳下來,存到cms中,同時更新這個文檔在資料庫中的時間——這個新的時間(updatedtime)下次用來打開這個文檔的key;另外一件事是資料中包含了修改記錄檔案(changesurl)位址,和這個版本的作者user、時間created,key1等資訊,cms擷取後需要存到資料庫中,不需要下載下傳真正的曆史版本檔案,隻要這些資料比如key1,曆史版本修改記錄檔案位址(changesurl)。

當下次打開這個檔案時候,OO隻認updatedtime生成的key,曆史版本的key1用存在資料庫中的,查曆史版本key1,OODS就調用存在它裡面的版本出來。

會思考的你可能發現了,那麼檔案其實不用存在本地(cms)嗎??有了key1不就行了麼?

//曆史版本保留1個月。比如Unix時間戳(Unix timestamp)expires=1524547423
      var onRequestHistory = function() {
        // var changes=[{
        //     "created":"2018-03-10 14:22:15",
        //     "user":{"id":"8","name":"qin8.xc"}
        // }];
        // alert(changes[0].created);
      	docEditor.refreshHistory({
        "currentVersion": 2,
        "history": [
          {
          	"changes": [{{.changes1}}], //the changes from the history object returned after saving the document
            "created": "2018-03-9 10:15:55",
            "key": "{{.Key}}",//1521951775531484800這裡影響曆史版本切換
            "serverVersion": "{{.serverVersion1}}", //the serverVersion from the history object returned after saving the document
        	  "user": {
        	    "id": "7",
        	    "name": "qin.xc"
        	  },
        	  "version": 1
        	},
        	{
      		  "changes": [{{.changes2}}],
      		  "created": "2018-03-10 14:11:35",
      		  "key": "1521951775531484800",//
      		  "user": {
      		      "id": "8",
      		      "name": "qin8.xc"
      		  },
      		  "version": 2
      		},
        	{
      		  "changes": [{{.changes2}}],
      		  "created": "2018-03-11 14:11:35",
      		  "key": "1521803509579508900",//目前版本
      		  "user": {
      		      "id": "9",
      		      "name": "qin9.xc"
      		  },
      		  "version": 3
      		},
    		]
  	});
	};

			var onRequestHistoryClose = function() {
  		  document.location.reload();
			};
			var onRequestHistoryData = function(event) {
    		var version = event.data;
    		docEditor.setHistoryData({
    			//下面這裡存變化的位置——一個文檔附件對應一個這個位址,每次更新??
      		"changesUrl": "http://192.168.99.100:9000/cache/files/1521953170330601700_4540/changes.zip/changes.zip?md5=w6DItkSwyBJkuHDl_CiZZQ==&expires=1524547423&disposition=attachment&ooname=output.zip", //the changesUrl from the JSON object returned after saving the document
      		"key": "",
      		"previous": {
      		  "key": "",//這裡不影響版本切換
      		  "url": ""//http://192.168.99.100:9000/cache/files/1521953170330601700_4540/output.docx/output.docx?md5=eSwnrSSumTeMuh59IoXhCQ==&expires=1524547423&disposition=attachment&ooname=output.docx這裡影響版本
      		},
      		"url": "",
      		"version":4 //version
    		})
	};

    	window.docEditor = new DocsAPI.DocEditor("placeholder",
      {
        "events": {
          "onRequestHistory": onRequestHistory,
          "onRequestHistoryClose": onRequestHistoryClose,
          "onRequestHistoryData": onRequestHistoryData,
        },