From 560f68de0bedafc1041fec7c59249b311a2dbc43 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Mon, 10 Feb 2025 08:27:03 +0000 Subject: [PATCH 01/12] feat(route): add route Gelbooru --- lib/routes/gelbooru/namespace.ts | 7 ++ lib/routes/gelbooru/post.ts | 121 +++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 lib/routes/gelbooru/namespace.ts create mode 100644 lib/routes/gelbooru/post.ts diff --git a/lib/routes/gelbooru/namespace.ts b/lib/routes/gelbooru/namespace.ts new file mode 100644 index 00000000000000..11b2154317f5c6 --- /dev/null +++ b/lib/routes/gelbooru/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Gelbooru | Free Anime and Hentai Gallery', + url: 'gelbooru.com', + description: `gelbooru posts`, +}; diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts new file mode 100644 index 00000000000000..3ac93dc073d91c --- /dev/null +++ b/lib/routes/gelbooru/post.ts @@ -0,0 +1,121 @@ +import { Route, ViewType } from '@/types'; +import { Context } from 'hono'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import queryString from 'query-string'; + +export const route: Route = { + path: '/post/:tags?', + categories: ['picture'], + view: ViewType.Pictures, + example: '/gelbooru/post/1girl rating:general', + parameters: { + tags: `要搜索的标签,多个标签用 \` \`(空格)隔开`, + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['gelbooru.com/index.php'], + }, + ], + name: 'Gelbooru 标签查询', + maintainers: ['magicFeirl'], + description: ` +- 默认查询: \`/gelbooru/post\` 功能等同查询 Gelbooru 网站最新的投稿 +- 单标签查询: \`/gelbooru/post/1girl\` 查询 \`1girl\` 的最新投稿 +- 多标签查询: \`\`/gelbooru/post/1girl school_uniform rating:general\`\` +- 更多例子: 请参考 Gelbooru 官方 wiki https://gelbooru.com/index.php?page=wiki&s=&s=view&id=25921 + +**可选的 URL 参数** +- apiKey & userId: API Access Credentials 如果需要认证,从 https://gelbooru.com/index.php?page=account&s=options 获取 +- limit 页面返回数据量,默认 40,可选 1 ~ 100 + +e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx\` +`, + handler, +}; + +function generatePostDescription(post, link) { + const { id, source, owner, file_url: fileUrl, tags, score } = post; + const isURL = URL.canParse(source); + const sourceHtml = isURL ? `Source` : `${source}`; + const sourceHost = isURL ? new URL(source).host : source; + const postHtml = `#${id}`; + const uploadByHtml = `Upload by: ${owner}`; + + // 只有两个视频后缀 + const videoExtList = ['mp4', 'webm']; + const fileExt = fileUrl.slice(fileUrl.lastIndexOf('.') + 1); + + // 默认是图片,但是也考虑视频的情况 + let contentHtml = ``; + if (videoExtList.includes(fileExt)) { + contentHtml = ``; + } + + return ` +
${contentHtml}
+

+

Info of ${postHtml}:

+

${sourceHtml}(${sourceHost})

+

${uploadByHtml}

+

Score: ${score || '-'}

+

Tags:

${tags}

+ `; +} + +async function handler(ctx: Context) { + const tags = (decodeURIComponent(ctx.req.param('tags')) || '').trim(); + const { apiKey = '', userId = '', limit = 40 }: { apiKey?: string; userId?: string; limit?: number } = ctx.req.query(); + + const response = await got({ + url: 'https://gelbooru.com/index.php', + searchParams: queryString.stringify({ + page: 'dapi', + s: 'post', + q: 'index', + tags, + api_key: apiKey, + user_id: userId, + limit: limit <= 0 || limit > 100 ? 40 : limit, + json: 1, + }), + }); + + const posts = response.data.post; + + return { + title: tags ? `${tags} - gelbooru.com` : `gelbooru.com post list`, + link: `https://gelbooru.com/index.php?page=post&s=list&tags=${tags}`, + icon: 'https://gelbooru.com/favicon.png', + logo: 'https://gelbooru.com/favicon.png', + description: 'Gelbooru post list', + item: posts.map((post) => ({ + title: post.id, + id: post.id, + link: `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, + author: post.owner, + pubDate: parseDate(post.created_at), + description: generatePostDescription(post, `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`), + upvotes: post.score, + updated: parseDate(post.change), + media: { + content: { + url: post.file_url, + }, + thumbnail: { + url: post.preview_url, + }, + }, + category: post.tags.split(/\s+/g), + })), + }; +} From a871d0f4824bbb3dd394bcd6bc9caccbafaed20f Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Mon, 10 Feb 2025 08:46:31 +0000 Subject: [PATCH 02/12] feat(route): add image quality option for Gelbooru --- lib/routes/gelbooru/post.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index 3ac93dc073d91c..6c0d429f716a0a 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -31,32 +31,35 @@ export const route: Route = { description: ` - 默认查询: \`/gelbooru/post\` 功能等同查询 Gelbooru 网站最新的投稿 - 单标签查询: \`/gelbooru/post/1girl\` 查询 \`1girl\` 的最新投稿 -- 多标签查询: \`\`/gelbooru/post/1girl school_uniform rating:general\`\` +- 多标签查询: \`/gelbooru/post/1girl school_uniform rating:general\` - 更多例子: 请参考 Gelbooru 官方 wiki https://gelbooru.com/index.php?page=wiki&s=&s=view&id=25921 **可选的 URL 参数** - apiKey & userId: API Access Credentials 如果需要认证,从 https://gelbooru.com/index.php?page=account&s=options 获取 - limit 页面返回数据量,默认 40,可选 1 ~ 100 +- imgQuality \`sample\` or \`orig\` 图片质量,默认为 sample -e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx\` +e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx&imgQuality=orig\` `, handler, }; -function generatePostDescription(post, link) { +function generatePostDescription(post, link, quality: 'sample' | 'orig') { const { id, source, owner, file_url: fileUrl, tags, score } = post; const isURL = URL.canParse(source); const sourceHtml = isURL ? `Source` : `${source}`; const sourceHost = isURL ? new URL(source).host : source; const postHtml = `#${id}`; const uploadByHtml = `Upload by: ${owner}`; + const imgQualityMap = { sample: 'sample_url', orig: 'file_url' }; + const contentURL = post[imgQualityMap[quality]] || fileUrl; // 只有两个视频后缀 const videoExtList = ['mp4', 'webm']; const fileExt = fileUrl.slice(fileUrl.lastIndexOf('.') + 1); // 默认是图片,但是也考虑视频的情况 - let contentHtml = ``; + let contentHtml = ``; if (videoExtList.includes(fileExt)) { contentHtml = ``; } @@ -74,7 +77,7 @@ function generatePostDescription(post, link) { async function handler(ctx: Context) { const tags = (decodeURIComponent(ctx.req.param('tags')) || '').trim(); - const { apiKey = '', userId = '', limit = 40 }: { apiKey?: string; userId?: string; limit?: number } = ctx.req.query(); + const { apiKey = '', userId = '', limit = 40, quality = 'sample' }: { apiKey?: string; userId?: string; limit?: number; quality?: 'sample' | 'orig' } = ctx.req.query(); const response = await got({ url: 'https://gelbooru.com/index.php', @@ -104,7 +107,7 @@ async function handler(ctx: Context) { link: `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, author: post.owner, pubDate: parseDate(post.created_at), - description: generatePostDescription(post, `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`), + description: generatePostDescription(post, `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, quality), upvotes: post.score, updated: parseDate(post.change), media: { From 4eed05a4fafaaa9c4c5d06c3e684f0a78f3b6be8 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Mon, 10 Feb 2025 08:54:14 +0000 Subject: [PATCH 03/12] feat(route): remove URL.canParse --- lib/routes/gelbooru/post.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index 6c0d429f716a0a..ac6bf8b96f2c79 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -46,9 +46,9 @@ e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx&imgQuality=orig\` function generatePostDescription(post, link, quality: 'sample' | 'orig') { const { id, source, owner, file_url: fileUrl, tags, score } = post; - const isURL = URL.canParse(source); - const sourceHtml = isURL ? `Source` : `${source}`; - const sourceHost = isURL ? new URL(source).host : source; + const isHttp = /^https?:\/\//.test(source); + const sourceHtml = isHttp ? `Source` : `${source}`; + const sourceHost = isHttp ? new URL(source).host : source; const postHtml = `#${id}`; const uploadByHtml = `Upload by: ${owner}`; const imgQualityMap = { sample: 'sample_url', orig: 'file_url' }; From 9a9769ef3e26d480c9e41b8b25ed64ab70065078 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Mon, 10 Feb 2025 09:00:44 +0000 Subject: [PATCH 04/12] feat(route): enhance display --- lib/routes/gelbooru/post.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index ac6bf8b96f2c79..371d40878ef63c 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -47,8 +47,8 @@ e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx&imgQuality=orig\` function generatePostDescription(post, link, quality: 'sample' | 'orig') { const { id, source, owner, file_url: fileUrl, tags, score } = post; const isHttp = /^https?:\/\//.test(source); - const sourceHtml = isHttp ? `Source` : `${source}`; - const sourceHost = isHttp ? new URL(source).host : source; + const sourceHtml = isHttp ? `Source` : `Source: ${source || '-'}`; + const sourceHost = isHttp ? new URL(source).host : source || 'unknown'; const postHtml = `#${id}`; const uploadByHtml = `Upload by: ${owner}`; const imgQualityMap = { sample: 'sample_url', orig: 'file_url' }; From aa6d1d11ab2fcec9d861f50598002735f5653ab2 Mon Sep 17 00:00:00 2001 From: undefined <2100709458@qq.com> Date: Sat, 15 Feb 2025 16:37:55 +0800 Subject: [PATCH 05/12] Update lib/routes/gelbooru/namespace.ts Co-authored-by: Tony --- lib/routes/gelbooru/namespace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/gelbooru/namespace.ts b/lib/routes/gelbooru/namespace.ts index 11b2154317f5c6..797b9373612fad 100644 --- a/lib/routes/gelbooru/namespace.ts +++ b/lib/routes/gelbooru/namespace.ts @@ -3,5 +3,5 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'Gelbooru | Free Anime and Hentai Gallery', url: 'gelbooru.com', - description: `gelbooru posts`, + description: 'gelbooru posts', }; From 6e89ae82f463f59b973087b4c0d530211067189e Mon Sep 17 00:00:00 2001 From: undefined <2100709458@qq.com> Date: Sat, 15 Feb 2025 16:38:03 +0800 Subject: [PATCH 06/12] Update lib/routes/gelbooru/namespace.ts Co-authored-by: Tony --- lib/routes/gelbooru/namespace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/gelbooru/namespace.ts b/lib/routes/gelbooru/namespace.ts index 797b9373612fad..fd9f5d0d675192 100644 --- a/lib/routes/gelbooru/namespace.ts +++ b/lib/routes/gelbooru/namespace.ts @@ -1,7 +1,7 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'Gelbooru | Free Anime and Hentai Gallery', + name: 'Gelbooru', url: 'gelbooru.com', description: 'gelbooru posts', }; From 37a6a176cd95da9b83b017668fa217498bb65e35 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Sat, 15 Feb 2025 09:57:08 +0000 Subject: [PATCH 07/12] fix: Apply code review --- lib/config.ts | 4 + lib/routes/gelbooru/post.ts | 74 ++++++++----------- lib/routes/gelbooru/templates/description.art | 19 +++++ lib/routes/gelbooru/utils.ts | 40 ++++++++++ 4 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 lib/routes/gelbooru/templates/description.art create mode 100644 lib/routes/gelbooru/utils.ts diff --git a/lib/config.ts b/lib/config.ts index 2afbce8a7e85fa..598cc5ff3f1cf4 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -827,6 +827,10 @@ const calculateValue = () => { zsxq: { accessToken: envs.ZSXQ_ACCESS_TOKEN, }, + gelbooru: { + apiKey: envs.GELBOORU_API_KEY, + userId: envs.GELBOORU_USER_ID, + }, }; for (const name in _value) { diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index 371d40878ef63c..b867edf2aebda9 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -1,19 +1,35 @@ import { Route, ViewType } from '@/types'; import { Context } from 'hono'; -import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; +import { renderDesc } from './utils'; +import got from '@/utils/got'; import queryString from 'query-string'; export const route: Route = { - path: '/post/:tags?', + path: '/post/:tags?/:quality?', categories: ['picture'], view: ViewType.Pictures, example: '/gelbooru/post/1girl rating:general', parameters: { - tags: `要搜索的标签,多个标签用 \` \`(空格)隔开`, + tags: '要搜索的标签,多个标签用 ` `(空格)隔开', + quality: { + description: '图片质量,可选值为 `sample`(压缩后的图片,推荐值) 或 `orig`(原图),默认为 `sample`', + default: 'sample', + }, }, features: { - requireConfig: false, + requireConfig: [ + { + name: 'GELBOORU_API_KEY', + description: 'Gelbooru 偶尔会开启 API 认证,需配合 `GELBOORU_USER_ID`,从 `https://gelbooru.com/index.php?page=account&s=options` 获取', + optional: true, + }, + { + name: 'GELBOORU_USER_ID', + description: '参见 `GELBOORU_API_KEY`', + optional: true, + }, + ], requirePuppeteer: false, antiCrawler: false, supportRadar: true, @@ -26,58 +42,30 @@ export const route: Route = { source: ['gelbooru.com/index.php'], }, ], - name: 'Gelbooru 标签查询', + name: 'Gelbooru标签查询', maintainers: ['magicFeirl'], description: ` - 默认查询: \`/gelbooru/post\` 功能等同查询 Gelbooru 网站最新的投稿 - 单标签查询: \`/gelbooru/post/1girl\` 查询 \`1girl\` 的最新投稿 - 多标签查询: \`/gelbooru/post/1girl school_uniform rating:general\` +- 指定为原图: \`/gelbooru/post/1girl school_uniform rating:general/orig\` - 更多例子: 请参考 Gelbooru 官方 wiki https://gelbooru.com/index.php?page=wiki&s=&s=view&id=25921 **可选的 URL 参数** -- apiKey & userId: API Access Credentials 如果需要认证,从 https://gelbooru.com/index.php?page=account&s=options 获取 - limit 页面返回数据量,默认 40,可选 1 ~ 100 -- imgQuality \`sample\` or \`orig\` 图片质量,默认为 sample -e.g.: \`/gelbooru/post?limit=20&apiKey=xx&userId=xx&imgQuality=orig\` +e.g.: \`/gelbooru/post?limit=20&\` `, handler, }; -function generatePostDescription(post, link, quality: 'sample' | 'orig') { - const { id, source, owner, file_url: fileUrl, tags, score } = post; - const isHttp = /^https?:\/\//.test(source); - const sourceHtml = isHttp ? `Source` : `Source: ${source || '-'}`; - const sourceHost = isHttp ? new URL(source).host : source || 'unknown'; - const postHtml = `#${id}`; - const uploadByHtml = `Upload by: ${owner}`; - const imgQualityMap = { sample: 'sample_url', orig: 'file_url' }; - const contentURL = post[imgQualityMap[quality]] || fileUrl; - - // 只有两个视频后缀 - const videoExtList = ['mp4', 'webm']; - const fileExt = fileUrl.slice(fileUrl.lastIndexOf('.') + 1); +async function handler(ctx: Context) { + const { tags: _tags = '', quality = 'sample' }: { tags?: string; quality?: 'sample' | 'orig' } = ctx.req.param(); - // 默认是图片,但是也考虑视频的情况 - let contentHtml = ``; - if (videoExtList.includes(fileExt)) { - contentHtml = ``; - } + const tags = decodeURIComponent(_tags).trim(); - return ` -
${contentHtml}
-

-

Info of ${postHtml}:

-

${sourceHtml}(${sourceHost})

-

${uploadByHtml}

-

Score: ${score || '-'}

-

Tags:

${tags}

- `; -} - -async function handler(ctx: Context) { - const tags = (decodeURIComponent(ctx.req.param('tags')) || '').trim(); - const { apiKey = '', userId = '', limit = 40, quality = 'sample' }: { apiKey?: string; userId?: string; limit?: number; quality?: 'sample' | 'orig' } = ctx.req.query(); + const { limit = 40 }: { limit?: number } = ctx.req.query(); + const { apiKey, useId } = getAPIKeys(); const response = await got({ url: 'https://gelbooru.com/index.php', @@ -87,7 +75,7 @@ async function handler(ctx: Context) { q: 'index', tags, api_key: apiKey, - user_id: userId, + user_id: useId, limit: limit <= 0 || limit > 100 ? 40 : limit, json: 1, }), @@ -96,7 +84,7 @@ async function handler(ctx: Context) { const posts = response.data.post; return { - title: tags ? `${tags} - gelbooru.com` : `gelbooru.com post list`, + title: tags ? `${tags} - gelbooru.com` : 'gelbooru.com post list', link: `https://gelbooru.com/index.php?page=post&s=list&tags=${tags}`, icon: 'https://gelbooru.com/favicon.png', logo: 'https://gelbooru.com/favicon.png', @@ -107,7 +95,7 @@ async function handler(ctx: Context) { link: `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, author: post.owner, pubDate: parseDate(post.created_at), - description: generatePostDescription(post, `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, quality), + description: renderDesc(post, `https://gelbooru.com/index.php?page=post&s=view&id=${post.id}`, quality), upvotes: post.score, updated: parseDate(post.change), media: { diff --git a/lib/routes/gelbooru/templates/description.art b/lib/routes/gelbooru/templates/description.art new file mode 100644 index 00000000000000..401fa8eb2a3239 --- /dev/null +++ b/lib/routes/gelbooru/templates/description.art @@ -0,0 +1,19 @@ +
+ {{if isVideo}} + + {{else}} + + {{/if}} +
+

Info of #{{id}}:

+

+ {{if isHttp}} + Source + {{else}} + Source: {{source}} + {{/if}} + ({{sourceHost}}) +

+

Upload by: {{owner}}

+

Score: {{score}}

+

Tags:

{{tags}}

diff --git a/lib/routes/gelbooru/utils.ts b/lib/routes/gelbooru/utils.ts new file mode 100644 index 00000000000000..175c4f51ab27f7 --- /dev/null +++ b/lib/routes/gelbooru/utils.ts @@ -0,0 +1,40 @@ +import path from 'node:path'; +import { art } from '@/utils/render'; +import { config } from '@/config'; + +export function renderDesc(post, link, quality: 'sample' | 'orig') { + const { id, source, owner, file_url: fileUrl, tags, score } = post; + const isHttp = /^https?:\/\//.test(source); + const sourceHost = isHttp ? new URL(source).host : source || 'unknown'; + const imgQualityMap = { sample: 'sample_url', orig: 'file_url' }; + + // 判断是否是视频链接 + const videoExtList = ['mp4', 'webm']; + const fileExt = fileUrl.slice(fileUrl.lastIndexOf('.') + 1); + const isVideo = videoExtList.includes(fileExt); + // 如果是视频则始终使用 fileUrl(原文件) + let contentURL = post[imgQualityMap[quality]] || fileUrl; + if (isVideo) { + contentURL = fileUrl; + } + + return art(path.join(__dirname, 'templates/description.art'), { + id, + source, + owner, + tags, + link, + isHttp, + sourceHost, + contentURL, + isVideo, + score: score || 0, + }); +} + +export function getAPIKeys() { + return { + apiKey: config.gelbooru.apiKey || '', + apiKey: config.gelbooru.userId || '', + }; +} From c2e5748afe0f8e48eedd1921016b17d922a82fab Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Sat, 15 Feb 2025 11:11:17 +0000 Subject: [PATCH 08/12] fix: Apply code review --- lib/routes/gelbooru/post.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index b867edf2aebda9..b6c1258dbc7302 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -1,7 +1,8 @@ import { Route, ViewType } from '@/types'; import { Context } from 'hono'; import { parseDate } from '@/utils/parse-date'; -import { renderDesc } from './utils'; +import { renderDesc, getAPIKeys } from './utils'; + import got from '@/utils/got'; import queryString from 'query-string'; From 101637a43737a71b8a17c86cf0ecdb514fd3b172 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Sat, 15 Feb 2025 11:44:02 +0000 Subject: [PATCH 09/12] fix: add __dirname var --- lib/config.ts | 4 ++++ lib/routes/gelbooru/utils.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/config.ts b/lib/config.ts index 598cc5ff3f1cf4..a9ddad62030554 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -393,6 +393,10 @@ export type Config = { zsxq: { accessToken?: string; }; + gelbooru: { + apiKey?: string; + userId?: string; + }; }; const value: Config | Record = {}; diff --git a/lib/routes/gelbooru/utils.ts b/lib/routes/gelbooru/utils.ts index 175c4f51ab27f7..eb67a61d6089b5 100644 --- a/lib/routes/gelbooru/utils.ts +++ b/lib/routes/gelbooru/utils.ts @@ -1,3 +1,6 @@ +import { getCurrentPath } from '@/utils/helpers'; +const __dirname = getCurrentPath(import.meta.url); + import path from 'node:path'; import { art } from '@/utils/render'; import { config } from '@/config'; @@ -35,6 +38,6 @@ export function renderDesc(post, link, quality: 'sample' | 'orig') { export function getAPIKeys() { return { apiKey: config.gelbooru.apiKey || '', - apiKey: config.gelbooru.userId || '', + userId: config.gelbooru.userId || '', }; } From 7d810b53fa8547cbfa6094ded53c596e138ec9f6 Mon Sep 17 00:00:00 2001 From: undefined <2100709458@qq.com> Date: Sun, 16 Feb 2025 14:28:28 +0800 Subject: [PATCH 10/12] Update lib/routes/gelbooru/templates/description.art Co-authored-by: Tony --- lib/routes/gelbooru/templates/description.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/gelbooru/templates/description.art b/lib/routes/gelbooru/templates/description.art index 401fa8eb2a3239..85ad3a619e704f 100644 --- a/lib/routes/gelbooru/templates/description.art +++ b/lib/routes/gelbooru/templates/description.art @@ -1,6 +1,6 @@
{{if isVideo}} - + {{else}} {{/if}} From 253bf6334ec16f520d52bd68671fe7adb26fc8ad Mon Sep 17 00:00:00 2001 From: undefined <2100709458@qq.com> Date: Sun, 16 Feb 2025 14:28:42 +0800 Subject: [PATCH 11/12] Update lib/routes/gelbooru/post.ts Co-authored-by: Tony --- lib/routes/gelbooru/post.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/gelbooru/post.ts b/lib/routes/gelbooru/post.ts index b6c1258dbc7302..83ddce77a6ed5e 100644 --- a/lib/routes/gelbooru/post.ts +++ b/lib/routes/gelbooru/post.ts @@ -43,7 +43,7 @@ export const route: Route = { source: ['gelbooru.com/index.php'], }, ], - name: 'Gelbooru标签查询', + name: '标签查询', maintainers: ['magicFeirl'], description: ` - 默认查询: \`/gelbooru/post\` 功能等同查询 Gelbooru 网站最新的投稿 From 915dfcea9eb442321d3c87ebd8c939db98d19154 Mon Sep 17 00:00:00 2001 From: undefined <33629016+magicFeirl@users.noreply.github.com> Date: Sun, 16 Feb 2025 06:32:32 +0000 Subject: [PATCH 12/12] fix: Add config key by alphabetical order --- lib/config.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index a9ddad62030554..f681d37d431f8f 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -176,6 +176,10 @@ export type Config = { guozaoke: { cookies?: string; }; + gelbooru: { + apiKey?: string; + userId?: string; + }; hefeng: { key?: string; }; @@ -393,10 +397,6 @@ export type Config = { zsxq: { accessToken?: string; }; - gelbooru: { - apiKey?: string; - userId?: string; - }; }; const value: Config | Record = {}; @@ -613,6 +613,10 @@ const calculateValue = () => { guozaoke: { cookies: envs.GUOZAOKE_COOKIES, }, + gelbooru: { + apiKey: envs.GELBOORU_API_KEY, + userId: envs.GELBOORU_USER_ID, + }, hefeng: { // weather key: envs.HEFENG_KEY, @@ -831,10 +835,6 @@ const calculateValue = () => { zsxq: { accessToken: envs.ZSXQ_ACCESS_TOKEN, }, - gelbooru: { - apiKey: envs.GELBOORU_API_KEY, - userId: envs.GELBOORU_USER_ID, - }, }; for (const name in _value) {