diff --git a/lib/api/follow/config.ts b/lib/api/follow/config.ts new file mode 100644 index 00000000000000..1eef74e5ab2e73 --- /dev/null +++ b/lib/api/follow/config.ts @@ -0,0 +1,22 @@ +import { config } from '@/config'; +import { createRoute, RouteHandler } from '@hono/zod-openapi'; + +const route = createRoute({ + method: 'get', + path: '/follow/config', + tags: ['Follow'], + responses: { + 200: { + description: 'Follow config', + }, + }, +}); + +const handler: RouteHandler = (ctx) => + ctx.json({ + ownerUserId: config.follow.ownerUserId, + description: config.follow.description, + price: config.follow.price, + }); + +export { route, handler }; diff --git a/lib/api/index.ts b/lib/api/index.ts index 71b8d0c75dd152..064852019b7244 100644 --- a/lib/api/index.ts +++ b/lib/api/index.ts @@ -4,6 +4,7 @@ import { route as namespaceOneRoute, handler as namespaceOneHandler } from '@/ap import { route as radarRulesAllRoute, handler as radarRulesAllHandler } from '@/api/radar/rules/all'; import { route as radarRulesOneRoute, handler as radarRulesOneHandler } from '@/api/radar/rules/one'; import { route as categoryOneRoute, handler as categoryOneHandler } from '@/api/category/one'; +import { route as followConfigRoute, handler as followConfigHandler } from '@/api/follow/config'; import { OpenAPIHono } from '@hono/zod-openapi'; import { apiReference } from '@scalar/hono-api-reference'; @@ -14,6 +15,7 @@ app.openapi(namespaceOneRoute, namespaceOneHandler); app.openapi(radarRulesAllRoute, radarRulesAllHandler); app.openapi(radarRulesOneRoute, radarRulesOneHandler); app.openapi(categoryOneRoute, categoryOneHandler); +app.openapi(followConfigRoute, followConfigHandler); const docs = app.getOpenAPI31Document({ openapi: '3.1.0', diff --git a/lib/config.ts b/lib/config.ts index 5967249cbe9340..2b8a687e2b6183 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -86,6 +86,11 @@ export type Config = { promptTitle: string; promptDescription: string; }; + follow: { + ownerUserId?: string; + description?: string; + price?: number; + }; // Route-specific Configurations bilibili: { @@ -398,7 +403,7 @@ const toBoolean = (value: string | undefined, defaultValue: boolean) => { } }; -const toInt = (value: string | undefined, defaultValue: number) => (value === undefined ? defaultValue : Number.parseInt(value)); +const toInt = (value: string | undefined, defaultValue?: number) => (value === undefined ? defaultValue : Number.parseInt(value)); const calculateValue = () => { const bilibili_cookies: Record = {}; @@ -510,6 +515,11 @@ const calculateValue = () => { promptDescription: envs.OPENAI_PROMPT || 'Please summarize the following article and reply with markdown format.', promptTitle: envs.OPENAI_PROMPT_TITLE || 'Please translate the following title into Simplified Chinese and reply only translated text.', }, + follow: { + ownerUserId: envs.FOLLOW_OWNER_USER_ID, + description: envs.FOLLOW_DESCRIPTION, + price: toInt(envs.FOLLOW_PRICE), + }, // Route-specific Configurations bilibili: {