1. 文档转换
- 将 About.odt 转成 About.docx
- (1) FileConverter/sources/converter.js 收到mq消息,调用receiveTask 处理消息
receiveTask redelivered data="{"cmd":{"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true},"toFile":"output.docx","fromOrigin":true,"visibilityTimeout":300}"
receiveTask redelivered dataRaw={"fields":{"consumerTag":"amq.ctag-bJKYusD2w3zLhyo464Owrw","deliveryTag":4,"redelivered":false,"exchange":"","routingKey":"ds.converttask"},"properties":{"headers":{},"deliveryMode":2,"priority":1},"content":{"type":"Buffer","data":[123,34,99,109,100,34,58,123,34,99,34,58,34,99,111,110,118,34,44,34,105,100,34,58,34,99,111,110,118,95,57,95,49,53,50,55,49,51,57,50,55,53,95,100,111,99,120,34,44,34,102,111,114,109,97,116,34,58,34,111,100,116,34,44,34,117,114,108,34,58,34,104,116,116,112,58,47,47,49,55,50,46,49,54,46,53,50,46,50,53,58,51,50,55,55,56,47,97,112,112,115,47,111,110,108,121,111,102,102,105,99,101,47,100,111,119,110,108,111,97,100,63,100,111,99,61,90,85,100,67,90,50,90,112,82,122,70,80,97,88,78,48,83,87,73,51,86,106,66,48,99,48,86,79,77,106,82,82,79,71,49,111,77,109,100,71,89,108,78,66,78,71,116,83,99,48,86,69,79,87,100,54,83,84,48,47,101,121,74,109,97,87,120,108,83,87,81,105,79,106,107,115,73,110,86,122,90,88,74,74,90,67,73,54,73,109,70,107,98,87,108,117,73,105,119,105,100,71,57,114,90,87,52,105,79,109,53,49,98,71,119,115,73,109,70,106,100,71,108,118,98,105,73,54,73,109,82,118,100,50,53,115,98,50,70,107,73,110,48,37,51,68,34,44,34,111,117,116,112,117,116,102,111,114,109,97,116,34,58,54,53,44,34,99,111,100,101,112,97,103,101,34,58,52,54,44,34,100,101,108,105,109,105,116,101,114,34,58,52,44,34,101,109,98,101,100,100,101,100,102,111,110,116,115,34,58,102,97,108,115,101,44,34,110,111,98,97,115,101,54,52,34,58,116,114,117,101,125,44,34,116,111,70,105,108,101,34,58,34,111,117,116,112,117,116,46,100,111,99,120,34,44,34,102,114,111,109,79,114,105,103,105,110,34,58,116,114,117,101,44,34,118,105,115,105,98,105,108,105,116,121,84,105,109,101,111,117,116,34,58,51,48,48,125]}}
- (1.1) 调用 ExecuteTask(task) 执行任务
ExecuteTask task={"cmd":{"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true},"toFile":"output.docx","fromOrigin":true,"visibilityTimeout":300}
Start Task(id=conv_9_1527139275_docx)
cmd={"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true}
- (1.1.1) 下载文件
docId=conv_9_1527139275_docx, uri=http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D, fileFrom=/tmp/ASC_CONVERT118429-17kvgd4.b1lm/source/conv_9_1527139275_docx.odt
downloadFile complete filesize=77422 (id=conv_9_1527139275_docx)
可以看到已下载的文件: /tmp/ASC_CONVERT118429-17kvgd4.b1lm/source/conv_9_1527139275_docx.odt
constants={"DOC_ID_PATTERN":"0-9-.a-zA-Z_=","CHAR_DELIMITER":"\u0005","OUTPUT_NAME":"output","ONLY_OFFICE_URL_PARAM":"ooname","DISPLAY_PREFIX":"display","RIGHTS":{"None":0,"Edit":1,"Review":2,"Comment":3,"View":4},"LICENSE_MODE":{"None":0,"Trial":1,"Developer":2},"LICENSE_RESULT":{"Error":1,"Expired":2,"Success":3,"UnknownUser":4,"Connections":5,"ExpiredTrial":6,"SuccessLimit":7,"UsersCount":8},"LICENSE_CONNECTIONS":20,"LICENSE_EXPIRE_USERS_ONE_DAY":86400,"AVS_OFFICESTUDIO_FILE_UNKNOWN":0,"AVS_OFFICESTUDIO_FILE_DOCUMENT":64,"AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX":65,"AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC":66,"AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT":67,"AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF":68,"AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT":69,"AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML":70,"AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT":71,"AVS_OFFICESTUDIO_FILE_DOCUMENT_EPUB":72,"AVS_OFFICESTUDIO_FILE_DOCUMENT_FB2":73,"AVS_OFFICESTUDIO_FILE_DOCUMENT_MOBI":74,"AVS_OFFICESTUDIO_FILE_PRESENTATION":128,"AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX":129,"AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT":130,"AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP":131,"AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX":132,"AVS_OFFICESTUDIO_FILE_SPREADSHEET":256,"AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX":257,"AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS":258,"AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS":259,"AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV":260,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM":512,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF":513,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SWF":514,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU":515,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_XPS":516,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG":517,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR":518,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR_MENU":519,"AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR_CANVAS":520,"AVS_OFFICESTUDIO_FILE_IMAGE":1024,"AVS_OFFICESTUDIO_FILE_IMAGE_JPG":1025,"AVS_OFFICESTUDIO_FILE_IMAGE_TIFF":1026,"AVS_OFFICESTUDIO_FILE_IMAGE_TGA":1027,"AVS_OFFICESTUDIO_FILE_IMAGE_GIF":1028,"AVS_OFFICESTUDIO_FILE_IMAGE_PNG":1029,"AVS_OFFICESTUDIO_FILE_IMAGE_EMF":1030,"AVS_OFFICESTUDIO_FILE_IMAGE_WMF":1031,"AVS_OFFICESTUDIO_FILE_IMAGE_BMP":1032,"AVS_OFFICESTUDIO_FILE_IMAGE_CR2":1033,"AVS_OFFICESTUDIO_FILE_IMAGE_PCX":1034,"AVS_OFFICESTUDIO_FILE_IMAGE_RAS":1035,"AVS_OFFICESTUDIO_FILE_IMAGE_PSD":1036,"AVS_OFFICESTUDIO_FILE_IMAGE_ICO":1037,"AVS_OFFICESTUDIO_FILE_OTHER":2048,"AVS_OFFICESTUDIO_FILE_OTHER_EXTRACT_IMAGE":2049,"AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO":2050,"AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP":2051,"AVS_OFFICESTUDIO_FILE_OTHER_OLD_DOCUMENT":2052,"AVS_OFFICESTUDIO_FILE_OTHER_OLD_PRESENTATION":2053,"AVS_OFFICESTUDIO_FILE_OTHER_OLD_DRAWING":2054,"AVS_OFFICESTUDIO_FILE_OTHER_TEAMLAB_INNER":2055,"AVS_OFFICESTUDIO_FILE_OTHER_JSON":2056,"AVS_OFFICESTUDIO_FILE_TEAMLAB":4096,"AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY":4097,"AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY":4098,"AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY":4099,"AVS_OFFICESTUDIO_FILE_CANVAS":8192,"AVS_OFFICESTUDIO_FILE_CANVAS_WORD":8193,"AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET":8194,"AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION":8195,"NO_ERROR":0,"UNKNOWN":-1,"READ_REQUEST_STREAM":-3,"WEB_REQUEST":-4,"TASK_QUEUE":-20,"TASK_RESULT":-40,"STORAGE":-60,"STORAGE_FILE_NO_FOUND":-61,"STORAGE_READ":-62,"STORAGE_WRITE":-63,"STORAGE_REMOVE_DIR":-64,"STORAGE_CREATE_DIR":-65,"STORAGE_GET_INFO":-66,"CONVERT":-80,"CONVERT_DOWNLOAD":-81,"CONVERT_UNKNOWN_FORMAT":-82,"CONVERT_TIMEOUT":-83,"CONVERT_READ_FILE":-84,"CONVERT_CORRUPTED":-86,"CONVERT_LIBREOFFICE":-87,"CONVERT_PARAMS":-88,"CONVERT_NEED_PARAMS":-89,"CONVERT_DRM":-90,"CONVERT_PASSWORD":-91,"CONVERT_ICU":-92,"CONVERT_LIMITS":-93,"CONVERT_DEAD_LETTER":-99,"UPLOAD":-100,"UPLOAD_CONTENT_LENGTH":-101,"UPLOAD_EXTENSION":-102,"UPLOAD_COUNT_FILES":-103,"UPLOAD_URL":-104,"VKEY":-120,"VKEY_ENCRYPT":-121,"VKEY_KEY_EXPIRE":-122,"VKEY_USER_COUNT_EXCEED":-123,"VKEY_TIME_EXPIRE":-124,"VKEY_TIME_INCORRECT":-125,"EDITOR_CHANGES":-160,"QUEUE_PRIORITY_VERY_LOW":0,"QUEUE_PRIORITY_LOW":1,"QUEUE_PRIORITY_NORMAL":2,"QUEUE_PRIORITY_HIGH":3,"QUEUE_PRIORITY_VERY_HIGH":4,"EDITOR_TYPE_WORD":0,"EDITOR_TYPE_SPREADSHEET":1,"EDITOR_TYPE_PRESENTATION":2,"EDITOR_TYPE_CONVERTATION":3,"PACKAGE_TYPE_OS":0,"PACKAGE_TYPE_I":1,"PACKAGE_TYPE_D":2,"REDIS_KEY_PUBSUB":"pubsub","REDIS_KEY_SAVE_LOCK":"savelock:","REDIS_KEY_PRESENCE_HASH":"presence:hash:","REDIS_KEY_PRESENCE_SET":"presence:set:","REDIS_KEY_PRESENCE_UNIQUE_USERS":"presence:unique:users","REDIS_KEY_LOCKS":"locks:","REDIS_KEY_CHANGES_INDEX":"changesindex:","REDIS_KEY_LOCK_DOCUMENT":"lockdocument:","REDIS_KEY_MESSAGE":"message:","REDIS_KEY_DOCUMENTS":"documents","REDIS_KEY_LAST_SAVE":"lastsave:","REDIS_KEY_FORCE_SAVE":"forcesave:","REDIS_KEY_FORCE_SAVE_TIMER":"forcesavetimer","REDIS_KEY_FORCE_SAVE_TIMER_LOCK":"forcesavetimerlock:","REDIS_KEY_SAVED":"saved:","REDIS_KEY_SHUTDOWN":"shutdown","REDIS_KEY_COLLECT_LOST":"collectlost","REDIS_KEY_LICENSE":"license","REDIS_KEY_LICENSE_T":"licenseT","SHUTDOWN_CODE":4001,"SHUTDOWN_REASON":"server shutdown","SESSION_IDLE_CODE":4002,"SESSION_IDLE_REASON":"idle session expires","SESSION_ABSOLUTE_CODE":4003,"SESSION_ABSOLUTE_REASON":"absolute session expires","ACCESS_DENIED_CODE":4004,"ACCESS_DENIED_REASON":"access deny","JWT_EXPIRED_CODE":4005,"JWT_EXPIRED_REASON":"token:","JWT_ERROR_CODE":4006,"JWT_ERROR_REASON":"token:","DROP_CODE":4007,"DROP_REASON":"drop","CONTENT_DISPOSITION_INLINE":"inline","CONTENT_DISPOSITION_ATTACHMENT":"attachment","CONN_CLOSED":3}
- (1.1.2) 使用 spawnAsync 调用c++程序转换文件
var spawnAsync = require('@expo/spawn-async');
spawnAsync(processPath, childArgs);
processPath=/var/www/onlyoffice/documentserver/server/FileConverter/bin/x2t, childArgs=["/tmp/ASC_CONVERT118429-17kvgd4.b1lm/params.xml"]
conv_9_1527139275_docx
/tmp/ASC_CONVERT118429-17kvgd4.b1lm/source/conv_9_1527139275_docx.odt
/tmp/ASC_CONVERT118429-17kvgd4.b1lm/result/output.docx
65
46
4
false
/usr/share/fonts
/var/www/onlyoffice/documentserver/sdkjs/slide/themes
2018-05-29T07:54:31.037Z
true
调用成功之后可以看到转换之后的文件: /tmp/ASC_CONVERT118429-17kvgd4.b1lm/result/output.docx
- (1.1.3) 调用 postProcess处理结果
postProcess cmd="c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true},dataConvert={"key":"conv_9_1527139275_docx","fileFrom":"/tmp/ASC_CONVERT118429-17kvgd4.b1lm/source/conv_9_1527139275_docx.odt","fileTo":"/tmp/ASC_CONVERT118429-17kvgd4.b1lm/result/output.docx","formatTo":65,"csvTxtEncoding":46,"csvDelimiter":4,"embeddedFonts":false,"fontDir":"/usr/share/fonts","themeDir":"/var/www/onlyoffice/documentserver/sdkjs/slide/themes","noBase64":true,"timestamp":"2018-05-29T07:54:31.037Z"},tempDirs={"temp":"/tmp/ASC_CONVERT118429-17kvgd4.b1lm","source":"/tmp/ASC_CONVERT118429-17kvgd4.b1lm/source","result":"/tmp/ASC_CONVERT118429-17kvgd4.b1lm/result"},childRes={"pid":6932,"output":["",""],"stdout":"","stderr":"","status":0,"signal":null},error=0,isTimeout=false
processUploadToStorage dir=/tmp/ASC_CONVERT118429-17kvgd4.b1lm/result, storagePath=conv_9_1527139275_docx
output (data={"cmd":{"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","title":"output.docx","outputformat":65,"outputpath":"output.docx","codepage":46,"delimiter":4,"embeddedfonts":false,"status_info":0,"nobase64":true}};id=conv_9_1527139275_docx)
将tmp中的文件存储到 /var/lib/onlyoffice/documentserver/App_Data/cache/files/conv_9_1527139275_docx/output.docx 中
- (1.1.4) 删除tmp临时目录
deleteFolderRecursive strPath=/tmp/ASC_CONVERT118429-17kvgd4.b1lm
(2) DocService/sources/converterservice.js 中的convertRequestXml被调用
调用 convertRequest 方法(2.1) 调用 convertByCmd方法
convertByCmd cmd={"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true}, async=false, baseUrl=http://172.16.52.49, opt_fileTo=output.docx, opt_taskExist=undefined, opt_priority=undefined, opt_expiration=undefined, opt_queue=undefined
Start convert request docId = conv_9_1527139275_docx
task={"key":"conv_9_1527139275_docx","status":2,"statusInfo":0,"lastOpenDate":null,"userIndex":null,"changeId":null,"callback":null,"baseurl":null}
向数据库中的 task_result 表中插入 task
+------------------------+--------+-------------+---------------------+------------+-----------+----------+---------+
| id | status | status_info | last_open_date | user_index | change_id | callback | baseurl |
+------------------------+--------+-------------+---------------------+------------+-----------+----------+---------+
| conv_9_1527139275_docx | 1 | 0 | 2018-05-29 07:54:31 | 1 | 0 | | |
+------------------------+--------+-------------+---------------------+------------+-----------+----------+---------+
(2.1.1) 调用 getConvertStatus 获取转换状态
(2.1.1.1) DocService/sources/canvasservice.js receiveTask收到消息
Start receiveTask: docId = conv_9_1527139275_docx {"cmd":{"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","title":"output.docx","outputformat":65,"outputpath":"output.docx","codepage":46,"delimiter":4,"embeddedfonts":false,"status_info":0,"nobase64":true}}
command=conv
do nothing
End receiveTask: docId = conv_9_1527139275_docx
- (2.1.2) 调用 getConvertStatus 获取转换状态
getConvertStatus cmd={"c":"conv","id":"conv_9_1527139275_docx","format":"odt","url":"http://172.16.52.25:32778/apps/onlyoffice/download?doc=ZUdCZ2ZpRzFPaXN0SWI3VjB0c0VOMjRROG1oMmdGYlNBNGtSc0VEOWd6ST0/eyJmaWxlSWQiOjksInVzZXJJZCI6ImFkbWluIiwidG9rZW4iOm51bGwsImFjdGlvbiI6ImRvd25sb2FkIn0%3D","outputformat":65,"codepage":46,"delimiter":4,"embeddedfonts":false,"nobase64":true}, selectRes=[{"id":"conv_9_1527139275_docx","status":1,"status_info":0,"last_open_date":"2018-05-29T08:48:37.000Z","user_index":1,"change_id":0,"callback":"","baseurl":""}], baseUrl="http://172.16.52.49", opt_fileTo="output.docx"
从数据库中查询记录
row = {"id":"conv_9_1527139275_docx","status":1,"status_info":0,"last_open_date":"2018-05-29T08:48:37.000Z","user_index":1,"change_id":0,"callback":"","baseurl":""}
var FileStatus = {
None: 0,
Ok: 1,
WaitQueue: 2,
NeedParams: 3,
Err: 5,
ErrToReload: 6,
SaveVersion: 7,
UpdateVersion: 8,
NeedPassword: 9
};
getConvertStatus status={"end":true,"url":"http://172.16.52.49/cache/files/conv_9_1527139275_docx/output.docx/output.docx?md5=xdNSdX_J9rna-u1BP3_hYg==&expires=1527584619&disposition=attachment&ooname=output.docx","err":0}
现在可以通过 url :http://172.16.52.49/cache/files/conv_9_1527139275_docx/output.docx/output.docx?md5=xdNSdX_J9rna-u1BP3_hYg==&expires=1527584619&disposition=attachment&ooname=output.docx 下载最新的文件了