赞
踩
onlyoffice在多人编辑时,每个人保存都会生成一个副本缓存,再回调给服务器.但是多人保存时会报错,因为传给后台的key不变,服务器收到的文档key是同一个就会覆盖源文档
为什么要保存?
比如现有两个人在同时编辑,那第三个人想加入,就得拿到原始的的key,不能用缓存的key.
但这样就会产生一个问题,多人要用相同的key,但每个人保存key后又要求传不同的key,这样保存的文档 才会生效. 相互矛盾.
onlyoffice原文档与数据分析:
有两个参数很关键:
actions 定义当用户对文档执行操作时接收到的对象。type 字段值可以具有以下值:
0 - 用户断开与文档共同编辑的连接,
1 - 新用户连接到文档共同编辑,
2 - 用户单击 强制保存按钮。
userid 字段值是用户标识符。
status 定义文档的状态。 可以有以下值:
1 - 正在编辑文档,
2 - 文档已准备好保存,
3 - 发生文档保存错误,
4 - 文档已关闭,没有任何更改,
6 - 正在编辑文档,但保存了当前文档状态,
7 - 强制保存文档时发生错误。
"http://192.168.0.246:19688/cache/files/data/6_1695606998645.docx_4715/changes.zip/changes.zip?md5=Hd7wYycjziuM5hJd8makAQ&expires=1695623658&filename=changes.zip",
"history":{"serverVersion":"7.4.1","changes":[{"created":"2023-09-25 06:19:14","user":{"name":"admin","id":"1"}}]},
"forcesavetype":1,
"actions":[{"type":2,"userid":"1"}],
"key":"6_1695606998645.docx",
"url":"http://192.168.0.246:19688/cache/files/data/6_1695606998645.docx_4715/output.docx/output.docx?md5=1fDBdQa-_Xj7SBRRFDMfSA&expires=1695623658&filename=output.docx",
"users":["1"],
"status":6,
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI2XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6NiwidXJsIjoiaHR0cDovLzE5Mi4xNjguMC4yNDY6MTk2ODgvY2FjaGUvZmlsZXMvZGF0YS82XzE2OTU2MDY5OTg2NDUuZG9jeF80NzE1L291dHB1dC5kb2N4L291dHB1dC5kb2N4P21kNT0xZkRCZFFhLV9YajdTQlJSRkRNZlNBJmV4cGlyZXM9MTY5NTYyMzY1OCZmaWxlbmFtZT1vdXRwdXQuZG9jeCIsImNoYW5nZXN1cmwiOiJodHRwOi8vMTkyLjE2OC4wLjI0NjoxOTY4OC9jYWNoZS9maWxlcy9kYXRhLzZfMTY5NTYwNjk5ODY0NS5kb2N4XzQ3MTUvY2hhbmdlcy56aXAvY2hhbmdlcy56aXA_bWQ1PUhkN3dZeWNqeml1TTVoSmQ4bWFrQVEmZXhwaXJlcz0xNjk1NjIzNjU4JmZpbGVuYW1lPWNoYW5nZXMuemlwIiwiaGlzdG9yeSI6eyJzZXJ2ZXJWZXJzaW9uIjoiNy40LjEiLCJjaGFuZ2VzIjpbeyJjcmVhdGVkIjoiMjAyMy0wOS0yNSAwNjoxOToxNCIsInVzZXIiOnsiaWQiOiIxIiwibmFtZSI6ImFkbWluIn19XX0sInVzZXJzIjpbIjEiXSwiYWN0aW9ucyI6W3sidHlwZSI6MiwidXNlcmlkIjoiMSJ9XSwibGFzdHNhdmUiOiIyMDIzLTA5LTI1VDA2OjE5OjE0LjAwMFoiLCJmb3JjZXNhdmV0eXBlIjoxLCJmaWxldHlwZSI6ImRvY3giLCJpYXQiOjE2OTU2MjI3NTcsImV4cCI6MTY5NTYyMzA1N30.MVZ7GAAAfHuJ3Ufzc27U8KxieU-GrGTMRRBhMkf65Zk"}
Onlyoffice回调 status -> 6
2023-09-25 15:38:33,301 [http-nio-8686-exec-10] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"filetype":"docx","lastsave":"2023-09-25T07:38:25.000Z","changesurl":"http://192.168.0.246:19688/cache/files/data/7_1695606998645.docx_9649/changes.zip/changes.zip?md5=nJ7fXwDNf-Pr9LFQyaZDrQ&expires=1695628409&filename=changes.zip","history":{"serverVersion":"7.4.1","changes":[{"created":"2023-09-25 07:08:02","user":{"name":"admin","id":"1"}}]},"forcesavetype":1,"actions":[{"type":2,"userid":"1"}],
"key":"7_1695606998645.docx",
"url":"http://192.168.0.246:19688/cache/files/data/7_1695606998645.docx_9649/output.docx/output.docx?md5=lGrKTT7d13afYXdnfAuoRg&expires=1695628409&filename=output.docx",
"users":["1"],
"status":6,
Onlyoffice回调 status -> 1
2023-09-25 14:19:13,426 [http-nio-8686-exec-9] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":1,"userid":"1"}],
"key":"6_1695606998645.docx",
"users":["1"],
"status":1,
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI2XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6MSwidXNlcnMiOlsiMSJdLCJhY3Rpb25zIjpbeyJ0eXBlIjoxLCJ1c2VyaWQiOiIxIn1dLCJpYXQiOjE2OTU2MjI3NDgsImV4cCI6MTY5NTYyMzA0OH0.FCGbWWf3rlMeSPdyEQ3g8yyacZODD-3sfgFsryTHkJo"}- Onlyoffice回调 status -> 1
2023-09-25 14:43:21,074 [http-nio-8686-exec-9] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":1,"userid":"144"}],"key":"7_1695606998645.docx","users":["144"],"status":1,"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI3XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6MSwidXNlcnMiOlsiMTQ0Il0sImFjdGlvbnMiOlt7InR5cGUiOjEsInVzZXJpZCI6IjE0NCJ9XSwiaWF0IjoxNjk1NjI0MTk2LCJleHAiOjE2OTU2MjQ0OTZ9.rFLyirOSlnWcPYtP-XyUlrYcrFMDjAS4Hs7rYxbix1k"}两个人:
Onlyoffice回调 status -> 1
2023-09-25 15:00:17,471 [http-nio-8686-exec-3] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":1,"userid":"1"}],
"key":"7_1695606998645.docx",
"users":["1","144"],
"status":1,
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI3XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6MSwidXNlcnMiOlsiMSIsIjE0NCJdLCJhY3Rpb25zIjpbeyJ0eXBlIjoxLCJ1c2VyaWQiOiIxIn1dLCJpYXQiOjE2OTU2MjUyMTIsImV4cCI6MTY5NTYyNTUxMn0.HX6gWPTJwDHj8ZfEcTz8PpG0J1jTRiiYBFat8fPyMKw"}
Onlyoffice回调 status -> 1
2023-09-25 15:01:56,760 [http-nio-8686-exec-3] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":1,"userid":"144"}],
"key":"7_1695606998645.docx",
"users":["1","144"],"status":1,"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI3XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6MSwidXNlcnMiOlsiMSIsIjE0NCJdLCJhY3Rpb25zIjpbeyJ0eXBlIjoxLCJ1c2VyaWQiOiIxNDQifV0sImlhdCI6MTY5NTYyNTMxMSwiZXhwIjoxNjk1NjI1NjExfQ.F1KEkqbxbmLurWldm1lxYgdKcFQSlzUmcAvw3DE4fpU"}
关闭文档: users 不为空,说明 还有人在编辑.
Onlyoffice回调 status -> 1
2023-09-25 15:02:37,754 [http-nio-8686-exec-1] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":0,"userid":"144"}],
"key":"7_1695606998645.docx",
"users":["1"],
"status":1,"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI3XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6MSwidXNlcnMiOlsiMSJdLCJhY3Rpb25zIjpbeyJ0eXBlIjowLCJ1c2VyaWQiOiIxNDQifV0sImlhdCI6MTY5NTYyNTM1MiwiZXhwIjoxNjk1NjI1NjUyfQ.Jk0mXoVMz_te5lKiR4oWBGcOyDfUA88z6KW6ImKXScE"}
Onlyoffice回调 status -> 4 完全关闭, users为空.无人再修改
2023-09-25 15:04:02,764 [http-nio-8686-exec-10] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":0,"userid":"1"}],
"key":"7_1695606998645.docx",
"status":4,
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiI3XzE2OTU2MDY5OTg2NDUuZG9jeCIsInN0YXR1cyI6NCwiYWN0aW9ucyI6W3sidHlwZSI6MCwidXNlcmlkIjoiMSJ9XSwiaWF0IjoxNjk1NjI1NDM3LCJleHAiOjE2OTU2MjU3Mzd9.sW711oOvL5yCsQskaX7wIZ_Nl3uU3jhnCpuBBsef-RQ"}
Onlyoffice回调 status -> 4
2023-09-25 17:32:05,607 [http-nio-8686-exec-7] INFO [c.s.s.e.controller.OnlyOfficeController] OnlyOfficeController.java:69 - Onlyoffice回调 callback JSON -> {"actions":[{"type":0,"userid":"145"}],"key":"10_1695606998645.docx","status":4,"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiIxMF8xNjk1NjA2OTk4NjQ1LmRvY3giLCJzdGF0dXMiOjQsImFjdGlvbnMiOlt7InR5cGUiOjAsInVzZXJpZCI6IjE0NSJ9XSwiaWF0IjoxNjk1NjM0MzIwLCJleHAiOjE2OTU2MzQ2MjB9.WtvyRkYX2XDn0y42Z4k6Lair0Fh94WZriYxvBm47jV0"}
注意看以上日志:Onlyoffice回调 status
再对比原文档发现日志中有两个关键参数: actions 与users
actions 与users 一个是指当前操作对象,一个是当前编辑的所有用户.
分析后结合status就知道如何写代码了:
当status 2,6 则是保存
status =1 则是新用户或断开重连的状态
具体代码以后发出.
有问题留言.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。