app.py 943 B

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. from flask import Flask, jsonify
  3. from watermark_generate.controller.function_test import test
  4. from watermark_generate.controller.watermark_generate_controller import generator
  5. from watermark_generate.exceptions import BusinessException
  6. def create_app():
  7. app = Flask(__name__)
  8. # 设置上传目录
  9. UPLOAD_FOLDER = './data/uploads'
  10. EXTRACT_FOLDER = './data/extract'
  11. # 确保目录存在
  12. os.makedirs(UPLOAD_FOLDER, exist_ok=True)
  13. os.makedirs(EXTRACT_FOLDER, exist_ok=True)
  14. # 配置 Flask
  15. app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  16. app.config['EXTRACT_FOLDER'] = EXTRACT_FOLDER
  17. # 注册蓝图
  18. app.register_blueprint(generator)
  19. app.register_blueprint(test)
  20. @app.errorhandler(BusinessException)
  21. def handle_business_exception(ex):
  22. """处理业务异常,返回JSON提示"""
  23. return jsonify({"message": ex.message, 'code': ex.code}), 500
  24. return app