@wahaha216/koishi-plugin-jmcomic 0.1.0 → 0.1.1

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.js CHANGED
@@ -33,14 +33,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  // src/locales/zh-CN.yml
34
34
  var require_zh_CN = __commonJS({
35
35
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { jm: { description: "下载JM漫画,无需python!", examples: "jm album 本子数字ID\njm album info 本子数字ID\njm photo 本子章节数字ID", album: { examples: "jm album 数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" }, info: { examples: "jm album info 本子数字ID", messages: { notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } } }, photo: { examples: "jm photo 本子章节数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", notExistError: "找不到该ID对应的章节", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } }, queue: { examples: "jm queue", messages: { emptyQueue: "当前没有正在处理或者等待处理的任务", msgFormat: "ID: {id}, 类型: {type}, 状态: {status}\n", task: { pending: "等待中...", processing: "处理中...", failed: "发生未知错误", completed: "已完成", unknown: "未定义状态" }, type: { album: "本子", photo: "章节" } } } } }, _config: [{ $desc: "基础设置", sendMethod: "发送方式", fileMethod: "文件获取方式<br>`buffer`: 读取成buffer后发送给bot实现端<br>`file`: 以`file:///` 本地路径形式发送,如docker环境,请在bot实现端同时映射/koishi目录", password: "密码,留空则不加密", fileName: "文件名定义<br>`{{name}}`:标题<br>`{{id}}`:章节或者本子ID<br>`{{index}}`:多章节本子自动填充`1` 、 `2`" }, { level: "压缩级别,0~9,0为仅存储" }, { $desc: "限制相关设置", retryCount: "重试次数限制", concurrentDownloadLimit: "同时下载数量限制", concurrentDecodeLimit: "同时解密数量限制", concurrentQueueLimit: "同时处理数量限制" }, { $desc: "缓存设置", cache: "缓存文件" }, { autoDelete: "自动删除缓存,**依赖cron服务**" }, { cron: "5位cron表达式", deleteInStart: "启动时检测", keepDays: "缓存保留时间(天)" }, { $desc: "开发者选项", debug: "调试模式,输出更多信息" }] };
36
+ module2.exports = { commands: { jm: { description: "下载JM漫画,无需python!", examples: "jm album 本子数字ID\njm album info 本子数字ID\njm photo 本子章节数字ID", album: { examples: "jm album 数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" }, info: { examples: "jm album info 本子数字ID", messages: { notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } } }, photo: { examples: "jm photo 本子章节数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的章节", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } }, queue: { examples: "jm queue", messages: { emptyQueue: "当前没有正在处理或者等待处理的任务", msgFormat: "ID: {id}, 类型: {type}, 状态: {status}\n", task: { pending: "等待中...", processing: "处理中...", failed: "发生未知错误", completed: "已完成", unknown: "未定义状态" }, type: { album: "本子", photo: "章节" } } } } }, _config: [{ $desc: "基础设置", sendMethod: "发送方式", fileMethod: "文件获取方式<br>`buffer`: 读取成buffer后发送给bot实现端<br>`file`: 以`file:///` 本地路径形式发送,如docker环境,请在bot实现端同时映射/koishi目录", password: "密码,留空则不加密", fileName: "文件名定义<br>`{{name}}`:标题<br>`{{id}}`:章节或者本子ID<br>`{{index}}`:多章节本子自动填充`1` 、 `2`" }, { level: "压缩级别,0~9,0为仅存储" }, { $desc: "限制相关设置", retryCount: "重试次数限制", concurrentDownloadLimit: "同时下载数量限制", concurrentDecodeLimit: "同时解密数量限制", concurrentQueueLimit: "同时处理数量限制" }, { $desc: "缓存设置", cache: "缓存文件" }, { autoDelete: "自动删除缓存,**依赖cron服务**" }, { cron: "5位cron表达式", deleteInStart: "启动时检测", keepDays: "缓存保留时间(天)" }, { $desc: "开发者选项", debug: "调试模式,输出更多信息" }] };
37
37
  }
38
38
  });
39
39
 
40
40
  // src/locales/en-US.yml
41
41
  var require_en_US = __commonJS({
42
42
  "src/locales/en-US.yml"(exports2, module2) {
43
- module2.exports = { commands: { jm: { description: "Download JM comics without python!", examples: "jm album albumID\njm album info albumID\njm photo photoID", album: { examples: "jm album albumID", messages: { addedToQueue: "Album {id} has been added to the processing queue. Please wait.", notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." }, info: { examples: "jm album info albumID", messages: { notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." } } }, photo: { examples: "jm photo photoID", messages: { addedToQueue: "Photo {id} has been added to the processing queue. Please wait.", notExistError: "photoID not found", mysqlError: "All alternate addresses have been tried. But no response." } }, queue: { examples: "jm queue", messages: { emptyQueue: "There are currently no tasks being processed or waiting.", msgFormat: "ID: {id}, type: {type}, status: {status}\n", task: { Pending: "Pending...", Processing: "Processing...", failed: "Failed (Unknown Error)", completed: "Completed", unknown: "Unknown Status" }, type: { album: "Album", photo: "Photo" } } } } }, _config: [{ $desc: "Basic settings", sendMethod: "Send method", fileMethod: "File acquisition method<br>`buffer`: Read as buffer and send it to the bot implementation.<br>`file`: Send it in the local path of `file:///`. For example, if in the docker environment, please map the `/koishi` directory at the bot implementation.", retryCount: "Retry limit", password: "Password, leave blank without encryption", fileName: "File name definition<br>`{{name}}`: Title<br>`{{id}}`: Chapter or Book ID<br>`{{index}}`: Multi-chapter book auto-filling `_1` `_2`" }, { $desc: "Limit settings", retryCount: "Retry limit", concurrentDownloadLimit: "Concurrent Download Limit", concurrentDecodeLimit: "Concurrent Decode Limit", concurrentQueueLimit: "Concurrent Queue Limit" }, { level: "Compression level, 0~9, 0 is only stores" }, { $desc: "Cache settings", cache: "Cache files" }, { autoDelete: "Automatically delete cache, **need cron services**" }, { cron: "5-bit cron expression", deleteInStart: "Detection on startup", keepDays: "Cache retention time (days)" }, { $desc: "Developer Options", debug: "Debug mode, output more information" }] };
43
+ module2.exports = { commands: { jm: { description: "Download JM comics without python!", examples: "jm album albumID\njm album info albumID\njm photo photoID", album: { examples: "jm album albumID", messages: { addedToQueue: "Album {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." }, info: { examples: "jm album info albumID", messages: { notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." } } }, photo: { examples: "jm photo photoID", messages: { addedToQueue: "Photo {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "photoID not found", mysqlError: "All alternate addresses have been tried. But no response." } }, queue: { examples: "jm queue", messages: { emptyQueue: "There are currently no tasks being processed or waiting.", msgFormat: "ID: {id}, type: {type}, status: {status}\n", task: { Pending: "Pending...", Processing: "Processing...", failed: "Failed (Unknown Error)", completed: "Completed", unknown: "Unknown Status" }, type: { album: "Album", photo: "Photo" } } } } }, _config: [{ $desc: "Basic settings", sendMethod: "Send method", fileMethod: "File acquisition method<br>`buffer`: Read as buffer and send it to the bot implementation.<br>`file`: Send it in the local path of `file:///`. For example, if in the docker environment, please map the `/koishi` directory at the bot implementation.", retryCount: "Retry limit", password: "Password, leave blank without encryption", fileName: "File name definition<br>`{{name}}`: Title<br>`{{id}}`: Chapter or Book ID<br>`{{index}}`: Multi-chapter book auto-filling `_1` `_2`" }, { $desc: "Limit settings", retryCount: "Retry limit", concurrentDownloadLimit: "Concurrent Download Limit", concurrentDecodeLimit: "Concurrent Decode Limit", concurrentQueueLimit: "Concurrent Queue Limit" }, { level: "Compression level, 0~9, 0 is only stores" }, { $desc: "Cache settings", cache: "Cache files" }, { autoDelete: "Automatically delete cache, **need cron services**" }, { cron: "5-bit cron expression", deleteInStart: "Detection on startup", keepDays: "Cache retention time (days)" }, { $desc: "Developer Options", debug: "Debug mode, output more information" }] };
44
44
  }
45
45
  });
46
46
 
@@ -1287,8 +1287,9 @@ var Queue = class {
1287
1287
  this.logger.info(
1288
1288
  `[任务添加] 任务ID: ${payload} 类型: ${payload.type} ID: ${payload.id}`
1289
1289
  );
1290
+ const { pendingAhead, queuePosition } = this.getTaskQueuePosition(task.id);
1290
1291
  setTimeout(() => this._processQueue(), 0);
1291
- return task;
1292
+ return { task, pendingAhead, queuePosition };
1292
1293
  }
1293
1294
  /**
1294
1295
  * 获取任务状态
@@ -1302,15 +1303,42 @@ var Queue = class {
1302
1303
  getAllTasks() {
1303
1304
  return this.tasks;
1304
1305
  }
1306
+ /**
1307
+ * 获取指定任务在队列中的位置信息
1308
+ * @param taskId 任务ID
1309
+ * @returns {pendingAhead: number, queuePosition: number}
1310
+ * pendingAhead: 在此任务之前有多少个待处理任务
1311
+ * queuePosition: 此任务在所有待处理任务中的位置(从1开始)
1312
+ */
1313
+ getTaskQueuePosition(taskId) {
1314
+ let pendingAhead = 0;
1315
+ let queuePosition = 0;
1316
+ let found = false;
1317
+ for (let i = 0; i < this.tasks.length; i++) {
1318
+ const currentTask = this.tasks[i];
1319
+ if (currentTask.id === taskId) {
1320
+ found = true;
1321
+ if (currentTask.status === "pending" || currentTask.status === "processing") {
1322
+ queuePosition = pendingAhead + 1;
1323
+ }
1324
+ break;
1325
+ }
1326
+ if (currentTask.status === "pending" || currentTask.status === "processing") {
1327
+ pendingAhead++;
1328
+ }
1329
+ }
1330
+ if (!found) {
1331
+ return { pendingAhead: -1, queuePosition: -1 };
1332
+ }
1333
+ return { pendingAhead, queuePosition };
1334
+ }
1305
1335
  /**
1306
1336
  * 检查并处理队列中的任务
1307
1337
  */
1308
1338
  _processQueue() {
1309
1339
  while (this.activeTasks < this.concurrency) {
1310
1340
  const task = this.tasks.find((t) => t.status === "pending");
1311
- if (!task) {
1312
- break;
1313
- }
1341
+ if (!task) break;
1314
1342
  this.activeTasks++;
1315
1343
  task.status = "processing";
1316
1344
  if (this.config.debug)
@@ -1443,35 +1471,42 @@ async function apply(ctx, config) {
1443
1471
  config,
1444
1472
  logger
1445
1473
  );
1446
- ctx.command("jm.album <albumId:string>").alias("本子").action(async ({ session, options }, albumId) => {
1474
+ const handleAlbumOrPhoto = /* @__PURE__ */ __name(async (session, id) => {
1447
1475
  const messageId = session.messageId;
1448
- if (!/^\d+$/.test(albumId)) {
1476
+ if (!/^\d+$/.test(id)) {
1449
1477
  await session.send([
1450
1478
  import_koishi2.h.quote(messageId),
1451
1479
  import_koishi2.h.text("输入的ID不合法,请检查")
1452
1480
  ]);
1453
1481
  return;
1454
1482
  }
1455
- queue.add({ type: "album", id: albumId, session, messageId });
1456
- await session.send([
1457
- import_koishi2.h.quote(messageId),
1458
- import_koishi2.h.text(session.text(".addedToQueue", { id: albumId }))
1459
- ]);
1483
+ const { task, pendingAhead, queuePosition } = queue.add({
1484
+ type: "album",
1485
+ id,
1486
+ session,
1487
+ messageId
1488
+ });
1489
+ const params = {
1490
+ id,
1491
+ ahead: pendingAhead,
1492
+ pos: queuePosition,
1493
+ status: task.status
1494
+ };
1495
+ const msg = [import_koishi2.h.quote(messageId)];
1496
+ if (pendingAhead === 0 && queuePosition === 1) {
1497
+ msg.push(import_koishi2.h.text(session.text(".queueFirst", params)));
1498
+ } else if (pendingAhead > 0) {
1499
+ msg.push(import_koishi2.h.text(session.text(".queuePosition", params)));
1500
+ } else {
1501
+ msg.push(import_koishi2.h.text(session.text(".queueProcessing", params)));
1502
+ }
1503
+ await session.send(msg);
1504
+ }, "handleAlbumOrPhoto");
1505
+ ctx.command("jm.album <albumId:string>").alias("本子").action(async ({ session, options }, albumId) => {
1506
+ await handleAlbumOrPhoto(session, albumId);
1460
1507
  });
1461
1508
  ctx.command("jm.photo <photoId:string>").alias("本子章节").action(async ({ session }, photoId) => {
1462
- const messageId = session.messageId;
1463
- if (!/^\d+$/.test(photoId)) {
1464
- await session.send([
1465
- import_koishi2.h.quote(messageId),
1466
- import_koishi2.h.text("输入的ID不合法,请检查")
1467
- ]);
1468
- return;
1469
- }
1470
- queue.add({ type: "album", id: photoId, session, messageId });
1471
- await session.send([
1472
- import_koishi2.h.quote(messageId),
1473
- import_koishi2.h.text(session.text(".addedToQueue", { id: photoId }))
1474
- ]);
1509
+ await handleAlbumOrPhoto(session, photoId);
1475
1510
  });
1476
1511
  ctx.command("jm.album.info <albumId:string>").alias("本子信息").action(async ({ session, options }, albumId) => {
1477
1512
  const messageId = session.messageId;
@@ -21,6 +21,11 @@ type TaskProcessor = (payload: JmTaskPayload) => Promise<void>;
21
21
  interface QueueOptions {
22
22
  concurrency?: number;
23
23
  }
24
+ interface AddTaskResult {
25
+ task: Task;
26
+ pendingAhead: number;
27
+ queuePosition: number;
28
+ }
24
29
  export declare class Queue {
25
30
  private tasks;
26
31
  private processor;
@@ -38,7 +43,7 @@ export declare class Queue {
38
43
  /**
39
44
  * 向队列添加一个新任务
40
45
  */
41
- add(payload: JmTaskPayload): Task;
46
+ add(payload: JmTaskPayload): AddTaskResult;
42
47
  /**
43
48
  * 获取任务状态
44
49
  */
@@ -47,6 +52,17 @@ export declare class Queue {
47
52
  * 获取所有任务的只读列表
48
53
  */
49
54
  getAllTasks(): Readonly<Task[]>;
55
+ /**
56
+ * 获取指定任务在队列中的位置信息
57
+ * @param taskId 任务ID
58
+ * @returns {pendingAhead: number, queuePosition: number}
59
+ * pendingAhead: 在此任务之前有多少个待处理任务
60
+ * queuePosition: 此任务在所有待处理任务中的位置(从1开始)
61
+ */
62
+ getTaskQueuePosition(taskId: string): {
63
+ pendingAhead: number;
64
+ queuePosition: number;
65
+ };
50
66
  /**
51
67
  * 检查并处理队列中的任务
52
68
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wahaha216/koishi-plugin-jmcomic",
3
3
  "description": "下载JM本子,无需python。支持pdf、zip加密。",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -10,6 +10,7 @@
10
10
  jm album xxxxxx
11
11
  jm album info xxxxxx
12
12
  jm photo xxxxxx
13
+ jm queue
13
14
  ```
14
15
 
15
16
  可在配置中配置是发送 PDF 还是 ZIP 压缩包,支持加密。
@@ -17,18 +18,22 @@ jm photo xxxxxx
17
18
  ## 更新日志
18
19
 
19
20
  <details>
20
- <summary>0.1.0</summary>
21
- 1.队列系统
22
-
23
- 2.下载并发与解密并发限制
21
+ <summary>0.1.1</summary>
24
22
 
25
- 3.修改配置页面顺序、分类
23
+ 1. 添加队列时返回队列信息
24
+ 2. 提取代码
26
25
 
27
- 4.不再直接暴露变量,改为逐级传递
26
+ </details>
28
27
 
29
- 5.统一暴露Error类
28
+ <details>
29
+ <summary>0.1.0</summary>
30
30
 
31
- 6.添加域名切换条件
31
+ 1. 队列系统
32
+ 2. 下载并发与解密并发限制
33
+ 3. 修改配置页面顺序、分类
34
+ 4. 不再直接暴露变量,改为逐级传递
35
+ 5. 统一暴露Error类
36
+ 6. 添加域名切换条件
32
37
 
33
38
  </details>
34
39
 
@@ -44,9 +49,9 @@ jm photo xxxxxx
44
49
 
45
50
  <details>
46
51
  <summary>0.0.4</summary>
47
- 1.文件名移除前后空格
48
52
 
49
- 2.新增文件发送配置,用于配置文件是以 buffer 读取后发送还是以本地地址的形式发送。docker 中使用 file 形式需要在 bot 实现端同时映射/koishi 目录
53
+ 1. 文件名移除前后空格
54
+ 2. 新增文件发送配置,用于配置文件是以 buffer 读取后发送还是以本地地址的形式发送。docker 中使用 file 形式需要在 bot 实现端同时映射/koishi 目录
50
55
 
51
56
  </details>
52
57