File: /volume1/@appstore/Spreadsheet/server/sheet/worker_task/take_snapshot.js
"use strict";const e=require("../sheet-fs");const{decrypt:t}=require("../../common/syno-crypto");const{generateSnapshot:r,cleanup:s,writeSnapshot:n}=require("./snapshot");const{readFile:c,writeFile:o}=require("fs/promises");async function a(e,r){try{const s=await c(e,"utf8");return s.split("\n").filter((e=>e)).map((e=>{let s;try{if(r){e=t(e,r)}s=JSON.parse(e)}catch{}return s})).filter((e=>e))}catch(e){return Promise.reject(e)}}async function i(t){const i={success:true,error:null};function u(e){return o(`${t}/_response.json`,JSON.stringify(e),"utf8")}try{const s=await c(`${t}/_request.json`,"utf8");const o=JSON.parse(s);const{object_id:f,queue_file:l,password:p}=o;const d=e.getData(f,p);const{password:y}=d;const m=await a(l,y);if(!Array.isArray(m)){i.error="commands are not valid";return u(i)}if(m.length===0){return u(i)}const w={};["gcVer","ver"].forEach((e=>{w[e]=d.index[e]}));const[h,g]=await r(d,m,w,f);Object.assign(i,{editors:Array.from(new Set(m.map((e=>e.uid)))),files:Object.keys(h),deletedFiles:g});await n(t,h,y)}catch(e){i.success=false;i.error=e.stack||e}s();return u(i)}module.exports=i;