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/sheet/core/client.js
"use strict";const e=require("./constants");const{default:t}=require("../../common/base/client");const i=new Set(["create_comment","reply_comment","edit_comment","reopen_comment","resolve_comment"]);const s=new Map;class n extends t{constructor(e,t,i){super(e,t,i);this.selection=null;this._init(i);t.on("init",(e=>this._onInit(e)));t.on("peek",(e=>this._onPeek(e)));if(this.isWritable()||this.isCommentable()){t.on("set",((e,t)=>this._onSet(e,t)))}if(this.isWritable()){t.on("peer",(e=>this._onPeer(e)));t.on("query_cell_history",((...e)=>this._onQueryCellHistory(...e)));t.on("save",((e,t)=>this._onSave(e,t)))}}_init(e){if(!this.isAnonymous()&&e.gids){s.set(this.uid,e.gids)}}_onInit(e){const t=this.instance.getQueue();e(t.identifier,t.rev,t.getCommands())}_onPeek(e){const t=this.instance.getQueue();e(t.identifier,t.rev,this.perm.writable)}_onSet(t,s){const n=i.has(t.cmd);if(!this.perm.writable&&!n){return}const o=this.instance.getQueue();const c=o.rev;const a=t.rev;if(!a||a!==c+1){s(a,c,2);return}if(!this.instance.validateCommand(this,t)){s(a,c,0);return}const[r,h]=this.instance.execCommand(t);if(!r){s(a,c,0);return}s(a,t.rev,1,h);t.uid=this.uid;t.client_id=this.id;this.instance.writeCommand(t);this.broadcast("set",t);if(n){this._processComment(t)}if(o.size()>=e.SNAPSHOT_THRESHOLD){this.instance.snapshot().catch((()=>{}))}else{this.instance.scheduleSave()}this.updateMtime()}_onPeer(e){e.client_id=this.id;switch(e.cmd){case"select":case"update":this.selection={row:e.row,col:e.col,img:e.img,id:e.id};break;case"deselect":this.selection=null;break}this.broadcast("peer",e)}_onSave(e,t){const i=e?e.mode:"save";const s=i==="publish"?this.instance.publishTemplate():this.instance.saveManually(i);s.catch((()=>({success:false}))).then((function(e){if(t){t(e)}}))}async _onQueryCellHistory(e,t,i,s,n){const o=await this.instance.queryCellHistory(e,t,i,s);n(o)}_processComment(e){let t;switch(e.cmd){case"create_comment":t=e.json.id;break;case"reply_comment":t=e.json.target;break;case"edit_comment":t=e.json.threadId;break}if(!t){return}const i=this.uid;this.notifyComment({type:e.cmd.split("_")[0],author:i,original_author:e.json.original_author?e.json.original_author:[i],message:e.json.text,comment_id:t})}onSayHello(e){this.getPeerInfo().then((t=>{e();this.broadcastPeerInfo("peer",Object.assign({cmd:"online"},t))})).catch((()=>{}))}sayBye(){this.broadcast("peer",{cmd:"offline",client_id:this.id})}canOrganize(){return this.perm.organizable}getGids(){return s.get(this.uid)||[]}}module.exports=n;