세션 기능 개선

This commit is contained in:
peregr1nus
2025-12-11 12:53:56 +09:00
parent a519c1856b
commit 4db67170f7

20
app.py
View File

@@ -178,6 +178,7 @@ def step5():
output_path = word_processor.generate_document(all_data, cult_name, cult_questions) output_path = word_processor.generate_document(all_data, cult_name, cult_questions)
# 구글 드라이브 업로드 # 구글 드라이브 업로드
upload_success = False
if drive_uploader and app.config['GOOGLE_DRIVE_FOLDER_ID']: if drive_uploader and app.config['GOOGLE_DRIVE_FOLDER_ID']:
upload_filename = f"교리점검표_{all_data['basic_info'].get('name', '무명')}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx" upload_filename = f"교리점검표_{all_data['basic_info'].get('name', '무명')}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx"
logger.info("구글 드라이브 업로드 시도 | file=%s, folder=%s", upload_filename, app.config['GOOGLE_DRIVE_FOLDER_ID']) logger.info("구글 드라이브 업로드 시도 | file=%s, folder=%s", upload_filename, app.config['GOOGLE_DRIVE_FOLDER_ID'])
@@ -188,8 +189,18 @@ def step5():
app.config['GOOGLE_DRIVE_FOLDER_ID'] app.config['GOOGLE_DRIVE_FOLDER_ID']
) )
logger.info("구글 드라이브 업로드 성공 | file_id=%s", file_id) logger.info("구글 드라이브 업로드 성공 | file_id=%s", file_id)
# 업로드 후 로컬 파일 삭제 (선택사항) upload_success = True
# os.remove(output_path) # 업로드 성공 시 로컬 파일 삭제
try:
os.remove(output_path)
logger.info("로컬 파일 삭제 완료 | file=%s", output_path)
except Exception as e:
logger.warning("로컬 파일 삭제 실패: %s", str(e))
# 세션 삭제 (문서 생성 및 업로드 완료)
session.clear()
logger.info("세션 삭제 완료")
return jsonify({ return jsonify({
'success': True, 'success': True,
'message': '제출이 완료되었습니다. 구글 드라이브에 업로드되었습니다.', 'message': '제출이 완료되었습니다. 구글 드라이브에 업로드되었습니다.',
@@ -197,13 +208,16 @@ def step5():
}) })
except Exception as e: except Exception as e:
logger.warning("구글 드라이브 업로드 실패: %s", str(e)) logger.warning("구글 드라이브 업로드 실패: %s", str(e))
# 업로드 실패 시 로컬 파일 경로 반환 # 업로드 실패 시 로컬 파일 유지
# 세션은 유지 (재시도 가능하도록)
return jsonify({ return jsonify({
'success': True, 'success': True,
'message': f'제출이 완료되었습니다. (구글 드라이브 업로드 실패: {str(e)})', 'message': f'제출이 완료되었습니다. (구글 드라이브 업로드 실패: {str(e)})',
'file_path': output_path 'file_path': output_path
}) })
else: else:
# 구글 드라이브 설정이 없는 경우 로컬 파일 유지
# 세션은 유지
return jsonify({ return jsonify({
'success': True, 'success': True,
'message': f'제출이 완료되었습니다. 파일: {output_path}', 'message': f'제출이 완료되었습니다. 파일: {output_path}',