koishi-plugin-nitter 0.0.17 → 0.0.18
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/lib/download.d.ts +1 -1
- package/lib/index.js +22 -3
- package/package.json +1 -1
package/lib/download.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function downloadImagesToBase64(imageUrls:
|
|
1
|
+
export declare function downloadImagesToBase64(imageUrls: string[]): Promise<Array<string | null>>;
|
|
2
2
|
export declare function downloadVideosToTempFiles(videoUrls: string[], tempDir: string, maxSize?: number): Promise<string[]>;
|
|
3
3
|
export declare function cleanupTempFiles(files: Array<string | null>): Promise<void>;
|
package/lib/index.js
CHANGED
|
@@ -176,6 +176,19 @@ var import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
|
176
176
|
var import_path = __toESM(require("path"));
|
|
177
177
|
var import_promises = __toESM(require("fs/promises"));
|
|
178
178
|
var import_axios2 = __toESM(require("axios"));
|
|
179
|
+
async function downloadImagesToBase64(imageUrls) {
|
|
180
|
+
return Promise.all(imageUrls.map(async (url) => {
|
|
181
|
+
try {
|
|
182
|
+
const response = await import_axios2.default.get(url, { responseType: "arraybuffer" });
|
|
183
|
+
const base64 = Buffer.from(response.data).toString("base64");
|
|
184
|
+
const contentType = response.headers?.["content-type"] || "image/jpeg";
|
|
185
|
+
return `data:${contentType};base64,${base64}`;
|
|
186
|
+
} catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
__name(downloadImagesToBase64, "downloadImagesToBase64");
|
|
179
192
|
async function downloadVideosToTempFiles(videoUrls, tempDir, maxSize = 20) {
|
|
180
193
|
await import_promises.default.mkdir(tempDir, { recursive: true });
|
|
181
194
|
const results = [];
|
|
@@ -400,10 +413,13 @@ function apply(ctx, config) {
|
|
|
400
413
|
await sendFunc(screenshotMsg);
|
|
401
414
|
const forwardMsg = [];
|
|
402
415
|
const videoUrls = pieces.filter((p) => p.type === "video").map((p) => p.url);
|
|
416
|
+
const imageUrls = pieces.filter((p) => p.type === "image").map((p) => p.url);
|
|
403
417
|
const tmpDir = config.tmpDir ?? "/shared/tmp";
|
|
418
|
+
const imageSources = imageUrls.length ? await downloadImagesToBase64(imageUrls) : [];
|
|
404
419
|
if (videoUrls.length) {
|
|
405
420
|
videoFiles = await downloadVideosToTempFiles(videoUrls, tmpDir, config.maxSize ?? 20);
|
|
406
421
|
}
|
|
422
|
+
let iIdx = 0;
|
|
407
423
|
let vIdx = 0;
|
|
408
424
|
for (const p of pieces) {
|
|
409
425
|
if (p.type === "account") {
|
|
@@ -411,9 +427,12 @@ function apply(ctx, config) {
|
|
|
411
427
|
} else if (p.type === "text") {
|
|
412
428
|
forwardMsg.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("message", { children: p.text }));
|
|
413
429
|
} else if (p.type === "image") {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
430
|
+
const src = imageSources[iIdx++];
|
|
431
|
+
if (src) {
|
|
432
|
+
forwardMsg.push(
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src }) })
|
|
434
|
+
);
|
|
435
|
+
}
|
|
417
436
|
} else if (p.type === "video") {
|
|
418
437
|
const file = videoFiles[vIdx++];
|
|
419
438
|
if (file) {
|