koishi-plugin-fimtale-api 1.0.6 → 1.0.8

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.
Files changed (2) hide show
  1. package/lib/index.js +20 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -66,7 +66,7 @@ function apply(ctx, config) {
66
66
  }, "stripHtml");
67
67
  const extractImage = /* @__PURE__ */ __name((html) => {
68
68
  if (!html) return null;
69
- const match = html.match(/<img[^>]+src="([^">]+)"/);
69
+ const match = html.match(/<img[^>]+src\s*=\s*["']([^"']+)["']/i);
70
70
  return match ? match[1] : null;
71
71
  }, "extractImage");
72
72
  const generateGradient = /* @__PURE__ */ __name((str) => {
@@ -194,14 +194,29 @@ function apply(ctx, config) {
194
194
  const isChapter = info.IsChapter || !!parent && parent.ID !== info.ID;
195
195
  const displayTitle = isChapter && parent ? parent.Title : info.Title;
196
196
  let displayCover = info.Background || extractImage(info.Content);
197
- if (!displayCover && isChapter && parent) {
198
- displayCover = parent.Background || extractImage(parent.Content);
197
+ if (!displayCover && parent) {
198
+ displayCover = parent.Background;
199
+ if (!displayCover) {
200
+ if (parent.Content) {
201
+ displayCover = extractImage(parent.Content);
202
+ } else {
203
+ try {
204
+ const parentRes = await fetchThread(parent.ID.toString());
205
+ if (parentRes.valid && parentRes.data) {
206
+ displayCover = parentRes.data.Background || extractImage(parentRes.data.Content);
207
+ }
208
+ } catch (e) {
209
+ }
210
+ }
211
+ }
199
212
  }
200
213
  const displayTagsObj = isChapter && parent ? parent.Tags : info.Tags;
201
214
  const subTitle = isChapter ? info.Title : null;
202
215
  const bgStyle = displayCover ? `background-image: url('${displayCover}');` : `background: ${generateGradient(displayTitle)};`;
203
216
  let summary = stripHtml(info.Content);
204
- if (summary.length < 10 && parent && isChapter) summary = stripHtml(parent.Content);
217
+ if (summary.length < 10 && parent && isChapter) {
218
+ summary = stripHtml(parent.Content);
219
+ }
205
220
  if (summary.length > 150) summary = summary.substring(0, 150) + "...";
206
221
  if (!summary) summary = "暂无简介";
207
222
  const tagsArr = [];
@@ -538,7 +553,7 @@ function apply(ctx, config) {
538
553
  });
539
554
  ctx.middleware(async (session, next) => {
540
555
  if (!config.autoParseLink) return next();
541
- const matches = [...session.content.matchAll(/fimtale\.com\/t\/(\d+)/g)];
556
+ const matches = [...session.content.matchAll(/fimtale\.(?:com|net)\/t\/(\d+)/g)];
542
557
  if (matches.length === 0) return next();
543
558
  const uniqueIds = [...new Set(matches.map((m) => m[1]))];
544
559
  if (session.userId === session.selfId) return next();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-fimtale-api",
3
3
  "description": "Koishi插件,从fimtale搜索/订阅/随机获取小说/解析链接等",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [