From 07f83daa2bf300548a007ffb282715ab0beb4dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B2=BD=EB=AF=BC?= Date: Thu, 19 Mar 2026 14:01:36 +0900 Subject: [PATCH] =?UTF-8?q?Cleanup:=20Deleting=2003.Code/=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=EC=9A=A9/converters/pipeline/router.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../업로드용/converters/pipeline/router.py | 180 ------------------ 1 file changed, 180 deletions(-) delete mode 100644 03.Code/업로드용/converters/pipeline/router.py diff --git a/03.Code/업로드용/converters/pipeline/router.py b/03.Code/업로드용/converters/pipeline/router.py deleted file mode 100644 index e30f755..0000000 --- a/03.Code/업로드용/converters/pipeline/router.py +++ /dev/null @@ -1,180 +0,0 @@ -# -*- coding: utf-8 -*- -from dotenv import load_dotenv -load_dotenv() - -""" -router.py - -기능: -- HTML 입력의 분량을 판단하여 적절한 파이프라인으로 분기 -- 긴 문서 (5000자 이상): RAG 파이프라인 (step3→4→5→6→7→8→9) -- 짧은 문서 (5000자 미만): 직접 생성 (step7→8→9) -""" - -import re -import os -from typing import Dict, Any - -# 분량 판단 기준 -LONG_DOC_THRESHOLD = 5000 # 5000자 이상이면 긴 문서 - -# 이미지 assets 경로 (개발용 고정) - r prefix 필수! -ASSETS_BASE_PATH = os.environ.get("ASSETS_BASE_PATH", "/tmp/assets") - - -def count_characters(html_content: str) -> int: - """HTML 태그 제외한 순수 텍스트 글자 수 계산""" - # HTML 태그 제거 - text_only = re.sub(r'<[^>]+>', '', html_content) - # 공백 정리 - text_only = ' '.join(text_only.split()) - return len(text_only) - - -def is_long_document(html_content: str) -> bool: - """긴 문서 여부 판단""" - char_count = count_characters(html_content) - return char_count >= LONG_DOC_THRESHOLD - -def convert_image_paths(html_content: str) -> str: - """ - HTML 내 이미지 경로를 서버 경로로 변환 - - assets/xxx.png → /assets/xxx.png (Flask 서빙용) - - 절대 경로나 URL은 그대로 유지 - """ - - def replace_src(match): - original_path = match.group(1) - - # 이미 절대 경로이거나 URL이면 그대로 - if original_path.startswith(('http://', 'https://', 'file://', 'D:', 'C:', '/')): - return match.group(0) - - # assets/로 시작하면 /assets/로 변환 (Flask 서빙) - if original_path.startswith('assets/'): - return f'src="/{original_path}"' - - return match.group(0) - - # src="..." 패턴 찾아서 변환 - result = re.sub(r'src="([^"]+)"', replace_src, html_content) - return result - -def run_short_pipeline(html_content: str, options: dict) -> Dict[str, Any]: - """ - 짧은 문서 파이프라인 (5000자 미만) - """ - try: - # 이미지 경로 변환 - processed_html = convert_image_paths(html_content) - - # TODO: step7, step8, step9 연동 - return { - 'success': True, - 'pipeline': 'short', - 'char_count': count_characters(html_content), - 'html': processed_html - } - except Exception as e: - return { - 'success': False, - 'error': str(e), - 'pipeline': 'short' - } - -def inject_template_css(html_content: str, template_css: str) -> str: - """ - HTML에 템플릿 CSS 주입 - - 태그 앞에 추가 - if '' in html_content: - return html_content.replace('', f'{css_block}', 1) - - # 태그 뒤에 새로 추가 - elif '' in html_content: - return html_content.replace('', f'\n', 1) - - # head도 없으면 맨 앞에 추가 - else: - return f'\n{html_content}' - - -def run_long_pipeline(html_content: str, options: dict) -> Dict[str, Any]: - """ - 긴 문서 파이프라인 (5000자 이상) - 이제 실제 step들을 호출함 - """ - try: - processed_html = convert_image_paths(html_content) - - folder_path = options.get('folder_path', '') - write_mode = options.get('write_mode', 'restructure') - - if not folder_path: - # 폴더 없으면 HTML만으로 처리 (기존 로직) - return { - 'success': True, - 'pipeline': 'long', - 'char_count': count_characters(html_content), - 'html': processed_html - } - - # ★ 파이프라인 실행은 /api/generate-toc → /api/generate-report-from-toc 에서 처리 - # router는 여전히 HTML 통과 역할 유지 - return { - 'success': True, - 'pipeline': 'long', - 'char_count': count_characters(html_content), - 'html': processed_html, - 'needs_pipeline': True # ← 프론트에서 분기 판단용 - } - - except Exception as e: - return {'success': False, 'error': str(e), 'pipeline': 'long'} - - -def process_document(content: str, options: dict = None) -> Dict[str, Any]: - """ - 메인 라우터 함수 - - 분량에 따라 적절한 파이프라인으로 분기 - - Args: - content: HTML 문자열 - options: 추가 옵션 (page_option, instruction 등) - - Returns: - {'success': bool, 'html': str, 'pipeline': str, ...} - """ - if options is None: - options = {} - - if not content or not content.strip(): - return { - 'success': False, - 'error': '내용이 비어있습니다.' - } - - char_count = count_characters(content) - - if is_long_document(content): - result = run_long_pipeline(content, options) - else: - result = run_short_pipeline(content, options) - - # 공통 정보 추가 - result['char_count'] = char_count - result['threshold'] = LONG_DOC_THRESHOLD - - # ⭐ 템플릿 CSS 주입 - template_css = options.get('template_css') - if template_css and result.get('success') and result.get('html'): - result['html'] = inject_template_css(result['html'], template_css) - - return result