commit b896ed6644c86233b234f497a67c6ef12ddba232 Author: 观炎 <849989428@qq.com> Date: Wed Jan 21 22:15:12 2026 +0800 feat(all): init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..323f73e --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +.venv +__pycache__ +*.pyc +test +*.log +dist +build +*.egg-info +.env + +# IDE specific files +.vscode/ +.idea/ +*.iml +.pytest_cache/ +.coverage +coverage.xml +.tox/ diff --git a/addons/__init__.py b/addons/__init__.py new file mode 100644 index 0000000..871c474 --- /dev/null +++ b/addons/__init__.py @@ -0,0 +1,17 @@ +import os +from flask import Flask +from importlib import import_module + +""" +自动载入所有插件,并注入应用上下文 +通过插件内的 manifest 信息识别是否为内置插件,第三方插件需要自行上传到此目录下 +manifest 需注释为第三方,否则会在比对数据库后直接过滤 +""" +def autoload_addon_and_inject_context(app: Flask): + addons_dir = os.path.dirname(__file__) + for item in os.listdir(addons_dir): + item_path = os.path.join(addons_dir, item) + if os.path.isdir(item_path) and os.path.exists(os.path.join(item_path, '__init__.py')): + addon_module = import_module(f'addons.{item}') + if hasattr(addon_module, 'register_addon'): + addon_module.register_addon(app) \ No newline at end of file diff --git a/addons/account/__init__.py b/addons/account/__init__.py new file mode 100644 index 0000000..98ada07 --- /dev/null +++ b/addons/account/__init__.py @@ -0,0 +1,16 @@ +from flask import Flask + +manifest = { + "name": "Account Addon", + "version": "1.0.0", + "description": "An addon to manage user accounts.", + "author": "Mike", + "license": "", + "url": "", + "addon": "account" +} + +def register_addon(app: Flask): + from .api import bp + app.register_blueprint(bp, url_prefix='/account') + pass \ No newline at end of file diff --git a/addons/account/api.py b/addons/account/api.py new file mode 100644 index 0000000..71f028f --- /dev/null +++ b/addons/account/api.py @@ -0,0 +1,11 @@ +from flask import Blueprint + +bp = Blueprint('account', __name__) + +@bp.route('/') +def account_home(): + return "Welcome to the Account Addon!" + +@bp.route('/profile') +def profile(): + return "This is the user profile page." \ No newline at end of file diff --git a/addons/account/model.py b/addons/account/model.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0ca71c4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +alembic==1.16.5 +blinker==1.9.0 +click==8.1.8 +Flask==3.1.2 +Flask-Migrate==4.1.0 +Flask-SQLAlchemy==3.1.1 +importlib_metadata==8.7.1 +itsdangerous==2.2.0 +Jinja2==3.1.6 +Mako==1.3.10 +MarkupSafe==3.0.3 +SQLAlchemy==2.0.45 +tomli==2.4.0 +typing_extensions==4.15.0 +Werkzeug==3.1.5 +zipp==3.23.0 diff --git a/visitor/__init__.py b/visitor/__init__.py new file mode 100644 index 0000000..497be77 --- /dev/null +++ b/visitor/__init__.py @@ -0,0 +1,11 @@ +from flask import Flask, Config +from addons import autoload_addon_and_inject_context + +def create_app(config: Config = None) -> Flask: + app = Flask(__name__) + app.config.from_object(config) + + # app.logger.info(autoload_addon_and_inject_context()) + autoload_addon_and_inject_context(app) + + return app \ No newline at end of file