fix: 将app设为包

This commit is contained in:
DLmaster361
2025-08-07 14:32:39 +08:00
parent 8cbd542a75
commit 7941f5cafd
14 changed files with 57 additions and 26 deletions

33
app/__init__.py Normal file
View File

@@ -0,0 +1,33 @@
# AUTO_MAA:A MAA Multi Account Management and Automation Tool
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 MoeSnowyFox
# This file is part of AUTO_MAA.
# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.
# Contact: DLmaster_361@163.com
__version__ = "5.0.0"
__author__ = "DLmaster361 <DLmaster_361@163.com>"
__license__ = "GPL-3.0 license"
from .api import *
from .core import *
from .models import *
from .services import *
from .utils import *
__all__ = ["api", "core", "models", "services", "utils"]

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/dispatch", tags=["任务调度"])

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/info", tags=["信息获取"])

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/plan", tags=["计划管理"])

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/queue", tags=["调度队列管理"])

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/scripts", tags=["脚本管理"])

View File

@@ -22,8 +22,8 @@
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
from app.core import Config
from app.models.schema import *
router = APIRouter(prefix="/api/setting", tags=["全局设置"])

View File

@@ -35,8 +35,8 @@ from pathlib import Path
from typing import Union, Dict, List, Literal, Optional, Any, Tuple, Callable, TypeVar
from utils import get_logger
from models.ConfigBase import *
from app.utils import get_logger
from app.models.ConfigBase import *
logger = get_logger("配置管理")

View File

@@ -22,7 +22,7 @@ import asyncio
import keyboard
from datetime import datetime
from utils import get_logger
from app.utils import get_logger
from .config import Config

View File

@@ -1,111 +0,0 @@
# AUTO_MAA:A MAA Multi Account Management and Automation Tool
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 MoeSnowyFox
# This file is part of AUTO_MAA.
# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.
# Contact: DLmaster_361@163.com
import os
import sys
import ctypes
from utils import get_logger
logger = get_logger("主程序")
def is_admin() -> bool:
"""检查当前程序是否以管理员身份运行"""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
# @logger.catch
def main():
if is_admin():
import asyncio
import uvicorn
from fastapi import FastAPI
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
from core import Config, MainTimer
await Config.init_config()
main_timer = asyncio.create_task(MainTimer.second_task())
yield
main_timer.cancel()
try:
await main_timer
except asyncio.CancelledError:
logger.info("主业务定时器已关闭")
logger.info("AUTO_MAA 后端程序关闭")
logger.info("----------------END----------------")
from fastapi.middleware.cors import CORSMiddleware
from api import (
info_router,
scripts_router,
plan_router,
queue_router,
setting_router,
)
app = FastAPI(
title="AUTO_MAA",
description="API for managing automation scripts, plans, and tasks",
version="1.0.0",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 允许所有域名跨域访问
allow_credentials=True,
allow_methods=["*"], # 允许所有请求方法,如 GET、POST、PUT、DELETE
allow_headers=["*"], # 允许所有请求头
)
app.include_router(info_router)
app.include_router(scripts_router)
app.include_router(plan_router)
app.include_router(queue_router)
app.include_router(setting_router)
uvicorn.run(app, host="0.0.0.0", port=8000)
else:
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, os.path.realpath(sys.argv[0]), None, 1
)
sys.exit(0)
if __name__ == "__main__":
main()

View File

@@ -28,7 +28,7 @@ from pathlib import Path
from typing import List, Any, Dict, Union
from utils import dpapi_encrypt, dpapi_decrypt
from app.utils import dpapi_encrypt, dpapi_decrypt
class ConfigValidator:

View File

@@ -30,8 +30,6 @@ __author__ = "DLmaster361 <DLmaster_361@163.com>"
__license__ = "GPL-3.0 license"
from .notification import Notify
from ..utils.security import Crypto
from .system import System
from ..task.skland import skland_sign_in
__all__ = ["Notify", "Crypto", "System", "skland_sign_in"]
__all__ = ["Notify", "System"]

View File

@@ -30,8 +30,8 @@ from pathlib import Path
from plyer import notification
from core import Config
from utils import get_logger, ImageUtils
from app.core import Config
from app.utils import get_logger, ImageUtils
logger = get_logger("通知服务")

View File

@@ -30,8 +30,8 @@ import getpass
from datetime import datetime
from pathlib import Path
from core import Config
from utils.logger import get_logger
from app.core import Config
from app.utils.logger import get_logger
logger = get_logger("系统服务")