mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-25 02:50:27 +08:00
Fix log bug
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import multiprocessing
|
||||
import logging
|
||||
import multiprocessing
|
||||
|
||||
from module import app
|
||||
from module import api
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
@@ -1,77 +1,83 @@
|
||||
import uvicorn
|
||||
from uvicorn.config import LOGGING_CONFIG
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import HTMLResponse, FileResponse
|
||||
from fastapi.responses import HTMLResponse, FileResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import logging
|
||||
|
||||
from module.core import APIProcess
|
||||
from module.conf import settings, DATA_PATH, LOG_PATH
|
||||
from module.conf import settings, DATA_PATH, LOG_PATH, VERSION
|
||||
from module.utils import json_config
|
||||
from module.models.api import *
|
||||
from module.models import Config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI()
|
||||
router = FastAPI()
|
||||
api_func = APIProcess()
|
||||
|
||||
app.mount("/assets", StaticFiles(directory="templates/assets"), name="assets")
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
if VERSION != "DEV_VERSION":
|
||||
router.mount("/assets", StaticFiles(directory="templates/assets"), name="assets")
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@app.get("/api/v1/data")
|
||||
|
||||
@router.get("/api/v1/data")
|
||||
def get_data():
|
||||
data = json_config.load(DATA_PATH)
|
||||
return data
|
||||
|
||||
|
||||
@app.get("/api/v1/log")
|
||||
@router.get("/api/v1/log")
|
||||
async def get_log():
|
||||
return FileResponse(LOG_PATH)
|
||||
|
||||
|
||||
@app.get("/api/v1/resetRule")
|
||||
@router.get("/api/v1/resetRule")
|
||||
def reset_rule():
|
||||
return api_func.reset_rule()
|
||||
|
||||
|
||||
@app.get("api/v1/removeRule/{bangumi_title}")
|
||||
@router.get("api/v1/removeRule/{bangumi_title}")
|
||||
def remove_rule(bangumi_title: str):
|
||||
return api_func.remove_rule(bangumi_title)
|
||||
|
||||
|
||||
@app.post("/api/v1/collection")
|
||||
@router.post("/api/v1/collection")
|
||||
async def collection(link: RssLink):
|
||||
return api_func.download_collection(link.rss_link)
|
||||
|
||||
|
||||
@app.post("/api/v1/subscribe")
|
||||
@router.post("/api/v1/subscribe")
|
||||
async def subscribe(link: RssLink):
|
||||
return api_func.add_subscribe(link.rss_link)
|
||||
|
||||
|
||||
@app.post("/api/v1/addRule")
|
||||
@router.post("/api/v1/addRule")
|
||||
async def add_rule(info: AddRule):
|
||||
return api_func.add_rule(info.title, info.season)
|
||||
|
||||
|
||||
@app.post("/api/v1/updateConfig", tags=["config"])
|
||||
@router.post("/api/v1/updateConfig", tags=["config"])
|
||||
async def update_config(config: Config):
|
||||
return api_func.update_config(config)
|
||||
|
||||
|
||||
if VERSION != "DEV_VERSION":
|
||||
# HTML Response
|
||||
@app.get("/{full_path:path}", response_class=HTMLResponse)
|
||||
def index(request: Request):
|
||||
context = {"request": request}
|
||||
return templates.TemplateResponse("index.html", context)
|
||||
@router.get("/{full_path:path}", response_class=HTMLResponse)
|
||||
def index(request: Request):
|
||||
context = {"request": request}
|
||||
return templates.TemplateResponse("index.html", context)
|
||||
else:
|
||||
@router.get("/", status_code=302)
|
||||
def index():
|
||||
return RedirectResponse("/docs")
|
||||
|
||||
|
||||
def run():
|
||||
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelprefix)s %(message)s"
|
||||
uvicorn.run(app, host="0.0.0.0", port=settings.program.webui_port)
|
||||
uvicorn.run(router, host="0.0.0.0", port=settings.program.webui_port)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import time
|
||||
import logging
|
||||
|
||||
from module.conf import settings, LOG_PATH, DATA_PATH, RSS_LINK
|
||||
from module.conf import settings, setup_logger, LOG_PATH, DATA_PATH, RSS_LINK
|
||||
from module.utils import json_config
|
||||
|
||||
from module.core import DownloadClient
|
||||
@@ -22,7 +22,7 @@ def load_data_file():
|
||||
if not os.path.exists(DATA_PATH):
|
||||
bangumi_data = {
|
||||
"rss_link": RSS_LINK,
|
||||
"data_version": settings.program.data_version,
|
||||
"data_version": settings.data_version,
|
||||
"bangumi_info": []
|
||||
}
|
||||
logger.info("Building data information...")
|
||||
@@ -62,6 +62,7 @@ def main_process(bangumi_data, download_client: DownloadClient):
|
||||
|
||||
|
||||
def run():
|
||||
setup_logger()
|
||||
# 初始化
|
||||
reset_log()
|
||||
download_client = DownloadClient()
|
||||
|
||||
@@ -76,9 +76,3 @@ class APIProcess:
|
||||
def update_config(config: Config):
|
||||
save_config_to_file(config, CONFIG_PATH)
|
||||
return {"message": "Success"}
|
||||
|
||||
def restart_main_process(self, mp):
|
||||
os.kill(mp.pid, signal.SIGTERM)
|
||||
global main_process
|
||||
main_process = multiprocessing.Process(target=main_program)
|
||||
main_process.start()
|
||||
|
||||
Reference in New Issue
Block a user