v6:HWPX 템플릿 분석·저장·관리_20260128
This commit is contained in:
65
app.py
65
app.py
@@ -9,6 +9,8 @@ import io
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, request, jsonify, Response, session, send_file
|
||||
from handlers.template import TemplateProcessor
|
||||
|
||||
|
||||
# 문서 유형별 프로세서
|
||||
from handlers.briefing import BriefingProcessor
|
||||
@@ -18,13 +20,15 @@ app = Flask(__name__)
|
||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'geulbeot-light-secret-key-v2')
|
||||
|
||||
# 프로세서 인스턴스
|
||||
# processors 딕셔너리에 추가
|
||||
processors = {
|
||||
'briefing': BriefingProcessor(),
|
||||
'report': ReportProcessor()
|
||||
'report': ReportProcessor(),
|
||||
'template': TemplateProcessor() # 추가
|
||||
}
|
||||
|
||||
|
||||
|
||||
# ============== 메인 페이지 ==============
|
||||
|
||||
@app.route('/')
|
||||
@@ -75,7 +79,8 @@ def generate_report():
|
||||
'cover': data.get('cover', False),
|
||||
'toc': data.get('toc', False),
|
||||
'divider': data.get('divider', False),
|
||||
'instruction': data.get('instruction', '')
|
||||
'instruction': data.get('instruction', ''),
|
||||
'template_id': data.get('template_id')
|
||||
}
|
||||
|
||||
result = processors['report'].generate(content, options)
|
||||
@@ -290,7 +295,59 @@ def analyze_styles():
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return jsonify({'error': str(e), 'trace': traceback.format_exc()}), 500
|
||||
|
||||
|
||||
@app.route('/templates', methods=['GET'])
|
||||
def get_templates():
|
||||
"""저장된 템플릿 목록 조회"""
|
||||
try:
|
||||
result = processors['template'].get_list()
|
||||
return jsonify(result)
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/analyze-template', methods=['POST'])
|
||||
def analyze_template():
|
||||
"""템플릿 분석 및 저장"""
|
||||
try:
|
||||
if 'file' not in request.files:
|
||||
return jsonify({'error': '파일이 없습니다'}), 400
|
||||
|
||||
file = request.files['file']
|
||||
name = request.form.get('name', '').strip()
|
||||
|
||||
if not name:
|
||||
return jsonify({'error': '템플릿 이름을 입력해주세요'}), 400
|
||||
|
||||
if not file.filename:
|
||||
return jsonify({'error': '파일을 선택해주세요'}), 400
|
||||
|
||||
result = processors['template'].analyze(file, name)
|
||||
|
||||
if 'error' in result:
|
||||
return jsonify(result), 400
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return jsonify({'error': str(e), 'trace': traceback.format_exc()}), 500
|
||||
|
||||
|
||||
@app.route('/delete-template/<template_id>', methods=['DELETE'])
|
||||
def delete_template(template_id):
|
||||
"""템플릿 삭제"""
|
||||
try:
|
||||
result = processors['template'].delete(template_id)
|
||||
|
||||
if 'error' in result:
|
||||
return jsonify(result), 400
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
|
||||
Reference in New Issue
Block a user