asaihost-nodejs 0.0.6 → 0.0.8
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/asaihost-nodejs.cjs +370 -343
- package/dist/asaihost-nodejs.cjs.map +1 -1
- package/dist/asaihost-nodejs.es.js +175 -148
- package/dist/asaihost-nodejs.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -399,7 +399,7 @@ var LogBuffer = class _LogBuffer {
|
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
401
|
function saveLog($asai, src, logstr) {
|
|
402
|
-
return new Promise((
|
|
402
|
+
return new Promise((resolve6, reject) => {
|
|
403
403
|
try {
|
|
404
404
|
const bufferKey = `${$asai.id || "default"}_${src}`;
|
|
405
405
|
let logBuffer = logBuffers.get(bufferKey);
|
|
@@ -408,7 +408,7 @@ function saveLog($asai, src, logstr) {
|
|
|
408
408
|
logBuffers.set(bufferKey, logBuffer);
|
|
409
409
|
}
|
|
410
410
|
logBuffer.add(logstr);
|
|
411
|
-
|
|
411
|
+
resolve6();
|
|
412
412
|
} catch (err) {
|
|
413
413
|
console.error(err);
|
|
414
414
|
reject(err);
|
|
@@ -1460,11 +1460,11 @@ function createSkipChecker($asai) {
|
|
|
1460
1460
|
}
|
|
1461
1461
|
if (exact.size === 0 && prefixes.length === 0) return () => false;
|
|
1462
1462
|
return (url) => {
|
|
1463
|
-
const
|
|
1464
|
-
if (!
|
|
1465
|
-
if (exact.has(
|
|
1463
|
+
const path8 = normalizeRequestPath(url);
|
|
1464
|
+
if (!path8) return false;
|
|
1465
|
+
if (exact.has(path8)) return true;
|
|
1466
1466
|
for (let i = 0; i < prefixes.length; i++) {
|
|
1467
|
-
if (
|
|
1467
|
+
if (path8.startsWith(prefixes[i])) return true;
|
|
1468
1468
|
}
|
|
1469
1469
|
return false;
|
|
1470
1470
|
};
|
|
@@ -2382,11 +2382,11 @@ function getSecurityConfig($asai) {
|
|
|
2382
2382
|
return $asai?.hostconfig?.security || {};
|
|
2383
2383
|
}
|
|
2384
2384
|
__name(getSecurityConfig, "getSecurityConfig");
|
|
2385
|
-
function pathMatchesPattern(
|
|
2385
|
+
function pathMatchesPattern(path8, pattern) {
|
|
2386
2386
|
if (pattern.endsWith("*")) {
|
|
2387
|
-
return
|
|
2387
|
+
return path8.startsWith(pattern.slice(0, -1));
|
|
2388
2388
|
}
|
|
2389
|
-
return
|
|
2389
|
+
return path8 === pattern;
|
|
2390
2390
|
}
|
|
2391
2391
|
__name(pathMatchesPattern, "pathMatchesPattern");
|
|
2392
2392
|
function isAuthSkipped($asai, pathname) {
|
|
@@ -2535,7 +2535,7 @@ __name(isApiCorsAllowed, "isApiCorsAllowed");
|
|
|
2535
2535
|
|
|
2536
2536
|
// src/common/server/Api.ts
|
|
2537
2537
|
function readRequestBody(req, maxBody) {
|
|
2538
|
-
return new Promise((
|
|
2538
|
+
return new Promise((resolve6, reject) => {
|
|
2539
2539
|
const chunks = [];
|
|
2540
2540
|
let received = 0;
|
|
2541
2541
|
let settled = false;
|
|
@@ -2543,7 +2543,7 @@ function readRequestBody(req, maxBody) {
|
|
|
2543
2543
|
if (settled) return;
|
|
2544
2544
|
settled = true;
|
|
2545
2545
|
if (err) reject(err);
|
|
2546
|
-
else
|
|
2546
|
+
else resolve6(data ?? "");
|
|
2547
2547
|
}, "finish");
|
|
2548
2548
|
req.on("data", (chunk) => {
|
|
2549
2549
|
if (settled) return;
|
|
@@ -2673,83 +2673,95 @@ var Api_default = /* @__PURE__ */ __name(($asai, opt = {}) => {
|
|
|
2673
2673
|
const isTextPost = req.method === "POST" && req.url.indexOf("binary") === -1;
|
|
2674
2674
|
const bodyPromise = isTextPost ? readRequestBody(req, maxBody) : null;
|
|
2675
2675
|
void (async () => {
|
|
2676
|
-
let authResult;
|
|
2677
|
-
let rawBody = "";
|
|
2678
2676
|
try {
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
if (!authResult.ok) {
|
|
2691
|
-
releaseSlot();
|
|
2692
|
-
return sendAuthError(res, authResult);
|
|
2693
|
-
}
|
|
2694
|
-
let apiFn = $asai.hostserverapi[apiHandlerKey]?.($asai, query);
|
|
2695
|
-
if (!apiFn) {
|
|
2696
|
-
return sendError(res, 501, "Not Implemented");
|
|
2697
|
-
}
|
|
2698
|
-
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
2699
|
-
$asai.$log("API", req.method, urlParse.pathname, query);
|
|
2700
|
-
let qrdata;
|
|
2701
|
-
let postdata;
|
|
2702
|
-
if (req.url.indexOf("binary") === -1) {
|
|
2703
|
-
qrdata = query;
|
|
2704
|
-
if (req.method === "POST") {
|
|
2705
|
-
try {
|
|
2706
|
-
const processed = processPostPayload($asai, req, rawBody, pm);
|
|
2707
|
-
postdata = processed.postdata;
|
|
2708
|
-
pm = processed.pm;
|
|
2709
|
-
isAes = processed.isAes;
|
|
2710
|
-
} catch {
|
|
2711
|
-
return sendError(res, 400, "AES decrypt failed");
|
|
2712
|
-
}
|
|
2713
|
-
if (apiFn?.post && typeof apiFn?.post === "function") {
|
|
2714
|
-
const optTmp = { qrdata, data: postdata, pm };
|
|
2715
|
-
if (isAes || $asai.$lib.aesfns?.allaes) {
|
|
2716
|
-
optTmp.resAES = $asai.$lib.aesfns?.resAES;
|
|
2717
|
-
}
|
|
2718
|
-
apiFn.post(req, res, hostdir, optTmp);
|
|
2719
|
-
} else {
|
|
2720
|
-
res.end(typeof postdata === "string" ? postdata : JSON.stringify(postdata ?? ""));
|
|
2721
|
-
}
|
|
2722
|
-
} else if (req.method === "GET") {
|
|
2723
|
-
if (apiFn?.get && typeof apiFn?.get === "function") {
|
|
2724
|
-
const optTmp = { qrdata, data: qrdata, pm };
|
|
2725
|
-
if (isAes || $asai.$lib.aesfns?.allaes) {
|
|
2726
|
-
optTmp.resAES = $asai.$lib.aesfns?.resAES;
|
|
2727
|
-
}
|
|
2728
|
-
apiFn.get(req, res, hostdir, optTmp);
|
|
2729
|
-
} else {
|
|
2730
|
-
res.end(JSON.stringify(qrdata));
|
|
2677
|
+
let authResult;
|
|
2678
|
+
let rawBody = "";
|
|
2679
|
+
try {
|
|
2680
|
+
[authResult, rawBody] = await Promise.all([
|
|
2681
|
+
validateHttpAuthAsync(req, $asai, pathname),
|
|
2682
|
+
bodyPromise ?? Promise.resolve("")
|
|
2683
|
+
]);
|
|
2684
|
+
} catch (err) {
|
|
2685
|
+
releaseSlot();
|
|
2686
|
+
if (err?.message === "PAYLOAD_TOO_LARGE") {
|
|
2687
|
+
return sendError(res, 413, "Payload Too Large");
|
|
2731
2688
|
}
|
|
2689
|
+
return sendError(res, 400, err?.message || "Bad Request");
|
|
2732
2690
|
}
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2691
|
+
if (!authResult.ok) {
|
|
2692
|
+
releaseSlot();
|
|
2693
|
+
return sendAuthError(res, authResult);
|
|
2736
2694
|
}
|
|
2737
|
-
|
|
2738
|
-
|
|
2695
|
+
let apiFn = $asai.hostserverapi[apiHandlerKey]?.($asai, query);
|
|
2696
|
+
if (!apiFn) {
|
|
2697
|
+
return sendError(res, 501, "Not Implemented");
|
|
2698
|
+
}
|
|
2699
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
2700
|
+
$asai.$log("API", req.method, urlParse.pathname, query);
|
|
2701
|
+
let qrdata;
|
|
2702
|
+
let postdata;
|
|
2703
|
+
if (req.url.indexOf("binary") === -1) {
|
|
2704
|
+
qrdata = query;
|
|
2705
|
+
if (req.method === "POST") {
|
|
2706
|
+
try {
|
|
2707
|
+
const processed = processPostPayload($asai, req, rawBody, pm);
|
|
2708
|
+
postdata = processed.postdata;
|
|
2709
|
+
pm = processed.pm;
|
|
2710
|
+
isAes = processed.isAes;
|
|
2711
|
+
} catch {
|
|
2712
|
+
return sendError(res, 400, "AES decrypt failed");
|
|
2713
|
+
}
|
|
2739
2714
|
if (apiFn?.post && typeof apiFn?.post === "function") {
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
}
|
|
2715
|
+
const optTmp = { qrdata, data: postdata, pm };
|
|
2716
|
+
if (isAes || $asai.$lib.aesfns?.allaes) {
|
|
2717
|
+
optTmp.resAES = $asai.$lib.aesfns?.resAES;
|
|
2718
|
+
}
|
|
2719
|
+
apiFn.post(req, res, hostdir, optTmp);
|
|
2744
2720
|
} else {
|
|
2745
|
-
res.end(
|
|
2721
|
+
res.end(typeof postdata === "string" ? postdata : JSON.stringify(postdata ?? ""));
|
|
2746
2722
|
}
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2723
|
+
} else if (req.method === "GET") {
|
|
2724
|
+
if (apiFn?.get && typeof apiFn?.get === "function") {
|
|
2725
|
+
const optTmp = { qrdata, data: qrdata, pm };
|
|
2726
|
+
if (isAes || $asai.$lib.aesfns?.allaes) {
|
|
2727
|
+
optTmp.resAES = $asai.$lib.aesfns?.resAES;
|
|
2728
|
+
}
|
|
2729
|
+
apiFn.get(req, res, hostdir, optTmp);
|
|
2730
|
+
} else {
|
|
2731
|
+
res.end(JSON.stringify(qrdata));
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
} else {
|
|
2735
|
+
if (Object.keys(query)?.length) {
|
|
2736
|
+
qrdata = query;
|
|
2737
|
+
}
|
|
2738
|
+
if (req.method === "POST") {
|
|
2739
|
+
$asai.$lib.AsNodeTool.upBinary(req).then((postdata2) => {
|
|
2740
|
+
if (apiFn?.post && typeof apiFn?.post === "function") {
|
|
2741
|
+
apiFn.post(req, res, hostdir, {
|
|
2742
|
+
qrdata,
|
|
2743
|
+
data: postdata2
|
|
2744
|
+
});
|
|
2745
|
+
} else {
|
|
2746
|
+
res.end(postdata2);
|
|
2747
|
+
}
|
|
2748
|
+
}).catch((err) => {
|
|
2749
|
+
return sendError(res, 400, "Invalid content type");
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
} catch (err) {
|
|
2754
|
+
releaseSlot();
|
|
2755
|
+
if (!res.headersSent) {
|
|
2756
|
+
return sendError(res, 500, err?.message || "Internal Server Error");
|
|
2750
2757
|
}
|
|
2751
2758
|
}
|
|
2752
|
-
})()
|
|
2759
|
+
})().catch((err) => {
|
|
2760
|
+
releaseSlot();
|
|
2761
|
+
if (!res.headersSent) {
|
|
2762
|
+
sendError(res, 500, err?.message || "Internal Server Error");
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2753
2765
|
} else {
|
|
2754
2766
|
$asai.$log("API", req.method, req.url);
|
|
2755
2767
|
}
|
|
@@ -2883,27 +2895,28 @@ var Sys_default = /* @__PURE__ */ __name(($asai, opt = {}) => {
|
|
|
2883
2895
|
}
|
|
2884
2896
|
const urlPath = (req.url || "").split("?")[0];
|
|
2885
2897
|
void (async () => {
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
handler
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
+
try {
|
|
2899
|
+
const authResult = await validateHttpAuthAsync(req, $asai, urlPath);
|
|
2900
|
+
if (!authResult.ok) {
|
|
2901
|
+
return sendAuthError(res, authResult);
|
|
2902
|
+
}
|
|
2903
|
+
const handler = $asai.hostserversys[handlerKey]?.($asai);
|
|
2904
|
+
if (!handler) {
|
|
2905
|
+
return sendError(res, 500, "Handler Initialization Failed");
|
|
2906
|
+
}
|
|
2907
|
+
if (handler?.show && typeof handler?.show === "function") {
|
|
2908
|
+
handler.show(req, res, hostdir);
|
|
2909
|
+
} else {
|
|
2910
|
+
res.end("postdata");
|
|
2911
|
+
}
|
|
2912
|
+
} catch (err) {
|
|
2913
|
+
return sendError(res, 500, err?.message || "Internal Server Error");
|
|
2898
2914
|
}
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
});
|
|
2903
|
-
res.end(req.url);
|
|
2904
|
-
} else {
|
|
2915
|
+
})().catch((err) => {
|
|
2916
|
+
if (!res.headersSent) {
|
|
2917
|
+
sendError(res, 500, err?.message || "Internal Server Error");
|
|
2905
2918
|
}
|
|
2906
|
-
})
|
|
2919
|
+
});
|
|
2907
2920
|
}
|
|
2908
2921
|
__name(sysWork, "sysWork");
|
|
2909
2922
|
return { sysWork };
|
|
@@ -2922,7 +2935,7 @@ var WsClient_default = /* @__PURE__ */ __name(($asai, wsname) => {
|
|
|
2922
2935
|
}
|
|
2923
2936
|
__name(getKeyByData, "getKeyByData");
|
|
2924
2937
|
function clientwsInit() {
|
|
2925
|
-
return new Promise((
|
|
2938
|
+
return new Promise((resolve6, reject) => {
|
|
2926
2939
|
$asai.clientws[wsname].socket = new $asai.asaiWs(
|
|
2927
2940
|
$asai.command.commandconfig.clientws[wsname]
|
|
2928
2941
|
);
|
|
@@ -2952,7 +2965,7 @@ var WsClient_default = /* @__PURE__ */ __name(($asai, wsname) => {
|
|
|
2952
2965
|
`${wsname}=${$asai.command.commandconfig.clientws[wsname]} is open.`
|
|
2953
2966
|
);
|
|
2954
2967
|
$asai.clientws[wsname].open = 1;
|
|
2955
|
-
|
|
2968
|
+
resolve6();
|
|
2956
2969
|
};
|
|
2957
2970
|
});
|
|
2958
2971
|
}
|
|
@@ -2982,7 +2995,7 @@ var WsClient_default = /* @__PURE__ */ __name(($asai, wsname) => {
|
|
|
2982
2995
|
}
|
|
2983
2996
|
__name(clientwsOnmessage, "clientwsOnmessage");
|
|
2984
2997
|
function clientwsApi(messageData) {
|
|
2985
|
-
return new Promise((
|
|
2998
|
+
return new Promise((resolve6, reject) => {
|
|
2986
2999
|
if ($asai.clientws[wsname].open) {
|
|
2987
3000
|
try {
|
|
2988
3001
|
const taskOpt = {};
|
|
@@ -2994,7 +3007,7 @@ var WsClient_default = /* @__PURE__ */ __name(($asai, wsname) => {
|
|
|
2994
3007
|
getKeyByData(messageData),
|
|
2995
3008
|
{
|
|
2996
3009
|
callback: /* @__PURE__ */ __name((res) => {
|
|
2997
|
-
|
|
3010
|
+
resolve6(res);
|
|
2998
3011
|
}, "callback"),
|
|
2999
3012
|
...messageData,
|
|
3000
3013
|
...taskOpt
|
|
@@ -4543,10 +4556,10 @@ var As_default = {
|
|
|
4543
4556
|
return absPath;
|
|
4544
4557
|
},
|
|
4545
4558
|
makeDir(fs11, filePaths) {
|
|
4546
|
-
return new Promise((
|
|
4559
|
+
return new Promise((resolve6, reject) => {
|
|
4547
4560
|
try {
|
|
4548
4561
|
const newPath = this.ensureDir(fs11, filePaths);
|
|
4549
|
-
|
|
4562
|
+
resolve6(newPath);
|
|
4550
4563
|
} catch (err) {
|
|
4551
4564
|
reject(err);
|
|
4552
4565
|
}
|
|
@@ -5142,6 +5155,7 @@ var AsDb_default = /* @__PURE__ */ __name(($asai, cfg) => {
|
|
|
5142
5155
|
}, "default");
|
|
5143
5156
|
|
|
5144
5157
|
// src/sysserver/lib/common/reqWork.ts
|
|
5158
|
+
import * as path4 from "path";
|
|
5145
5159
|
var reqWork_default = /* @__PURE__ */ __name(($asai) => {
|
|
5146
5160
|
function hostDefault2(mod) {
|
|
5147
5161
|
if (mod && typeof mod === "object" && "default" in mod) {
|
|
@@ -5157,6 +5171,19 @@ var reqWork_default = /* @__PURE__ */ __name(($asai) => {
|
|
|
5157
5171
|
throw new Error("Missing path");
|
|
5158
5172
|
}
|
|
5159
5173
|
const decoded = decodeURIComponent(String(rawPath));
|
|
5174
|
+
if (path4.isAbsolute(decoded)) {
|
|
5175
|
+
return path4.normalize(decoded);
|
|
5176
|
+
}
|
|
5177
|
+
const rel = decoded.replace(/^\.(\/)?/, "");
|
|
5178
|
+
const serverRoot = $asai?.serverRoot;
|
|
5179
|
+
if (serverRoot && rel) {
|
|
5180
|
+
const absRoot = path4.resolve(serverRoot);
|
|
5181
|
+
const abs = path4.resolve(absRoot, rel);
|
|
5182
|
+
const relCheck = path4.relative(absRoot, abs);
|
|
5183
|
+
if (relCheck === "" || !relCheck.startsWith("..") && !path4.isAbsolute(relCheck)) {
|
|
5184
|
+
return abs;
|
|
5185
|
+
}
|
|
5186
|
+
}
|
|
5160
5187
|
const roots = $asai?.asaihost?.getHostAllowedRoots?.($asai?.hostconfig) || [];
|
|
5161
5188
|
if (!roots.length) {
|
|
5162
5189
|
const fallback = $asai?.serverRoot || process.cwd();
|
|
@@ -5214,17 +5241,17 @@ __export(AsFs_exports, {
|
|
|
5214
5241
|
writeJson: () => writeJson
|
|
5215
5242
|
});
|
|
5216
5243
|
import fs9 from "fs/promises";
|
|
5217
|
-
import
|
|
5244
|
+
import path5 from "path";
|
|
5218
5245
|
async function ensureFile(filePath) {
|
|
5219
|
-
const normalized =
|
|
5220
|
-
await fs9.mkdir(
|
|
5246
|
+
const normalized = path5.normalize(filePath);
|
|
5247
|
+
await fs9.mkdir(path5.dirname(normalized), { recursive: true });
|
|
5221
5248
|
const fh = await fs9.open(normalized, "a");
|
|
5222
5249
|
await fh.close();
|
|
5223
5250
|
}
|
|
5224
5251
|
__name(ensureFile, "ensureFile");
|
|
5225
5252
|
async function pathExists(filePath) {
|
|
5226
5253
|
try {
|
|
5227
|
-
await fs9.access(
|
|
5254
|
+
await fs9.access(path5.normalize(filePath));
|
|
5228
5255
|
return true;
|
|
5229
5256
|
} catch {
|
|
5230
5257
|
return false;
|
|
@@ -5232,7 +5259,7 @@ async function pathExists(filePath) {
|
|
|
5232
5259
|
}
|
|
5233
5260
|
__name(pathExists, "pathExists");
|
|
5234
5261
|
async function readJson(filePath) {
|
|
5235
|
-
const raw = await fs9.readFile(
|
|
5262
|
+
const raw = await fs9.readFile(path5.normalize(filePath), "utf8");
|
|
5236
5263
|
return JSON.parse(raw);
|
|
5237
5264
|
}
|
|
5238
5265
|
__name(readJson, "readJson");
|
|
@@ -5243,26 +5270,26 @@ function resolvePathUnderBase(baseDir, relPath) {
|
|
|
5243
5270
|
if (relPath.includes("\0")) {
|
|
5244
5271
|
throw new Error("Invalid path");
|
|
5245
5272
|
}
|
|
5246
|
-
const base =
|
|
5247
|
-
const target =
|
|
5248
|
-
const rel =
|
|
5249
|
-
if (rel.startsWith("..") ||
|
|
5273
|
+
const base = path5.resolve(baseDir);
|
|
5274
|
+
const target = path5.resolve(base, relPath.replace(/\\/g, "/"));
|
|
5275
|
+
const rel = path5.relative(base, target);
|
|
5276
|
+
if (rel.startsWith("..") || path5.isAbsolute(rel)) {
|
|
5250
5277
|
throw new Error("Path not allowed");
|
|
5251
5278
|
}
|
|
5252
5279
|
return target;
|
|
5253
5280
|
}
|
|
5254
5281
|
__name(resolvePathUnderBase, "resolvePathUnderBase");
|
|
5255
5282
|
async function readLogDir(dir) {
|
|
5256
|
-
const resolved =
|
|
5283
|
+
const resolved = path5.resolve(dir);
|
|
5257
5284
|
const stats = await fs9.stat(resolved);
|
|
5258
5285
|
if (!stats.isDirectory()) {
|
|
5259
5286
|
throw new Error("Not a directory");
|
|
5260
5287
|
}
|
|
5261
|
-
const dirName =
|
|
5288
|
+
const dirName = path5.basename(resolved);
|
|
5262
5289
|
const entries = await fs9.readdir(resolved, { withFileTypes: true });
|
|
5263
5290
|
const children = await Promise.all(
|
|
5264
5291
|
entries.map(async (entry) => {
|
|
5265
|
-
const fullPath =
|
|
5292
|
+
const fullPath = path5.join(resolved, entry.name);
|
|
5266
5293
|
const st = await fs9.stat(fullPath);
|
|
5267
5294
|
const dot = entry.name.lastIndexOf(".");
|
|
5268
5295
|
const type = entry.isDirectory() ? "dir" : dot > -1 ? entry.name.substring(dot) : "file";
|
|
@@ -5270,7 +5297,7 @@ async function readLogDir(dir) {
|
|
|
5270
5297
|
name: entry.name,
|
|
5271
5298
|
size: st.size,
|
|
5272
5299
|
time: st.mtime.toISOString(),
|
|
5273
|
-
path:
|
|
5300
|
+
path: path5.normalize(fullPath),
|
|
5274
5301
|
type,
|
|
5275
5302
|
created: st.birthtime.toISOString(),
|
|
5276
5303
|
permissions: st.mode.toString(8).slice(-3)
|
|
@@ -5281,7 +5308,7 @@ async function readLogDir(dir) {
|
|
|
5281
5308
|
name: dirName,
|
|
5282
5309
|
size: stats.size,
|
|
5283
5310
|
time: stats.mtime.toISOString(),
|
|
5284
|
-
path:
|
|
5311
|
+
path: path5.normalize(resolved),
|
|
5285
5312
|
type: "dir",
|
|
5286
5313
|
created: stats.birthtime.toISOString(),
|
|
5287
5314
|
permissions: stats.mode.toString(8).slice(-3),
|
|
@@ -5291,7 +5318,7 @@ async function readLogDir(dir) {
|
|
|
5291
5318
|
__name(readLogDir, "readLogDir");
|
|
5292
5319
|
async function removeFile(filePath) {
|
|
5293
5320
|
try {
|
|
5294
|
-
await fs9.unlink(
|
|
5321
|
+
await fs9.unlink(path5.normalize(filePath));
|
|
5295
5322
|
} catch (err) {
|
|
5296
5323
|
if (err?.code !== "ENOENT") throw err;
|
|
5297
5324
|
}
|
|
@@ -5299,13 +5326,13 @@ async function removeFile(filePath) {
|
|
|
5299
5326
|
__name(removeFile, "removeFile");
|
|
5300
5327
|
var remove = removeFile;
|
|
5301
5328
|
async function write(filePath, content) {
|
|
5302
|
-
const normalized =
|
|
5303
|
-
await fs9.mkdir(
|
|
5329
|
+
const normalized = path5.normalize(filePath);
|
|
5330
|
+
await fs9.mkdir(path5.dirname(normalized), { recursive: true });
|
|
5304
5331
|
await fs9.writeFile(normalized, content, "utf8");
|
|
5305
5332
|
}
|
|
5306
5333
|
__name(write, "write");
|
|
5307
5334
|
async function read(filePath) {
|
|
5308
|
-
return fs9.readFile(
|
|
5335
|
+
return fs9.readFile(path5.normalize(filePath), "utf8");
|
|
5309
5336
|
}
|
|
5310
5337
|
__name(read, "read");
|
|
5311
5338
|
async function writeJson(filePath, data) {
|
|
@@ -5341,19 +5368,19 @@ __export(common_exports, {
|
|
|
5341
5368
|
toSetObject: () => toSetObject,
|
|
5342
5369
|
toWherePairs: () => toWherePairs
|
|
5343
5370
|
});
|
|
5344
|
-
import * as
|
|
5371
|
+
import * as path6 from "path";
|
|
5345
5372
|
function promisifySqlDb(query, sql) {
|
|
5346
|
-
return new Promise((
|
|
5373
|
+
return new Promise((resolve6, reject) => {
|
|
5347
5374
|
query(sql, (err, result) => {
|
|
5348
5375
|
if (err) {
|
|
5349
5376
|
reject(err);
|
|
5350
5377
|
return;
|
|
5351
5378
|
}
|
|
5352
5379
|
if (!result || Array.isArray(result) && result.length === 0) {
|
|
5353
|
-
|
|
5380
|
+
resolve6("");
|
|
5354
5381
|
return;
|
|
5355
5382
|
}
|
|
5356
|
-
|
|
5383
|
+
resolve6(result);
|
|
5357
5384
|
});
|
|
5358
5385
|
});
|
|
5359
5386
|
}
|
|
@@ -5406,11 +5433,11 @@ function toInsertRows(sql) {
|
|
|
5406
5433
|
}
|
|
5407
5434
|
__name(toInsertRows, "toInsertRows");
|
|
5408
5435
|
function isPathInside(baseDir, targetPath) {
|
|
5409
|
-
const base =
|
|
5410
|
-
const target =
|
|
5411
|
-
const
|
|
5412
|
-
if (!
|
|
5413
|
-
return !
|
|
5436
|
+
const base = path6.resolve(baseDir);
|
|
5437
|
+
const target = path6.resolve(targetPath);
|
|
5438
|
+
const relative5 = path6.relative(base, target);
|
|
5439
|
+
if (!relative5) return true;
|
|
5440
|
+
return !relative5.startsWith("..") && !path6.isAbsolute(relative5);
|
|
5414
5441
|
}
|
|
5415
5442
|
__name(isPathInside, "isPathInside");
|
|
5416
5443
|
function joinTablePath(table, ...segments) {
|
|
@@ -5592,7 +5619,7 @@ var Sql_default = {
|
|
|
5592
5619
|
|
|
5593
5620
|
// src/sysserver/db/src/file/Index.ts
|
|
5594
5621
|
import * as fs10 from "fs";
|
|
5595
|
-
import * as
|
|
5622
|
+
import * as path7 from "path";
|
|
5596
5623
|
function dbDriver(opt = {}) {
|
|
5597
5624
|
const { Sql, DbCommon } = opt;
|
|
5598
5625
|
const { isPathInside: isPathInside2, joinTablePath: joinTablePath2 } = DbCommon;
|
|
@@ -5606,7 +5633,7 @@ function dbDriver(opt = {}) {
|
|
|
5606
5633
|
this.fileDel = (config.del || 0) !== 0;
|
|
5607
5634
|
this.createDir = config.create || false;
|
|
5608
5635
|
const root = config.$asai?.serverRoot || getPrimaryServerRoot();
|
|
5609
|
-
this.baseDirAbs =
|
|
5636
|
+
this.baseDirAbs = path7.resolve(root, config.dir);
|
|
5610
5637
|
}
|
|
5611
5638
|
dbLog(...args) {
|
|
5612
5639
|
(this.config?.$asai?.$log || console.log)("FILE", ...args);
|
|
@@ -5619,9 +5646,9 @@ function dbDriver(opt = {}) {
|
|
|
5619
5646
|
if (!relPath) {
|
|
5620
5647
|
return this.baseDirAbs;
|
|
5621
5648
|
}
|
|
5622
|
-
const abs =
|
|
5649
|
+
const abs = path7.isAbsolute(relPath) ? path7.normalize(relPath) : path7.resolve(this.baseDirAbs, relPath);
|
|
5623
5650
|
if (!isPathInside2(this.baseDirAbs, abs)) {
|
|
5624
|
-
|
|
5651
|
+
throw new Error("Path not allowed");
|
|
5625
5652
|
}
|
|
5626
5653
|
return abs;
|
|
5627
5654
|
}
|
|
@@ -5633,11 +5660,11 @@ function dbDriver(opt = {}) {
|
|
|
5633
5660
|
if (!relPath) {
|
|
5634
5661
|
return "";
|
|
5635
5662
|
}
|
|
5636
|
-
return
|
|
5663
|
+
return path7.isAbsolute(relPath) ? path7.relative(this.baseDirAbs, relPath) : relPath;
|
|
5637
5664
|
}
|
|
5638
5665
|
ensureDir(relPath) {
|
|
5639
|
-
const
|
|
5640
|
-
const dirPath =
|
|
5666
|
+
const relative5 = this.normalizeRelPath(relPath);
|
|
5667
|
+
const dirPath = path7.dirname(relative5);
|
|
5641
5668
|
const absDir = this.resolvePath(dirPath === "." ? "" : dirPath);
|
|
5642
5669
|
if (this.createDir && !fs10.existsSync(absDir)) {
|
|
5643
5670
|
this.dbLog("mkdir", "[MKDIR]", absDir);
|
|
@@ -5663,9 +5690,9 @@ function dbDriver(opt = {}) {
|
|
|
5663
5690
|
this.dbLog("delete", "[RMDIR]", absPath);
|
|
5664
5691
|
const entries = fs10.readdirSync(absPath, { withFileTypes: true });
|
|
5665
5692
|
for (const entry of entries) {
|
|
5666
|
-
const current =
|
|
5693
|
+
const current = path7.join(absPath, entry.name);
|
|
5667
5694
|
if (entry.isDirectory()) {
|
|
5668
|
-
this.deldir(
|
|
5695
|
+
this.deldir(path7.join(relativePath, entry.name));
|
|
5669
5696
|
} else {
|
|
5670
5697
|
this.dbLog("delete", "[UNLINK]", current);
|
|
5671
5698
|
fs10.unlinkSync(current);
|
|
@@ -5676,8 +5703,8 @@ function dbDriver(opt = {}) {
|
|
|
5676
5703
|
getReadPath(file, sql) {
|
|
5677
5704
|
const candidates = [];
|
|
5678
5705
|
if (sql?.filename) {
|
|
5679
|
-
candidates.push({ dir:
|
|
5680
|
-
candidates.push({ dir:
|
|
5706
|
+
candidates.push({ dir: path7.join(file, sql.filename) });
|
|
5707
|
+
candidates.push({ dir: path7.join(file + ".delete" + this.fileExt, sql.filename) });
|
|
5681
5708
|
} else {
|
|
5682
5709
|
candidates.push({ dir: file });
|
|
5683
5710
|
candidates.push({ dir: file + this.fileExt + ".delete" });
|
|
@@ -5696,13 +5723,13 @@ function dbDriver(opt = {}) {
|
|
|
5696
5723
|
return { path: "", dir: read2.dir };
|
|
5697
5724
|
}
|
|
5698
5725
|
if (sql?.filename) {
|
|
5699
|
-
return { path:
|
|
5726
|
+
return { path: path7.dirname(read2.path), dir: path7.dirname(read2.dir) };
|
|
5700
5727
|
}
|
|
5701
5728
|
return { path: read2.path, dir: read2.dir };
|
|
5702
5729
|
}
|
|
5703
5730
|
getNewPath(file, sql) {
|
|
5704
5731
|
if (sql?.filename) {
|
|
5705
|
-
return this.getAbsPath(
|
|
5732
|
+
return this.getAbsPath(path7.join(file, sql.filename), true);
|
|
5706
5733
|
}
|
|
5707
5734
|
return this.getAbsPath(file, true);
|
|
5708
5735
|
}
|
|
@@ -5795,7 +5822,7 @@ function dbDriver(opt = {}) {
|
|
|
5795
5822
|
const isDelete = fileName.endsWith(deleteSuffix);
|
|
5796
5823
|
const baseName = isDelete ? fileName.slice(0, -deleteSuffix.length) : fileName;
|
|
5797
5824
|
if (this.fileExt && !baseName.endsWith(this.fileExt)) continue;
|
|
5798
|
-
const fullPath =
|
|
5825
|
+
const fullPath = path7.join(absDir, fileName);
|
|
5799
5826
|
try {
|
|
5800
5827
|
const data = fs10.readFileSync(fullPath, "utf8");
|
|
5801
5828
|
const entryData = { data, file: baseName };
|
|
@@ -5824,7 +5851,7 @@ function dbDriver(opt = {}) {
|
|
|
5824
5851
|
return String(raw ?? "");
|
|
5825
5852
|
}
|
|
5826
5853
|
sqlDb(sql) {
|
|
5827
|
-
return new Promise((
|
|
5854
|
+
return new Promise((resolve6, reject) => {
|
|
5828
5855
|
try {
|
|
5829
5856
|
let result;
|
|
5830
5857
|
const tableDir = this.tableFilePath(sql.table);
|
|
@@ -5953,7 +5980,7 @@ function dbDriver(opt = {}) {
|
|
|
5953
5980
|
}
|
|
5954
5981
|
}
|
|
5955
5982
|
if (result !== void 0) {
|
|
5956
|
-
|
|
5983
|
+
resolve6(result);
|
|
5957
5984
|
} else {
|
|
5958
5985
|
reject("");
|
|
5959
5986
|
}
|
|
@@ -6563,7 +6590,7 @@ var initAsaiHostNodejs2 = {
|
|
|
6563
6590
|
createTransportDataHandler,
|
|
6564
6591
|
wireTransportConnectionLogs
|
|
6565
6592
|
};
|
|
6566
|
-
var PLUGIN_VERSION = true ? "0.0.
|
|
6593
|
+
var PLUGIN_VERSION = true ? "0.0.8" : "0.0.1";
|
|
6567
6594
|
var index_default = initAsaiHostNodejs2;
|
|
6568
6595
|
export {
|
|
6569
6596
|
Index_default as AsaiCommon,
|