HEX
Server: Apache/2.4.63 (Unix)
System: Linux Synopilou92 4.4.302+ #72806 SMP Mon Jul 21 23:16:00 CST 2025 x86_64
User: pilou92 (1026)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /volume1/@appstore/Spreadsheet/server/cluster/ClusterMgrCls.js
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return c}});const e=require("net");const t=require("../common/helper");const o=n(require("../common/webapi"));const r=n(require("../common/domain-socket"));const i=require("@synology-office/logger");function n(e){return e&&e.__esModule?e:{default:e}}class s{constructor(){this.socketPath="/run/synoffice/synofficeclusterd.sock";this.timeout=12e5}async lock(e){if(this.lockPromise){return this.lockPromise}return this.lockPromise=this.lockPromiseFn(e).finally((()=>{this.lockPromise=undefined}))}lockPromiseFn(e){if(this.unlockPromise){return Promise.reject(new Error(e.objectId+" is unlocking"))}const t=3;const o={...e,timeout:t};return this.doLock(o).catch((e=>{if(!o.retry||e!=="timeout"){return Promise.reject()}const t=new Promise((e=>setTimeout(e,1e3)));o.timeout=90;return Promise.any([this.doUnlockAll(o).catch((()=>{})),t]).then((()=>this.doLock(o)))}))}async doLock(e){const{objectId:o,path:r,timeout:i}=e;if(!o){throw new Error("wrong parameter")}if(!(0,t.isFile)(o)&&!(0,t.isTemplate)(o)){return}return this.sendCmd("lock",{object_id:o,path:r,timeout:i})}async unlock(e){if(this.unlockPromise){return this.unlockPromise}this.unlockPromise=this.unlockPromiseFn(e).finally((()=>{this.unlockPromise=undefined}));return this.unlockPromise}async unlockPromiseFn(e){if(this.lockPromise){await this.lockPromise.catch((()=>{}))}return await this.doUnlock(e).catch((()=>{}))}async doUnlock(e){const{objectId:o}=e;if(!o){throw new Error("wrong parameter")}if(!(0,t.isFile)(o)&&!(0,t.isTemplate)(o)){return}return this.sendCmd("unlock",{object_id:o})}async doUnlockAll(e){const{objectId:r,timeout:i}=e;if(!r){throw new Error("wrong parameter")}if(!(0,t.isFile)(r)&&!(0,t.isTemplate)(r)){return}return o.default.root.run({api:"SYNO.Office.Cluster.Locker",method:"unlockall",version:1,object_id:r,timeout:i})}async clearPaths(e){return this.sendCmd("clear_paths",{paths:e})}async sendCmd(t,o){return new Promise(((n,s)=>{const c=(0,e.connect)({path:this.socketPath},(()=>{const e=new r.default(c,{timeout:this.timeout});e.on("data",(e=>{if(e?.success){n()}else{s(e?.error)}}));e.on("error",(e=>{i.logger.error("Failed to",t,e);s()}));e.send({cmd:t,...o})}));c.on("error",(e=>{i.logger.error("Failed to",t,e);s()}))}))}}const c=s;