koishi-plugin-nitter 0.0.6 → 0.0.7

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/index.d.ts CHANGED
@@ -14,9 +14,10 @@ export interface Config {
14
14
  temperature: number;
15
15
  timeout?: number;
16
16
  app: string;
17
- sendPic: boolean;
18
17
  enableReTweet: boolean;
18
+ sendPic: boolean;
19
+ maxSize: number;
19
20
  }
20
21
  export declare const Config: Schema<Config, Dict>;
21
22
  export declare function apply(ctx: Context, config: Config): void;
22
- export declare function downloadVideosToBase64(videoUrls: any): Promise<any[]>;
23
+ export declare function downloadVideosToBase64(videoUrls: any, maxSize?: number): Promise<any[]>;
package/lib/index.js CHANGED
@@ -194,9 +194,15 @@ var Config = import_koishi.Schema.intersect([
194
194
  app: import_koishi.Schema.string().description("subscription配置中应用名")
195
195
  }).description("订阅配置"),
196
196
  import_koishi.Schema.object({
197
- sendPic: import_koishi.Schema.boolean().default(false).description("是否单独发送推文中的图片"),
198
- enableReTweet: import_koishi.Schema.boolean().default(false).description("是否发送转推")
199
- }).description("推送设置")
197
+ enableReTweet: import_koishi.Schema.boolean().default(false).description("是否发送转推"),
198
+ sendPic: import_koishi.Schema.boolean().default(false).description("是否单独发送推文中的图片")
199
+ }).description("推送设置"),
200
+ import_koishi.Schema.union([
201
+ import_koishi.Schema.object({
202
+ sendPic: import_koishi.Schema.const(true).required(),
203
+ maxSize: import_koishi.Schema.number().default(10).description("发送视频的最大大小,单位为mb")
204
+ })
205
+ ])
200
206
  ]);
201
207
  function apply(ctx, config) {
202
208
  config.nitterUrl = config.nitterUrl.replace(/\/+$/, "");
@@ -247,7 +253,7 @@ function apply(ctx, config) {
247
253
  const [screenshot, imageUrls, hlsUrls] = await renderTweetScreenshot(ctx, tweetId, config);
248
254
  let msg = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: "data:image/png;base64," + screenshot.toString("base64") });
249
255
  let forwardMsg = [];
250
- const videoUrls = await downloadVideosToBase64(hlsUrls);
256
+ const videoUrls = await downloadVideosToBase64(hlsUrls, config.maxSize);
251
257
  if (imageUrls.length > 0) {
252
258
  forwardMsg.push(...imageUrls.map((url) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: url }) })));
253
259
  }
@@ -272,7 +278,7 @@ function apply(ctx, config) {
272
278
  const screenshotMsg = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: "data:image/png;base64," + screenshot.toString("base64") });
273
279
  ctx.subscription.broadcast(config.app, account, screenshotMsg);
274
280
  let forwardMsg = [];
275
- const videoUrls = await downloadVideosToBase64(hlsUrls);
281
+ const videoUrls = await downloadVideosToBase64(hlsUrls, config.maxSize);
276
282
  if (imageUrls.length > 0) {
277
283
  forwardMsg.push(...imageUrls.map((url) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("message", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: url }) })));
278
284
  }
@@ -313,7 +319,7 @@ function apply(ctx, config) {
313
319
  }
314
320
  __name(apply, "apply");
315
321
  var tempDir = import_path.default.join(process.cwd(), "tmp");
316
- async function downloadVideosToBase64(videoUrls) {
322
+ async function downloadVideosToBase64(videoUrls, maxSize = 20) {
317
323
  await import_promises.default.mkdir(tempDir, { recursive: true });
318
324
  const results = [];
319
325
  for (const url of videoUrls) {
@@ -331,8 +337,8 @@ async function downloadVideosToBase64(videoUrls) {
331
337
  });
332
338
  const stats = await import_promises.default.stat(outputPath);
333
339
  const fileSizeInMB = stats.size / (1024 * 1024);
334
- if (fileSizeInMB > 10) {
335
- logger.info(`视频大小 ${fileSizeInMB.toFixed(2)}MB 超过10MB限制,跳过转换`);
340
+ if (fileSizeInMB > maxSize) {
341
+ logger.info(`视频大小 ${fileSizeInMB.toFixed(2)}MB 超过${maxSize}MB限制,跳过转换`);
336
342
  } else {
337
343
  const fileBuffer = await import_promises.default.readFile(outputPath);
338
344
  const base64String = fileBuffer.toString("base64");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-nitter",
3
3
  "description": "使用Rettiwt-API订阅推文,并使用nitter渲染",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [