1234567891011121314151617181920212223242526272829303132333435 |
- import os
- from flask import Flask, jsonify
- from watermark_generate.controller.function_test import test
- from watermark_generate.controller.watermark_generate_controller import generator
- from watermark_generate.exceptions import BusinessException
- def create_app():
- app = Flask(__name__)
- # 设置上传目录
- UPLOAD_FOLDER = './data/uploads'
- EXTRACT_FOLDER = './data/extract'
- # 确保目录存在
- os.makedirs(UPLOAD_FOLDER, exist_ok=True)
- os.makedirs(EXTRACT_FOLDER, exist_ok=True)
- # 配置 Flask
- app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
- app.config['EXTRACT_FOLDER'] = EXTRACT_FOLDER
- # 注册蓝图
- app.register_blueprint(generator)
- app.register_blueprint(test)
- @app.errorhandler(BusinessException)
- def handle_business_exception(ex):
- """处理业务异常,返回JSON提示"""
- return jsonify({"message": ex.message, 'code': ex.code}), 500
- return app
|