koishi-plugin-share-links-analysis 0.8.3 → 0.8.5

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.
@@ -8,7 +8,7 @@ const utils_1 = require("../utils");
8
8
  exports.name = "bilibili";
9
9
  const linkRules = [
10
10
  {
11
- pattern: /(?:https?:\/\/)?www\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+)/gi,
11
+ pattern: /(?:https?:\/\/)?(www)?m?\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+)/gi,
12
12
  type: "video",
13
13
  },
14
14
  {
package/lib/utils.js CHANGED
@@ -256,13 +256,15 @@ async function tryHeadRequest(url, proxy, userAgent, logger) {
256
256
  const u = new url_1.URL(url);
257
257
  const agent = getProxyAgent(proxy, url);
258
258
  const getter = u.protocol === 'https:' ? require('https').get : require('http').get;
259
+ const headers = { 'User-Agent': userAgent };
260
+ if (u.hostname.includes('bilibili.com')) {
261
+ headers['Referer'] = 'https://www.bilibili.com/';
262
+ }
259
263
  const req = getter(url, {
260
264
  agent,
261
265
  method: 'HEAD',
262
- timeout: 10000,
263
- headers: {
264
- 'User-Agent': userAgent,
265
- }
266
+ timeout: 5000,
267
+ headers: headers
266
268
  }, (res) => {
267
269
  const len = res.headers['content-length'];
268
270
  if (len && /^\d+$/.test(len)) {
@@ -290,13 +292,17 @@ async function tryGetRequestForSize(url, proxy, userAgent, logger) {
290
292
  const u = new url_1.URL(url);
291
293
  const agent = getProxyAgent(proxy, url);
292
294
  const getter = u.protocol === 'https:' ? require('https').get : require('http').get;
295
+ const headers = {
296
+ 'User-Agent': userAgent,
297
+ 'Range': 'bytes=0-1023'
298
+ };
299
+ if (u.hostname.includes('bilibili.com')) {
300
+ headers['Referer'] = 'https://www.bilibili.com/';
301
+ }
293
302
  const req = getter(url, {
294
303
  agent,
295
- timeout: 15000,
296
- headers: {
297
- 'User-Agent': userAgent,
298
- 'Range': 'bytes=0-1023' // 只请求前1KB
299
- }
304
+ timeout: 5000,
305
+ headers: headers
300
306
  }, (res) => {
301
307
  const contentRange = res.headers['content-range'];
302
308
  if (contentRange) {
@@ -475,13 +481,17 @@ async function sendResult_plain(ctx, session, config, result, logger, statsRef)
475
481
  const sizeBytes = await getFileSize(remoteUrl, proxy, config.userAgent, logger);
476
482
  statsRef.downloadTime += Date.now() - t;
477
483
  const maxBytes = config.Max_size * 1024 * 1024;
478
- if (sizeBytes !== null && sizeBytes > maxBytes) {
484
+ if (sizeBytes === null) {
485
+ shouldSend = false;
486
+ sendPromises.push(session.send(`无法获取文件大小,已跳过发送`));
487
+ logger.info(`获取文件大小失败,放弃发送: ${remoteUrl}`);
488
+ }
489
+ else if (sizeBytes > maxBytes) {
479
490
  shouldSend = false;
480
491
  const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);
481
492
  const maxMB = config.Max_size.toFixed(2);
482
493
  sendPromises.push(session.send(`文件大小超限 (${sizeMB} MB > ${maxMB} MB)`));
483
494
  logger.info(`文件大小超限 (${sizeMB} MB > ${maxMB} MB),跳过: ${remoteUrl}`);
484
- sendPromises.push(session.send(`文件大小超限...`));
485
495
  }
486
496
  }
487
497
  if (shouldSend) {
@@ -639,7 +649,23 @@ async function sendResult_forward(ctx, session, config, result, logger, mixed_se
639
649
  const sizeBytes = await getFileSize(remoteUrl, proxy, config.userAgent, logger);
640
650
  statsRef.downloadTime += Date.now() - t;
641
651
  const maxBytes = config.Max_size * 1024 * 1024;
642
- if (sizeBytes !== null && sizeBytes > maxBytes) {
652
+ if (sizeBytes === null) {
653
+ shouldInclude = false;
654
+ logger.warn(`获取文件大小失败,放弃发送: ${remoteUrl}`);
655
+ forwardNodes.push({
656
+ type: 'node',
657
+ data: {
658
+ user_id: session.selfId,
659
+ nickname: '分享助手',
660
+ content: {
661
+ type: 'text', data: {
662
+ text: `无法获取文件大小,已跳过发送`
663
+ }
664
+ }
665
+ }
666
+ });
667
+ }
668
+ else if (sizeBytes > maxBytes) {
643
669
  shouldInclude = false;
644
670
  const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(2);
645
671
  const maxMB = config.Max_size.toFixed(2);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "koishi-plugin-share-links-analysis",
3
3
  "description": "自用插件",
4
4
  "license": "MIT",
5
- "version": "0.8.3",
5
+ "version": "0.8.5",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [