agent-bridge-aun 1.0.25 → 1.0.27
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AunDownloadUrlError = void 0;
|
|
3
4
|
exports.parseAunAttachment = parseAunAttachment;
|
|
4
5
|
exports.downloadAunAttachments = downloadAunAttachments;
|
|
5
6
|
exports.downloadAunAttachment = downloadAunAttachment;
|
|
@@ -162,10 +163,20 @@ async function downloadAunAttachments(client, refs) {
|
|
|
162
163
|
(0, attachments_1.validateAttachments)(result);
|
|
163
164
|
return result;
|
|
164
165
|
}
|
|
166
|
+
class AunDownloadUrlError extends Error {
|
|
167
|
+
diagnostic;
|
|
168
|
+
constructor(url, reason) {
|
|
169
|
+
super("AUN 下载地址无效");
|
|
170
|
+
this.name = "AunDownloadUrlError";
|
|
171
|
+
this.diagnostic = { protocol: url.protocol, hostname: url.hostname, port: url.port, reason };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.AunDownloadUrlError = AunDownloadUrlError;
|
|
165
175
|
function checkedDownloadUrl(url) {
|
|
166
176
|
const storagePort = url.port === "9470" && /^storage\.[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(url.hostname);
|
|
167
|
-
|
|
168
|
-
|
|
177
|
+
const reason = url.protocol !== "https:" ? "协议" : url.username || url.password ? "凭据" : url.port && !storagePort ? "端口" : url.hash ? "片段" : !url.hostname.includes(".") ? "主机名" : /^(?:localhost|127\.|0\.|10\.|192\.168\.|169\.254\.|172\.(?:1[6-9]|2\d|3[01])\.)/.test(url.hostname) ? "本机地址" : url.hostname.includes(":") ? "主机名" : undefined;
|
|
178
|
+
if (reason)
|
|
179
|
+
throw new AunDownloadUrlError(url, reason);
|
|
169
180
|
return url;
|
|
170
181
|
}
|
|
171
182
|
async function readDownloadTicket(value, expectedSize) {
|
|
@@ -226,9 +237,21 @@ async function uploadAunAttachments(client, ownerAid, peerAid, items) {
|
|
|
226
237
|
const objectKey = `shared/${(0, node_crypto_1.randomUUID)()}/${filename.replace(/[^A-Za-z0-9._-]/g, "_")}`;
|
|
227
238
|
const sha256 = digest(item.data);
|
|
228
239
|
const ref = { ownerAid, bucket: "default", objectKey, filename, contentType: item.contentType.toLowerCase(), sizeBytes: item.data.byteLength, sha256 };
|
|
229
|
-
const uploaded = await client.storage.writeBytes(`/${objectKey}`, item.data, { contentType: item.contentType, public:
|
|
240
|
+
const uploaded = await client.storage.writeBytes(`/${objectKey}`, item.data, { contentType: item.contentType, public: false, overwrite: false });
|
|
230
241
|
checkedMetadata({ ...uploaded, size: uploaded.size ?? uploaded.size_bytes ?? item.data.byteLength }, ref);
|
|
231
|
-
|
|
242
|
+
const share = await client.storage.lowlevel.createShareLink({ owner: ownerAid, bucket: "default", objectKey, allowedAids: [peerAid], expireInSeconds: 86400 });
|
|
243
|
+
if (share.owner_aid && share.owner_aid !== ownerAid || share.bucket && share.bucket !== "default" || share.object_key && share.object_key !== objectKey)
|
|
244
|
+
throw new Error("AUN 附件分享对象不一致");
|
|
245
|
+
if (share.allowed_aids !== undefined && (!Array.isArray(share.allowed_aids) || share.allowed_aids.length !== 1 || share.allowed_aids[0] !== peerAid))
|
|
246
|
+
throw new Error("AUN 附件分享授权不一致");
|
|
247
|
+
const shareId = typeof share.share_id === "string" && /^[A-Za-z0-9]{10}$/.test(share.share_id) ? share.share_id : undefined;
|
|
248
|
+
if (share.share_id !== undefined && !shareId)
|
|
249
|
+
throw new Error("AUN 附件分享标识无效");
|
|
250
|
+
const url = typeof share.path_url === "string" && share.path_url ? share.path_url : shareId ? `https://${ownerAid}/${objectKey}?t=${shareId}` : "";
|
|
251
|
+
const token = url ? pathToken(url, ownerAid, objectKey) : undefined;
|
|
252
|
+
if (!token || shareId && shareId !== token)
|
|
253
|
+
throw new Error("AUN 附件分享链接无效");
|
|
254
|
+
result.push({ owner_aid: ownerAid, bucket: "default", object_key: objectKey, url, filename, content_type: item.contentType, size_bytes: item.data.byteLength, sha256 });
|
|
232
255
|
}
|
|
233
256
|
return result;
|
|
234
257
|
}
|
|
@@ -11,7 +11,7 @@ const node_url_1 = require("node:url");
|
|
|
11
11
|
const messages_1 = require("./messages");
|
|
12
12
|
const attachments_1 = require("./attachments");
|
|
13
13
|
const manifest = {
|
|
14
|
-
id: "aun", version: "1.0.
|
|
14
|
+
id: "aun", version: "1.0.27", type: "channel", displayName: "AUN 通道",
|
|
15
15
|
entry: "dist/src-ts/plugins/aun/index.js", apiVersion: "1", process: "in-process",
|
|
16
16
|
capabilities: ["channel", "channel.identity.create", "channel.receive", "channel.send", "health", "cli"],
|
|
17
17
|
configSchema: "config.schema.json",
|
|
@@ -783,7 +783,7 @@ class AunPlugin {
|
|
|
783
783
|
}
|
|
784
784
|
}
|
|
785
785
|
catch (error) {
|
|
786
|
-
this.context?.logger.warn("AUN 附件下载失败", { error: safeError(error) });
|
|
786
|
+
this.context?.logger.warn("AUN 附件下载失败", { error: safeError(error), ...(error instanceof attachments_1.AunDownloadUrlError ? { downloadUrl: error.diagnostic } : {}) });
|
|
787
787
|
try {
|
|
788
788
|
await this.sendText(aid, message.peerId, `附件接收失败:${safeError(error)}`, message.threadId);
|
|
789
789
|
}
|
package/package.json
CHANGED