Skip to content

Commit

Permalink
feat: follow config
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Dec 18, 2024
1 parent 4bec9ed commit 2aab504
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/api/follow/config.ts
Original file line number Diff line number Diff line change
@@ -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<typeof route> = (ctx) =>
ctx.json({
ownerUserId: config.follow.ownerUserId,
description: config.follow.description,
price: config.follow.price,
});

export { route, handler };
2 changes: 2 additions & 0 deletions lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
Expand Down
12 changes: 11 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export type Config = {
promptTitle: string;
promptDescription: string;
};
follow: {
ownerUserId?: string;
description?: string;
price?: number;
};

// Route-specific Configurations
bilibili: {
Expand Down Expand Up @@ -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<string, string | undefined> = {};
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 2aab504

Please sign in to comment.