@qqbrowser/qbot-claw-launcher 0.10.21 → 0.10.23
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/filePicker.js +16 -16
- package/dist/server.js +1 -1
- package/package.json +1 -1
package/dist/authMiddleware.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.verifyOrigin=n,exports.authenticateRequest=c;const i=require("./service"),a=["https://quickstart.imtt.qq.com","https://quickstarttest.imtt.qq.com","https://browser.qq.com"];function o(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 u(e){const t=o(e);if(!t)return!1;const r=(0,i.getOrCreateGatewayToken)();return r?t===r:!1}function n(e){const t=e.headers.origin;if(!t)return!1;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.verifyOrigin=n,exports.authenticateRequest=c;const i=require("./service"),a=["https://quickstart.imtt.qq.com","https://quickstarttest.imtt.qq.com","https://browser.qq.com"];function o(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 u(e){const t=o(e);if(!t)return!1;const r=(0,i.getOrCreateGatewayToken)();return r?t===r:!1}function n(e){const t=e.headers.origin;if(!t)return!1;try{const r=new URL(t).origin;return a.some(s=>{try{return new URL(s).origin===r}catch{return!1}})}catch{return!1}}function c(e){return n(e)?u(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.23",exports.IS_DEBUG_BUILD=!1;
|
package/dist/filePicker.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isFilePickerBusy=P,exports.showFilePicker=O;const d=require("child_process"),w=3e5;let h=!1;function P(){return h}async function O(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isFilePickerBusy=P,exports.showFilePicker=O;const d=require("child_process"),w=3e5;let h=!1;function P(){return h}async function O(e={}){if(h)throw new Error("\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A");h=!0;try{const o=process.platform;switch(o){case"darwin":return await S(e);case"win32":return await k(e);case"linux":return await E(e);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0: ${o}`)}}finally{h=!1}}function S(e){const{multiple:o=!1,allowDirectory:f=!1}=e,a="\u8BF7\u9009\u62E9\u6587\u4EF6";let u;f?(u=`choose folder with prompt "${$(a)}"`,o&&(u+=" with multiple selections allowed")):(u=`choose file with prompt "${$(a)}"`,o&&(u+=" with multiple selections allowed"));const n=o?`set selectedItems to (${u})
|
|
2
2
|
set posixPaths to ""
|
|
3
3
|
repeat with anItem in selectedItems
|
|
4
4
|
set posixPaths to posixPaths & POSIX path of anItem & linefeed
|
|
5
5
|
end repeat
|
|
6
|
-
return posixPaths`:`set selectedItem to (${
|
|
7
|
-
return POSIX path of selectedItem`;return new Promise((i
|
|
8
|
-
`).map(
|
|
9
|
-
${
|
|
6
|
+
return posixPaths`:`set selectedItem to (${u})
|
|
7
|
+
return POSIX path of selectedItem`;return new Promise((t,i)=>{const l=(0,d.execFile)("osascript",["-e",n],{timeout:w},(r,s,c)=>{if(r){if(r.killed){i(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(c&&c.includes("User canceled")){t(null);return}if(r.code===1){t(null);return}i(new Error(`macOS \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${c||r.message}`));return}const p=s.trim().split(`
|
|
8
|
+
`).map(m=>m.trim()).filter(Boolean);t(p.length>0?p:null)})})}function $(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function k(e){const{multiple:o=!1,allowDirectory:f=!1}=e,a=[],u="\u8BF7\u9009\u62E9\u6587\u4EF6";let n;const t="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;";if(f)n=`
|
|
9
|
+
${t}
|
|
10
10
|
Add-Type -AssemblyName System.Windows.Forms
|
|
11
11
|
$dialog = New-Object System.Windows.Forms.FolderBrowserDialog
|
|
12
|
-
$dialog.Description = '${
|
|
12
|
+
$dialog.Description = '${g(u)}'
|
|
13
13
|
$dialog.ShowNewFolderButton = $true
|
|
14
14
|
$result = $dialog.ShowDialog()
|
|
15
15
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
|
|
16
16
|
Write-Output $dialog.SelectedPath
|
|
17
17
|
} else {
|
|
18
18
|
Write-Output ''
|
|
19
|
-
}`;else{let i="\u6240\u6709\u6587\u4EF6 (*.*)|*.*";if(
|
|
20
|
-
${
|
|
19
|
+
}`;else{let i="\u6240\u6709\u6587\u4EF6 (*.*)|*.*";if(a.length>0){const l=a.map(s=>`*${s.startsWith(".")?s:"."+s}`).join(";");i=`\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B (${a.map(s=>s.startsWith(".")?s:"."+s).join(", ")})|${l}|\u6240\u6709\u6587\u4EF6 (*.*)|*.*`}n=`
|
|
20
|
+
${t}
|
|
21
21
|
Add-Type -AssemblyName System.Windows.Forms
|
|
22
22
|
$dialog = New-Object System.Windows.Forms.OpenFileDialog
|
|
23
|
-
$dialog.Title = '${
|
|
24
|
-
$dialog.Filter = '${
|
|
25
|
-
$dialog.Multiselect = $${
|
|
23
|
+
$dialog.Title = '${g(u)}'
|
|
24
|
+
$dialog.Filter = '${g(i)}'
|
|
25
|
+
$dialog.Multiselect = $${o?"true":"false"}
|
|
26
26
|
$result = $dialog.ShowDialog()
|
|
27
27
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
|
|
28
28
|
$dialog.FileNames | ForEach-Object { Write-Output $_ }
|
|
29
29
|
} else {
|
|
30
30
|
Write-Output ''
|
|
31
|
-
}`}return new Promise((i,
|
|
32
|
-
`).map(
|
|
33
|
-
`),!
|
|
34
|
-
`).map(
|
|
35
|
-
`).map(
|
|
31
|
+
}`}return new Promise((i,l)=>{(0,d.execFile)("powershell.exe",["-NoProfile","-NonInteractive","-Command",n],{timeout:w,windowsHide:!0,encoding:"utf8"},(r,s,c)=>{if(r){if(r.killed){l(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}l(new Error(`Windows \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${c||r.message}`));return}const p=s.trim();if(!p){i(null);return}const m=p.split(`
|
|
32
|
+
`).map(F=>F.trim()).filter(Boolean);i(m.length>0?m:null)})})}function g(e){return e.replace(/'/g,"''")}async function E(e){if(await y("zenity"))return W(e);if(await y("kdialog"))return D(e);throw new Error("Linux \u7CFB\u7EDF\u672A\u5B89\u88C5 zenity \u6216 kdialog\uFF0C\u65E0\u6CD5\u5F39\u51FA\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u3002\u8BF7\u5B89\u88C5\u5176\u4E2D\u4E4B\u4E00\uFF1Asudo apt install zenity \u6216 sudo apt install kdialog")}function y(e){return new Promise(o=>{(0,d.execFile)("which",[e],f=>{o(!f)})})}function W(e){const{multiple:o=!1,allowDirectory:f=!1}=e,a=[],n=["--file-selection","--title=\u8BF7\u9009\u62E9\u6587\u4EF6"];if(f&&n.push("--directory"),o&&n.push("--multiple",`--separator=
|
|
33
|
+
`),!f&&a.length>0){const t=a.map(i=>`*${i.startsWith(".")?i:"."+i}`).join(" ");n.push(`--file-filter=\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B | ${t}`),n.push("--file-filter=\u6240\u6709\u6587\u4EF6 | *")}return new Promise((t,i)=>{(0,d.execFile)("zenity",n,{timeout:w},(l,r,s)=>{if(l){if(l.killed){i(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(l.code===1){t(null);return}i(new Error(`zenity \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${s||l.message}`));return}const c=r.trim();if(!c){t(null);return}const p=c.split(`
|
|
34
|
+
`).map(m=>m.trim()).filter(Boolean);t(p.length>0?p:null)})})}function D(e){const{multiple:o=!1,allowDirectory:f=!1}=e,a=[],u="\u8BF7\u9009\u62E9\u6587\u4EF6";let n;if(f)n=["--getexistingdirectory",process.env.HOME||"/"];else{let t="";a.length>0&&(t=`${a.map(l=>`*${l.startsWith(".")?l:"."+l}`).join(" ")} | \u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B`),o?n=["--getopenfilename",process.env.HOME||"/",t,"--multiple","--separate-output"]:n=["--getopenfilename",process.env.HOME||"/",t]}return n.push("--title",u),new Promise((t,i)=>{(0,d.execFile)("kdialog",n,{timeout:w},(l,r,s)=>{if(l){if(l.killed){i(new Error("\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u8D85\u65F6\uFF0860\u79D2\uFF09"));return}if(l.code===1){t(null);return}i(new Error(`kdialog \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${s||l.message}`));return}const c=r.trim();if(!c){t(null);return}const p=c.split(`
|
|
35
|
+
`).map(m=>m.trim()).filter(Boolean);t(p.length>0?p:null)})})}
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";var L=exports&&exports.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.setGlobalAuthClient=z,exports.getGlobalAuthClient=j,exports.watchParentProcess=M;const W=L(require("http")),y=L(require("fs")),I=L(require("path")),g=require("./config"),a=require("./utils"),i=require("./reportLog"),k=require("./installer"),U=require("./build"),_=require("./state"),$=require("child_process"),G=require("./service"),J=require("./filePicker"),x=require("./fileSecurityCheck"),Q=require("./authMiddleware"),q=require("./qbotclaw-routes"),H="\u9009\u62E9\u6587\u4EF6",F=10485760,b=10,B=!1,S={CANCELLED:"CANCELLED",INVALID_PARAMS:"INVALID_PARAMS",DIALOG_BUSY:"DIALOG_BUSY",DIALOG_TIMEOUT:"DIALOG_TIMEOUT",PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"},V=require("./openai-proxy"),K=require("./api/auth-client");let v=new K.AuthClient({usePipe:!0});function z(d){v=d}function j(){return v}const T={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Max-Age":"86400"};function Y(d){for(const[t,p]of Object.entries(T))d.setHeader(t,p)}exports.server=W.default.createServer(async(d,t)=>{const p=d.url||"";if(Y(t),d.method==="OPTIONS"){t.writeHead(204,T),t.end();return}if(p.startsWith("/v1/")){await(0,V.handleOpenAIProxy)(d,t,v);return}const R=(0,Q.authenticateRequest)(d);if(!R.ok){(0,a.sendJSON)(t,R.statusCode,{ok:!1,status:"\u5931\u8D25",message:R.message});return}if(p==="/api/version"){let n="unknown";try{n=(await(0,a.execCommand)(`"${g.NODE_BIN}" -v`)).trim(),(0,i.log)(`[version] node \u7248\u672C: ${n}`)}catch(o){(0,i.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${o.message}`),n=`error: ${o.message}`}const r=await(0,a.getQBotClawVersion)()??"0.0.0";(0,i.log)(`[version] qbotclaw \u7248\u672C: ${r}`);let s="0.0.0";if(y.default.existsSync(g.PYTHON_BIN))try{s=(await(0,a.execCommand)(`"${g.PYTHON_BIN}" --version`)).trim(),(0,i.log)(`[version] python \u7248\u672C: ${s}`)}catch(o){(0,i.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${o.message}`),s=`error: ${o.message}`}(0,a.sendJSON)(t,200,{status:"\u6210\u529F",launcher:U.LAUNCHER_VERSION,node:n,qbotclaw:r,python:s});return}if(p==="/api/port"){const n=exports.server.address(),r=n&&typeof n=="object"?n.port:null,s=(0,_.readState)();(0,a.sendJSON)(t,200,{status:"\u6210\u529F",launcher:r,qbotclaw:s.gatewayPort??2e3,mcpWs:s.mcpWsPort??8765}),(0,i.log)(`[port] launcher: ${r}, qbotclaw: ${s.gatewayPort}, mcpWs: ${s.mcpWsPort}`);return}if(p==="/api/status"){const n=(0,_.readState)(),r=[];if(n.gatewayPid)try{process.kill(n.gatewayPid,0)}catch{r.push(`gateway \u8FDB\u7A0B (pid: ${n.gatewayPid}) \u5DF2\u9000\u51FA`)}else r.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const s=[{name:"gateway",port:n.gatewayPort},{name:"mcpWs",port:n.mcpWsPort}];for(const{name:o,port:f}of s){if(!f){r.push(`${o} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,_.isPortAvailable)(f)&&r.push(`${o} \u7AEF\u53E3 (${f}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,a.sendJSON)(t,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,a.sendJSON)(t,200,{ok:!1,message:r.join("\uFF1B")});return}if(p==="/api/restart"){try{const n=(0,_.readState)();if(n.gatewayPid)try{process.kill(n.gatewayPid,"SIGTERM"),(0,i.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${n.gatewayPid}`)}catch{(0,i.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${n.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:r,gatewayPort:s,mcpWsPort:o,...f}=n;(0,_.writeState)(f),(0,i.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,k.configAndRunQBotClaw)(),(0,i.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const c=(0,_.readState)(),l=exports.server.address(),e=l&&typeof l=="object"?l.port:null;(0,a.sendJSON)(t,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:e,qbotclaw:c.gatewayPort??2e3,mcpWs:c.mcpWsPort??8765,gatewayToken:(0,G.getOrCreateGatewayToken)()})}catch(n){(0,i.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${n.message}`})}return}if(p==="/api/wechat/history"){try{if(!y.default.existsSync(g.SESSIONS_FILE)){(0,a.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const n=JSON.parse(y.default.readFileSync(g.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[c,l]of Object.entries(n))if(c.includes("openclaw-weixin")){const u=l.updatedAt??0;u>s&&(s=u,r=c)}if(!r){(0,a.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const f=r.split(":").slice(2).join(":");(0,a.sendJSON)(t,200,{ok:!0,sessionKey:f,message:"\u83B7\u53D6\u6210\u529F"})}catch(n){(0,i.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`})}return}if(p==="/api/chat/latest"){try{if(!y.default.existsSync(g.SESSIONS_FILE)){(0,a.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const n=JSON.parse(y.default.readFileSync(g.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[f,c]of Object.entries(n)){if(f.includes("openclaw-weixin"))continue;const e=c.updatedAt??0;e>s&&(s=e,r=f)}if(!r){(0,a.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const o=n[r];(0,a.sendJSON)(t,200,{ok:!0,sessionId:o.sessionId??"",sessionKey:r,updatedAt:s,message:"\u83B7\u53D6\u6210\u529F"})}catch(n){(0,i.log)(`[chat/latest] \u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${n.message}`})}return}if(p==="/api/installing"){(0,a.sendJSON)(t,200,{installing:k.isInstalling});return}if(p==="/api/install"||p.startsWith("/api/install?")){const n=new URL(p,"http://localhost"),r=n.searchParams.get("version")||void 0,s=n.searchParams.get("overrideConfig")==="true";if(!r){(0,a.sendJSON)(t,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,a.sendJSON)(t,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}t.writeHead(200,{...T,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,k.runInstall)(t,r,s);return}if(p.startsWith("/api/watch")){const r=new URL(p,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const s=parseInt(r,10);try{process.kill(s,0)}catch{(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${s} \u4E0D\u5B58\u5728`});return}const o=(0,_.readState)();(0,_.writeState)({...o,ppid:s}),M(s),(0,a.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${s}`});return}if(!(p.startsWith("/api/qbotclaw/")&&await(0,q.handleQBotClawRoutes)(d,t,p))){if(p.startsWith("/api/uninstall")){const r=new URL(p,"http://localhost").searchParams.get("keepWorkspace")==="true";t.writeHead(200,{...T,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const s=(o,f,c)=>{if(t.writable)try{t.write(JSON.stringify({status:o,file:f,msg:c})+`
|
|
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,$.spawn)(g.NPM_BIN,["--userconfig",g.NPM_RC,"uninstall","-g",g.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${g.NODE_BIN_DIR}${I.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=I.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,$.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,$.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,$.execSync)(`rmdir /s /q "${g.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,$.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,a.sendJSON)(t,409,{ok:!1,code:S.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 n="";d.on("data",r=>{n+=r.toString()}),d.on("end",async()=>{let r=[],s=!1,o=H,f=F,c=b,l=B;if(n){let e;try{e=JSON.parse(n)}catch{(0,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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)({extensions:r,multiple:s,title:o,allowDirectory:l});if(!e||e.length===0){(0,a.sendJSON)(t,200,{ok:!1,code:S.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const A=e.slice(0,c).map(D=>({name:I.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=e.length>c;(0,a.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=[],w=[];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}):w.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`),w.length>0){const A=w.map(h=>`${I.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");N.push(`${w.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&&w.length>0;(0,a.sendJSON)(t,200,{ok:!P,code:P?w[0].code:void 0,files:O,failedFiles:w.length>0?w: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=S.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?u=S.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(u=S.PLATFORM_NOT_SUPPORTED),(0,a.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,a.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,a.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,a.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,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,a.sendJSON)(t,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,a.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,a.sendJSON)(t,403,{status:"\u5931\u8D25",message:m}));return}const f=I.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=[I.default.dirname(f)]),(0,i.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${e.join(" ")}`);try{await new Promise((m,O)=>{const w=(0,$.spawn)(l,e,u),N=setTimeout(()=>{w.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);w.on("close",P=>{clearTimeout(N),c==="win32"||P===0||P===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${P}`))}),w.on("error",P=>{clearTimeout(N),O(P)})}),(0,i.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`),(0,a.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,a.sendJSON)(t,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,a.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}
|
|
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,$.spawn)(g.NPM_BIN,["--userconfig",g.NPM_RC,"uninstall","-g",g.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${g.NODE_BIN_DIR}${I.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=I.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,$.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,$.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,$.execSync)(`rmdir /s /q "${g.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,$.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,a.sendJSON)(t,409,{ok:!1,code:S.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 n="";d.on("data",r=>{n+=r.toString()}),d.on("end",async()=>{let r=[],s=!1,o=H,f=F,c=b,l=B;if(n){let e;try{e=JSON.parse(n)}catch{(0,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,400,{ok:!1,code:S.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,a.sendJSON)(t,200,{ok:!1,code:S.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const A=e.slice(0,c).map(D=>({name:I.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=e.length>c;(0,a.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=[],w=[];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}):w.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`),w.length>0){const A=w.map(h=>`${I.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");N.push(`${w.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&&w.length>0;(0,a.sendJSON)(t,200,{ok:!P,code:P?w[0].code:void 0,files:O,failedFiles:w.length>0?w: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=S.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?u=S.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(u=S.PLATFORM_NOT_SUPPORTED),(0,a.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,a.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,a.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,a.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,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,a.sendJSON)(t,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,a.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,a.sendJSON)(t,403,{status:"\u5931\u8D25",message:m}));return}const f=I.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=[I.default.dirname(f)]),(0,i.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${e.join(" ")}`);try{await new Promise((m,O)=>{const w=(0,$.spawn)(l,e,u),N=setTimeout(()=>{w.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);w.on("close",P=>{clearTimeout(N),c==="win32"||P===0||P===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${P}`))}),w.on("error",P=>{clearTimeout(N),O(P)})}),(0,i.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`),(0,a.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,a.sendJSON)(t,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,a.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}
|