koishi-plugin-share-links-analysis 0.2.5 → 0.3.0
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 +1 -1
- package/lib/parsers/bilibili.js +2 -2
- package/lib/parsers/xiaohongshu.js +23 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function apply(ctx, config) {
|
|
|
81
81
|
ctx.middleware(async (session, next) => {
|
|
82
82
|
if (!session.content || !session.channelId)
|
|
83
83
|
return next();
|
|
84
|
-
const content = session.content.replace(/\\/g, '');
|
|
84
|
+
const content = session.content.replace(/\\/g, '').replace(/&/g, '&');
|
|
85
85
|
const channelId = session.channelId;
|
|
86
86
|
const links = (0, core_1.resolveLinks)(content);
|
|
87
87
|
if (links.length === 0)
|
package/lib/parsers/bilibili.js
CHANGED
|
@@ -13,8 +13,8 @@ function match(content) {
|
|
|
13
13
|
const results = [];
|
|
14
14
|
// 匹配标准长链接和短链接
|
|
15
15
|
const linkRegex = [
|
|
16
|
-
{ pattern: /(https?:\/\/)?(www\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+))/
|
|
17
|
-
{ pattern: /(https?:\/\/)?(b23\.tv\/[0-9a-zA-Z]+)/
|
|
16
|
+
{ pattern: /(https?:\/\/)?(www\.bilibili\.com\/video\/([ab]v[0-9a-zA-Z]+))/g, type: "video" },
|
|
17
|
+
{ pattern: /(https?:\/\/)?(b23\.tv\/[0-9a-zA-Z]+)/g, type: "short" },
|
|
18
18
|
];
|
|
19
19
|
for (const rule of linkRegex) {
|
|
20
20
|
const matches = [...content.matchAll(new RegExp(rule.pattern, 'gi'))];
|
|
@@ -12,16 +12,29 @@ const utils_1 = require("../utils");
|
|
|
12
12
|
* @returns 匹配到的链接对象数组
|
|
13
13
|
*/
|
|
14
14
|
function match(content) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const results = [];
|
|
16
|
+
// 匹配标准长链接和短链接
|
|
17
|
+
const linkRegex = [
|
|
18
|
+
{ pattern: /(https?:\/\/)?(www\.xiaohongshu\.com\/discovery\/item\/([\w?=\-&\.%]+))/g, type: "discovery" },
|
|
19
|
+
{ pattern: /(https?:\/\/)?(www\.xiaohongshu\.com\/explore\/([\w?=\-&\.%]+))/g, type: "explore" },
|
|
20
|
+
{ pattern: /(https?:\/\/)?(xhslink\.com\/(m\/)?[0-9a-zA-Z]+)/g, type: "short" },
|
|
21
|
+
];
|
|
22
|
+
for (const rule of linkRegex) {
|
|
23
|
+
const matches = [...content.matchAll(new RegExp(rule.pattern, 'gi'))];
|
|
24
|
+
for (const matchArr of matches) {
|
|
25
|
+
if (matchArr[2]) {
|
|
26
|
+
// 强制将所有链接格式化为 https 开头
|
|
27
|
+
const formattedUrl = `https://${matchArr[2]}`;
|
|
28
|
+
results.push({
|
|
29
|
+
platform: 'xiaohongshu',
|
|
30
|
+
type: rule.type,
|
|
31
|
+
id: formattedUrl.split('/').pop().split('?')[0],
|
|
32
|
+
url: formattedUrl
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
25
38
|
}
|
|
26
39
|
/**
|
|
27
40
|
* 使用 Puppeteer 刷新小红书 Cookie 并存入数据库
|