Skip to content

Commit 7b89bef

Browse files
committed
feat: 支持配置 JKit 简书数据源 Endpoint
1 parent b34f352 commit 7b89bef

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

backend/api/v1/articles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Annotated
66

77
from jkit.article import Article
8+
from jkit.config import CONFIG as JKIT_CONFIG
89
from jkit.constants import ARTICLE_SLUG_REGEX
910
from jkit.exceptions import ResourceUnavailableError
1011
from litestar import Response, Router, get
@@ -27,6 +28,9 @@
2728
)
2829
from utils.config import CONFIG
2930

31+
if CONFIG.jianshu_endpoint:
32+
JKIT_CONFIG.datasources.jianshu.endpoint = CONFIG.jianshu_endpoint
33+
3034
splitter = WordSplitter(
3135
access_key_id=CONFIG.word_split_access_key.access_key_id,
3236
access_key_secret=CONFIG.word_split_access_key.access_key_secret,

backend/api/v1/users.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44
from typing import Annotated, Literal
55

6+
from jkit.config import CONFIG as JKIT_CONFIG
67
from jkit.constants import USER_SLUG_REGEX
78
from jkit.exceptions import ResourceUnavailableError
89
from jkit.identifier_check import is_user_slug
@@ -25,6 +26,10 @@
2526
)
2627
from models.jianshu.lottery_win_record import LotteryWinRecord
2728
from models.jianshu.user import User as DbUser
29+
from utils.config import CONFIG
30+
31+
if CONFIG.jianshu_endpoint:
32+
JKIT_CONFIG.datasources.jianshu.endpoint = CONFIG.jianshu_endpoint
2833

2934
MembershipTextType = Literal[
3035
"铜牌", "银牌", "金牌", "白金", "(旧版)普通会员", "(旧版)尊享会员"

backend/config.example.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
jianshu_endpoint = ""
2+
13
[jtools_postgres]
24
host = "localhost"
35
port = 5432

backend/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class CustomOpenAPIController(OpenAPIController):
4949
)
5050

5151
if __name__ == "__main__":
52+
# TODO: 集中管理 JKit 简书数据源 Endpoint 配置
53+
if CONFIG.jianshu_endpoint:
54+
logger.debug("已成功配置 JKit 简书数据源 Endpoint")
55+
else:
56+
logger.warn("未配置 JKit 简书数据源 Endpoint,可能出现限流错误")
57+
5258
logger.info("启动 API 服务")
5359
uvicorn_run(
5460
app="main:app",

backend/utils/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
class _Config(ConfigBase, frozen=True):
11+
jianshu_endpoint: str
1112
jtools_postgres: PostgresBlock
1213
jianshu_postgres: PostgresBlock
1314
jpep_postgres: PostgresBlock

0 commit comments

Comments
 (0)