@qqbrowser/qbot-claw-launcher 0.10.24 → 0.10.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authMiddleware.js +1 -1
- package/dist/build.js +1 -1
- package/dist/history-viewer.js +1 -1
- package/dist/server.js +2 -2
- package/package.json +1 -1
package/dist/authMiddleware.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
|
1
|
+
"use strict";var a=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.verifyClientId=n,exports.authenticateRequest=d;const s=a(require("crypto")),i=require("./service"),u=require("./reportLog"),o="5896D98D15D95899003A3FB6CD7FFC33A4DEC4A5";function f(e){const t=e.headers.authorization;if(typeof t=="string"){const r=t.match(/^Bearer\s+(.+)$/i);if(r&&r[1])return r[1].trim()}}function c(e){const t=f(e);if(!t)return!1;const r=(0,i.getOrCreateGatewayToken)();return r?t===r:!1}function n(e){const t=e.headers["x-client-id"];return(0,u.log)(`verifyClientId: ${t}`),t?s.default.createHash("sha1").update(t).digest("hex").toUpperCase()===o:!1}function d(e){return n(e)?c(e)?{ok:!0,statusCode:200,message:""}:{ok:!1,statusCode:401,message:"gateway token \u7F3A\u5931\u6216\u4E0D\u5339\u914D"}:{ok:!1,statusCode:403,message:"\u8BF7\u6C42\u6765\u6E90\u4E0D\u5728\u5141\u8BB8\u5217\u8868\u4E2D"}}
|
package/dist/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.10.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.10.26",exports.IS_DEBUG_BUILD=!1;
|
package/dist/history-viewer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var c=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getChatHistory=
|
|
1
|
+
"use strict";var c=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getChatHistory=u;const o=c(require("fs")),f=c(require("fs/promises")),d=c(require("readline")),y=require("./config");async function m(e){if(!o.default.existsSync(e))return console.error(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${e}`),null;try{const n=await f.default.readFile(e,"utf-8");return JSON.parse(n)}catch(n){return console.error(`\u8BFB\u53D6\u6216\u89E3\u6790\u6587\u4EF6\u5931\u8D25: ${e}`,n.message),null}}async function g(e,n){return new Promise(s=>{const r=o.default.createReadStream(e,{encoding:"utf-8"}),t=d.default.createInterface({input:r,crlfDelay:1/0});let i=0;t.on("line",a=>{i++,i===n&&(t.close(),r.destroy(),s(a))}),t.on("close",()=>{i<n&&s(null)}),t.on("error",()=>{s(null)}),r.on("error",()=>{t.close(),s(null)})})}function p(e){return e.startsWith("A new session was started via")}function S(e){if(e.type==="message"&&e.message&&e.message.role==="user"){const n=e.message.content;if(Array.isArray(n)){const s=n.find(r=>r.type==="text");if(s&&s.text){const r=s.text,t=r.match(/\[.*?\]\s*(.*)/s);return t&&t[1]?t[1].trim():r}}}return null}async function _(e){if(!o.default.existsSync(e))return"(sessionFile\u4E0D\u5B58\u5728)";try{for(let r=5;r<25;r++){const t=await g(e,r);if(!t)break;try{const i=JSON.parse(t),a=S(i);if(a!==null){if(p(a))continue;return a}}catch{continue}}return"(\u672A\u627E\u5230\u6709\u6548\u7528\u6237\u6D88\u606F)"}catch{return"(\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25)"}}function h(e){return JSON.stringify(e,null,2)}async function u(){const e=[],n=await m(y.SESSIONS_FILE);if(n){const s=Object.entries(n).filter(([t])=>!t.includes("openclaw-weixin")),r=await Promise.all(s.filter(([,t])=>!!t.sessionFile).map(async([t,i])=>{const a=i.updatedAt||i.timestamp,l=await _(i.sessionFile);return{sessionKey:t,updatedAt:a,firstUserMessage:l}}));e.push(...r),e.sort((t,i)=>(i.updatedAt||0)-(t.updatedAt||0))}return e}require.main===module&&u().then(e=>{console.log(h(e))});
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}catch{}};try{s("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const o=(0,_.readState)();if(o.gatewayPid)try{process.kill(o.gatewayPid,"SIGTERM"),(0,i.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`),s("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`)}catch{(0,i.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${o.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),s("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${o.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else s("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");s("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${g.NPM_PACKAGE_NAME}...`);try{await new Promise((c,l)=>{const e=(0,I.spawn)(g.NPM_BIN,["--userconfig",g.NPM_RC,"uninstall","-g",g.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${g.NODE_BIN_DIR}${$.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});e.stdout?.on("data",u=>{(0,i.log)(`[uninstall] npm: ${u.toString().trim()}`)}),e.stderr?.on("data",u=>{(0,i.log)(`[uninstall] npm stderr: ${u.toString().trim()}`)}),e.on("close",u=>{u===0?c():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${u}`))}),e.on("error",u=>l(u))}),(0,i.log)(`[uninstall] npm uninstall -g ${g.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${g.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(c){(0,i.log)(`[uninstall] npm uninstall \u5931\u8D25: ${c.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${c.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${g.QBOT_CLAW_DIR}...`);const f=[];if(y.default.existsSync(g.QBOT_CLAW_DIR)){const c=y.default.readdirSync(g.QBOT_CLAW_DIR);for(const l of c){const e=$.default.join(g.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){s("\u6210\u529F",e,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{y.default.statSync(e).isDirectory()?y.default.rmSync(e,{recursive:!0,force:!0}):y.default.unlinkSync(e),s("\u6210\u529F",e,"\u5DF2\u5220\u9664")}catch(u){(0,i.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${e} - ${u.message}`),s("\u5931\u8D25",e,`\u5220\u9664\u5931\u8D25: ${u.message}`),f.push(e)}}if(f.length>0){s("\u6210\u529F","",`${f.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of f)try{process.platform==="win32"?(0,I.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,I.execSync)(`rm -rf "${l}"`),(0,i.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u6210\u529F: ${l}`),s("\u6210\u529F",l,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(e){(0,i.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${l} - ${e.message}`),s("\u5931\u8D25",l,`\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${e.message}`)}}if(r)s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{y.default.rmSync(g.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(l){(0,i.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`);try{process.platform==="win32"?(0,I.execSync)(`rmdir /s /q "${g.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,I.execSync)(`rm -rf "${g.QBOT_CLAW_DIR}"`),s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(e){s("\u5931\u8D25",g.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${e.message}`)}}}else s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");s("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(o){(0,i.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`),s("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`)}t.end(),setTimeout(()=>{(0,i.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(p==="/api/file-picker"&&d.method==="POST"){if((0,J.isFilePickerBusy)()){(0,n.sendJSON)(t,409,{ok:!1,code:w.DIALOG_BUSY,files:[],message:"\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u5BF9\u8BDD\u6846\u5173\u95ED\u540E\u91CD\u8BD5"});return}let a="";d.on("data",r=>{a+=r.toString()}),d.on("end",async()=>{let r=[],s=!1,o=V,f=F,c=b,l=B;if(a){let e;try{e=JSON.parse(a)}catch{(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(e.extensions!==void 0){if(!Array.isArray(e.extensions)||!e.extensions.every(u=>typeof u=="string")){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}r=e.extensions}if(e.multiple!==void 0){if(typeof e.multiple!="boolean"){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}s=e.multiple}if(e.title!==void 0){if(typeof e.title!="string"||e.title.length>200){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}o=e.title}if(e.maxFileSize!==void 0){if(typeof e.maxFileSize!="number"||e.maxFileSize<=0||!Number.isFinite(e.maxFileSize)){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}f=Math.min(e.maxFileSize,F)}if(e.maxFileCount!==void 0){if(typeof e.maxFileCount!="number"||e.maxFileCount<=0||!Number.isInteger(e.maxFileCount)){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}c=Math.min(e.maxFileCount,b)}if(B&&e.allowDirectory!==void 0){if(typeof e.allowDirectory!="boolean"){(0,n.sendJSON)(t,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}l=e.allowDirectory}}s||(c=1);try{const e=await(0,J.showFilePicker)({multiple:s,allowDirectory:l});if(!e||e.length===0){(0,n.sendJSON)(t,200,{ok:!1,code:w.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const A=e.slice(0,c).map(D=>({name:$.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=e.length>c;(0,n.sendJSON)(t,200,{ok:!0,files:A,message:h?`\u5DF2\u9009\u62E9 ${A.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${e.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${A.length} \u4E2A\u76EE\u5F55`});return}let u=!1,m=e;e.length>c&&(m=e.slice(0,c),u=!0);const O=[],S=[];for(const A of m){const h=(0,x.readFileInfo)(A,f);h.ok?O.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):S.push({path:h.path,reason:h.reason,code:h.code})}const N=[];if(O.length>0&&N.push(`\u6210\u529F\u8BFB\u53D6 ${O.length} \u4E2A\u6587\u4EF6`),S.length>0){const A=S.map(h=>`${$.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");N.push(`${S.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${A}\uFF09`)}u&&N.push(`\u5171\u9009\u62E9 ${e.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD`);const P=O.length===0&&S.length>0;(0,n.sendJSON)(t,200,{ok:!P,code:P?S[0].code:void 0,files:O,failedFiles:S.length>0?S:void 0,message:N.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(e){(0,i.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`);let u=w.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?u=w.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(u=w.PLATFORM_NOT_SUPPORTED),(0,n.sendJSON)(t,500,{ok:!1,code:u,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`})}});return}if(p.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${p}`);const r=new URL(p,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!r){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let s;try{s=Buffer.from(r,"base64").toString("utf-8")}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!s||s.trim()===""){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const o=(0,x.validateFilePath)(s);if(!o.valid){const m=o.reason;m.includes("\u975E\u6CD5\u5B57\u7B26")?(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):((0,i.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${s}\uFF0C\u539F\u56E0: ${m}`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:m}));return}const f=$.default.resolve(s),c=process.platform;let l,e,u={stdio:"ignore",windowsHide:!0};c==="darwin"?(l="open",e=["-R",f]):c==="win32"?(l="explorer.exe",e=[`/select,"${f}"`],u={...u,shell:!0}):(l="xdg-open",e=[$.default.dirname(f)]),(0,i.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${e.join(" ")}`);try{await new Promise((m,O)=>{const S=(0,I.spawn)(l,e,u),N=setTimeout(()=>{S.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);S.on("close",P=>{clearTimeout(N),c==="win32"||P===0||P===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${P}`))}),S.on("error",P=>{clearTimeout(N),O(P)})}),(0,i.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`),(0,n.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`})}catch(m){(0,i.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`),(0,n.sendJSON)(t,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})}});let E=null,C=null;function M(d){if(!d)return;if(E&&C===d){(0,i.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}E?((0,i.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${C}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${d}`),clearInterval(E),E=null,C=null):(0,i.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}`);const t=setInterval(()=>{try{process.kill(d,0)}catch{(0,i.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${d} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(t),E=null,C=null,(0,_.stopGateway)(),(0,_.clearState)(),(0,i.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,i.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,i.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);t.unref(),E=t,C=d}
|
|
1
|
+
"use strict";var R=exports&&exports.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=x;const F=R(require("http")),S=R(require("fs")),N=R(require("path")),d=require("./config"),n=require("./utils"),B=require("./history-viewer"),o=require("./reportLog"),C=require("./installer"),M=require("./build"),y=require("./state"),$=require("child_process"),W=require("./service"),L=require("./filePicker"),k=require("./fileSecurityCheck"),b=require("./authMiddleware"),U=require("./qbotclaw-routes"),v=10485760,D=10,J=!1,w={CANCELLED:"CANCELLED",INVALID_PARAMS:"INVALID_PARAMS",DIALOG_BUSY:"DIALOG_BUSY",DIALOG_TIMEOUT:"DIALOG_TIMEOUT",PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"},q=require("./openai-proxy"),Q=require("./api/auth-client");let G=new Q.AuthClient({usePipe:!0});exports.server=F.default.createServer(async(m,s)=>{const p=m.url||"";if(p.startsWith("/v1/")){await(0,q.handleOpenAIProxy)(m,s,G);return}const E=(0,b.authenticateRequest)(m);if(!E.ok){(0,n.sendJSON)(s,E.statusCode,{ok:!1,status:"\u5931\u8D25",message:E.message});return}if(p==="/api/version"){let a="unknown";try{a=(await(0,n.execCommand)(`"${d.NODE_BIN}" -v`)).trim(),(0,o.log)(`[version] node \u7248\u672C: ${a}`)}catch(i){(0,o.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${i.message}`),a=`error: ${i.message}`}const r=await(0,n.getQBotClawVersion)()??"0.0.0";(0,o.log)(`[version] qbotclaw \u7248\u672C: ${r}`);let t="0.0.0";if(S.default.existsSync(d.PYTHON_BIN))try{t=(await(0,n.execCommand)(`"${d.PYTHON_BIN}" --version`)).trim(),(0,o.log)(`[version] python \u7248\u672C: ${t}`)}catch(i){(0,o.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${i.message}`),t=`error: ${i.message}`}(0,n.sendJSON)(s,200,{status:"\u6210\u529F",launcher:M.LAUNCHER_VERSION,node:a,qbotclaw:r,python:t});return}if(p==="/api/port"){const a=exports.server.address(),r=a&&typeof a=="object"?a.port:null,t=(0,y.readState)();(0,n.sendJSON)(s,200,{status:"\u6210\u529F",launcher:r,qbotclaw:t.gatewayPort??2e3,mcpWs:t.mcpWsPort??8765}),(0,o.log)(`[port] launcher: ${r}, qbotclaw: ${t.gatewayPort}, mcpWs: ${t.mcpWsPort}`);return}if(p==="/api/status"){const a=(0,y.readState)(),r=[];if(a.gatewayPid)try{process.kill(a.gatewayPid,0)}catch{r.push(`gateway \u8FDB\u7A0B (pid: ${a.gatewayPid}) \u5DF2\u9000\u51FA`)}else r.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const t=[{name:"gateway",port:a.gatewayPort},{name:"mcpWs",port:a.mcpWsPort}];for(const{name:i,port:u}of t){if(!u){r.push(`${i} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,y.isPortAvailable)(u)&&r.push(`${i} \u7AEF\u53E3 (${u}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,n.sendJSON)(s,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,n.sendJSON)(s,200,{ok:!1,message:r.join("\uFF1B")});return}if(p==="/api/restart"){try{const a=(0,y.readState)();if(a.gatewayPid)try{process.kill(a.gatewayPid,"SIGTERM"),(0,o.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${a.gatewayPid}`)}catch{(0,o.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${a.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:r,gatewayPort:t,mcpWsPort:i,...u}=a;(0,y.writeState)(u),(0,o.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,C.configAndRunQBotClaw)(),(0,o.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const e=(0,y.readState)(),l=exports.server.address(),c=l&&typeof l=="object"?l.port:null;(0,n.sendJSON)(s,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:c,qbotclaw:e.gatewayPort??2e3,mcpWs:e.mcpWsPort??8765,gatewayToken:(0,W.getOrCreateGatewayToken)()})}catch(a){(0,o.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${a.message}`})}return}if(p==="/api/wechat/history"){try{if(!S.default.existsSync(d.SESSIONS_FILE)){(0,n.sendJSON)(s,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(d.SESSIONS_FILE,"utf-8"));let r=null,t=0;for(const[e,l]of Object.entries(a))if(e.includes("openclaw-weixin")){const f=l.updatedAt??0;f>t&&(t=f,r=e)}if(!r){(0,n.sendJSON)(s,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const u=r.split(":").slice(2).join(":");(0,n.sendJSON)(s,200,{ok:!0,sessionKey:u,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,o.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(p==="/api/chat/latest"){try{if(!S.default.existsSync(d.SESSIONS_FILE)){(0,n.sendJSON)(s,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(d.SESSIONS_FILE,"utf-8"));let r=null,t=0;for(const[u,e]of Object.entries(a)){if(u.includes("openclaw-weixin"))continue;const c=e.updatedAt??0;c>t&&(t=c,r=u)}if(!r){(0,n.sendJSON)(s,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const i=a[r];(0,n.sendJSON)(s,200,{ok:!0,sessionId:i.sessionId??"",sessionKey:r,updatedAt:t,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,o.log)(`[chat/latest] \u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(p==="/api/chat/history"){(0,B.getChatHistory)().then(a=>{(0,n.sendJSON)(s,200,{ok:!0,data:a,message:"\u83B7\u53D6\u6210\u529F"})}).catch(a=>{(0,o.log)(`[chat/history] \u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,data:[],message:`\u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`})});return}if(p==="/api/installing"){(0,n.sendJSON)(s,200,{installing:C.isInstalling});return}if(p==="/api/install"||p.startsWith("/api/install?")){const a=new URL(p,"http://localhost"),r=a.searchParams.get("version")||void 0,t=a.searchParams.get("overrideConfig")==="true";if(!r){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 version\uFF0C\u7528\u6CD5: GET /api/install?version=x.x.x"});return}if(!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(r)){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:`version \u53C2\u6570\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF08${r}\uFF09\uFF0C\u5FC5\u987B\u4E3A\u4E09\u6BB5\u5F0F\u7248\u672C\u53F7\uFF0C\u4F8B\u5982 1.2.3`});return}s.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,C.runInstall)(s,r,t);return}if(p.startsWith("/api/watch")){const r=new URL(p,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const t=parseInt(r,10);try{process.kill(t,0)}catch{(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${t} \u4E0D\u5B58\u5728`});return}const i=(0,y.readState)();(0,y.writeState)({...i,ppid:t}),x(t),(0,n.sendJSON)(s,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${t}`});return}if(!(p.startsWith("/api/qbotclaw/")&&await(0,U.handleQBotClawRoutes)(m,s,p))){if(p.startsWith("/api/uninstall")){const r=new URL(p,"http://localhost").searchParams.get("keepWorkspace")==="true";s.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const t=(i,u,e)=>{if(s.writable)try{s.write(JSON.stringify({status:i,file:u,msg:e})+`
|
|
2
|
+
`)}catch{}};try{t("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const i=(0,y.readState)();if(i.gatewayPid)try{process.kill(i.gatewayPid,"SIGTERM"),(0,o.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`),t("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`)}catch{(0,o.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),t("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else t("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");t("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${d.NPM_PACKAGE_NAME}...`);try{await new Promise((e,l)=>{const c=(0,$.spawn)(d.NPM_BIN,["--userconfig",d.NPM_RC,"uninstall","-g",d.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${d.NODE_BIN_DIR}${N.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});c.stdout?.on("data",f=>{(0,o.log)(`[uninstall] npm: ${f.toString().trim()}`)}),c.stderr?.on("data",f=>{(0,o.log)(`[uninstall] npm stderr: ${f.toString().trim()}`)}),c.on("close",f=>{f===0?e():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${f}`))}),c.on("error",f=>l(f))}),(0,o.log)(`[uninstall] npm uninstall -g ${d.NPM_PACKAGE_NAME} \u6210\u529F`),t("\u6210\u529F","",`npm uninstall -g ${d.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(e){(0,o.log)(`[uninstall] npm uninstall \u5931\u8D25: ${e.message}`),t("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${e.message}`)}t("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${d.QBOT_CLAW_DIR}...`);const u=[];if(S.default.existsSync(d.QBOT_CLAW_DIR)){const e=S.default.readdirSync(d.QBOT_CLAW_DIR);for(const l of e){const c=N.default.join(d.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){t("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{S.default.statSync(c).isDirectory()?S.default.rmSync(c,{recursive:!0,force:!0}):S.default.unlinkSync(c),t("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(f){(0,o.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${f.message}`),t("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${f.message}`),u.push(c)}}if(u.length>0){t("\u6210\u529F","",`${u.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of u)try{process.platform==="win32"?(0,$.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${l}"`),(0,o.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u6210\u529F: ${l}`),t("\u6210\u529F",l,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(c){(0,o.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${l} - ${c.message}`),t("\u5931\u8D25",l,`\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${c.message}`)}}if(r)t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{S.default.rmSync(d.QBOT_CLAW_DIR,{recursive:!0,force:!0}),t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(l){(0,o.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`);try{process.platform==="win32"?(0,$.execSync)(`rmdir /s /q "${d.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${d.QBOT_CLAW_DIR}"`),t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){t("\u5931\u8D25",d.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`)}}}else t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");t("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(i){(0,o.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`),t("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`)}s.end(),setTimeout(()=>{(0,o.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(p==="/api/file-picker"&&m.method==="POST"){if((0,L.isFilePickerBusy)()){(0,n.sendJSON)(s,409,{ok:!1,code:w.DIALOG_BUSY,files:[],message:"\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u5BF9\u8BDD\u6846\u5173\u95ED\u540E\u91CD\u8BD5"});return}let a="";m.on("data",r=>{a+=r.toString()}),m.on("end",async()=>{let r=!1,t=v,i=D,u=J;if(a){let e;try{e=JSON.parse(a)}catch{(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(e.extensions!==void 0&&(!Array.isArray(e.extensions)||!e.extensions.every(l=>typeof l=="string"))){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}if(e.multiple!==void 0){if(typeof e.multiple!="boolean"){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}r=e.multiple}if(e.title!==void 0&&(typeof e.title!="string"||e.title.length>200)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}if(e.maxFileSize!==void 0){if(typeof e.maxFileSize!="number"||e.maxFileSize<=0||!Number.isFinite(e.maxFileSize)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}t=Math.min(e.maxFileSize,v)}if(e.maxFileCount!==void 0){if(typeof e.maxFileCount!="number"||e.maxFileCount<=0||!Number.isInteger(e.maxFileCount)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}i=Math.min(e.maxFileCount,D)}if(J&&e.allowDirectory!==void 0){if(typeof e.allowDirectory!="boolean"){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}u=e.allowDirectory}}r||(i=1);try{const e=await(0,L.showFilePicker)({multiple:r,allowDirectory:u});if(!e||e.length===0){(0,n.sendJSON)(s,200,{ok:!1,code:w.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(u){const _=e.slice(0,i).map(T=>({name:N.default.basename(T),path:T,size:0,mimeType:"inode/directory"})),h=e.length>i;(0,n.sendJSON)(s,200,{ok:!0,files:_,message:h?`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${e.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55`});return}let l=!1,c=e;e.length>i&&(c=e.slice(0,i),l=!0);const f=[],g=[];for(const _ of c){const h=(0,k.readFileInfo)(_,t);h.ok?f.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):g.push({path:h.path,reason:h.reason,code:h.code})}const O=[];if(f.length>0&&O.push(`\u6210\u529F\u8BFB\u53D6 ${f.length} \u4E2A\u6587\u4EF6`),g.length>0){const _=g.map(h=>`${N.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");O.push(`${g.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${_}\uFF09`)}l&&O.push(`\u5171\u9009\u62E9 ${e.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD`);const P=f.length===0&&g.length>0;(0,n.sendJSON)(s,200,{ok:!P,code:P?g[0].code:void 0,files:f,failedFiles:g.length>0?g:void 0,message:O.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(e){(0,o.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`);let l=w.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?l=w.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(l=w.PLATFORM_NOT_SUPPORTED),(0,n.sendJSON)(s,500,{ok:!1,code:l,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`})}});return}if(p.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${p}`);const r=new URL(p,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!r){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let t;try{t=Buffer.from(r,"base64").toString("utf-8")}catch{(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!t||t.trim()===""){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const i=(0,k.validateFilePath)(t);if(!i.valid){const g=i.reason;g.includes("\u975E\u6CD5\u5B57\u7B26")?(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:g}):g.includes("\u4E0D\u5B58\u5728")?(0,n.sendJSON)(s,404,{status:"\u5931\u8D25",message:g}):g.includes("\u65E0\u6CD5\u89E3\u6790")?(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:g}):((0,o.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${t}\uFF0C\u539F\u56E0: ${g}`),(0,n.sendJSON)(s,403,{status:"\u5931\u8D25",message:g}));return}const u=N.default.resolve(t),e=process.platform;let l,c,f={stdio:"ignore",windowsHide:!0};e==="darwin"?(l="open",c=["-R",u]):e==="win32"?(l="explorer.exe",c=[`/select,"${u}"`],f={...f,shell:!0}):(l="xdg-open",c=[N.default.dirname(u)]),(0,o.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${c.join(" ")}`);try{await new Promise((g,O)=>{const P=(0,$.spawn)(l,c,f),_=setTimeout(()=>{P.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);P.on("close",h=>{clearTimeout(_),e==="win32"||h===0||h===1?g():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${h}`))}),P.on("error",h=>{clearTimeout(_),O(h)})}),(0,o.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${u}`),(0,n.sendJSON)(s,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${u}`})}catch(g){(0,o.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${g.message}`),(0,n.sendJSON)(s,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${g.message}`})}return}(0,n.sendJSON)(s,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})}});let A=null,I=null;function x(m){if(!m)return;if(A&&I===m){(0,o.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${m}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}A?((0,o.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${I}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${m}`),clearInterval(A),A=null,I=null):(0,o.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${m}`);const s=setInterval(()=>{try{process.kill(m,0)}catch{(0,o.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${m} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(s),A=null,I=null,(0,y.stopGateway)(),(0,y.clearState)(),(0,o.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,o.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,o.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);s.unref(),A=s,I=m}
|