Skip to content

Commit 12439b1

Browse files
committed
add log size limit
1 parent 736bd2c commit 12439b1

5 files changed

Lines changed: 28 additions & 47 deletions

File tree

backend/src/module/conf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from .config import VERSION, get_plugin_config, settings
55
from .log import LOG_PATH, setup_logger
66
from .search_provider import SEARCH_CONFIG
7+
from .tmdb import TMDB_API_KEY
78

89
PLATFORM = sys.platform
9-
TMDB_API = "291237f90b24267380d6176c98f7619f"
1010
DATA_PATH = "sqlite:///data/data.db"
1111
LEGACY_DATA_PATH = Path("data/data.json")
1212
VERSION_PATH = Path("config/version.info")
@@ -15,7 +15,7 @@
1515

1616
__all__ = [
1717
"VERSION",
18-
"TMDB_API",
18+
"TMDB_API_KEY",
1919
"DATA_PATH",
2020
"LEGACY_DATA_PATH",
2121
"VERSION_PATH",

backend/src/module/conf/log.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from logging import NullHandler
2+
from logging.handlers import RotatingFileHandler
33
from pathlib import Path
44

55
from .config import settings
@@ -38,7 +38,12 @@ def setup_logger(level: int = logging.INFO, reset: bool = False):
3838
datefmt=TIME_FORMAT,
3939
encoding="utf-8",
4040
handlers=[
41-
logging.FileHandler(LOG_PATH, encoding="utf-8"),
41+
RotatingFileHandler(
42+
LOG_PATH,
43+
maxBytes=10*1024*1024, # 10MB
44+
backupCount=5,
45+
encoding="utf-8"
46+
),
4247
logging.StreamHandler(),
4348
],
4449
force=reset, # 强制重新配置如果是重置模式

backend/src/module/conf/tmdb.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
"""TMDB API configuration and constants."""
22

3-
from . import TMDB_API
3+
from .config import settings
4+
45

56
TMDB_URL = "https://api.themoviedb.org"
67
TMDB_IMG_URL = "https://image.tmdb.org/t/p/w780"
78

9+
# Default TMDB API key, replace with your own key if needed
10+
# Note: Using a public key is not recommended for production use.
11+
# It is better to set your own key in the configuration.
12+
TMDB_API_KEY = "291237f90b24267380d6176c98f7619f"
13+
814
LANGUAGE = {"zh": "zh-CN", "jp": "ja-JP", "en": "en-US"}
915

16+
def get_api_key():
17+
"""Get the TMDB API key from settings."""
18+
return settings.rss_parser.tmdb_api_key or TMDB_API_KEY
19+
1020

1121
def search_url(keyword: str) -> str:
1222
"""Generate TMDB search URL for TV shows."""
13-
return f"{TMDB_URL}/3/search/tv?api_key={TMDB_API}&page=1&query={keyword}&include_adult=false"
23+
return f"{TMDB_URL}/3/search/tv?api_key={get_api_key()}&page=1&query={keyword}&include_adult=false"
1424

1525

1626
def info_url(show_id: str, language: str) -> str:
1727
"""Generate TMDB info URL for a specific TV show."""
18-
return f"{TMDB_URL}/3/tv/{show_id}?api_key={TMDB_API}&language={LANGUAGE[language]}"
28+
return f"{TMDB_URL}/3/tv/{show_id}?api_key={get_api_key()}&language={LANGUAGE[language]}"

backend/src/module/conf/uvicorn_logging.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

backend/src/module/models/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def validate_rename_time(cls, v: int) -> int:
2727
class Downloader(BaseModel):
2828
type: str = Field(default="qbittorrent", description="Downloader type")
2929
path: str = Field(default="/downloads/Bangumi", description="Downloader path")
30-
host: str = Field("172.17.0.1:8080", alias="host", description="Downloader host")
31-
ssl: bool = Field(False, description="Downloader ssl")
30+
host: str = Field(default="172.17.0.1:8080", alias="host", description="Downloader host")
31+
ssl: bool = Field(default=False, description="Downloader ssl")
3232

3333
class Config:
3434
extra: str = "allow" # This allows extra fields not defined in the model
@@ -82,6 +82,10 @@ class RSSParser(BaseModel):
8282
include: list[str] = Field(default=[], description="Include")
8383
language: str = "zh"
8484
mikan_custom_url: str = Field(default="mikanani.me", description="Mikan custom url")
85+
tmdb_api_key: str = Field(
86+
default="",
87+
description="TMDB API key, used for TMDB integration",
88+
)
8589

8690

8791
class BangumiManage(BaseModel):

0 commit comments

Comments
 (0)