Skip to content

Commit ccdda1a

Browse files
authored
Merge pull request #20 from KKU-NoteFlow/feat/1st_presentation
1st presentation
2 parents 3e71007 + 89d5c2c commit ccdda1a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ sentencepiece
2020
protobuf
2121
python-multipart
2222
easyocr
23+
whisper

routers/file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ~/noteflow/Backend/routers/file.py
21
import os
32
import io
43
import whisper
@@ -18,6 +17,9 @@
1817
from models.note import Note as NoteModel
1918
from utils.jwt_utils import get_current_user
2019

20+
# 추가: 파일명 인코딩용
21+
import urllib.parse
22+
2123
# -------------------------------
2224
# 1) EasyOCR 라이브러리 임포트 (GPU 모드 활성화)
2325
# -------------------------------
@@ -54,7 +56,6 @@
5456
trust_remote_code=True
5557
)
5658

57-
# 업로드 디렉토리 설정
5859
BASE_UPLOAD_DIR = os.path.join(
5960
os.path.dirname(os.path.abspath(__file__)),
6061
"..",
@@ -79,11 +80,9 @@ async def upload_file(
7980
orig_filename: str = upload_file.filename or "unnamed"
8081
content_type: str = upload_file.content_type or "application/octet-stream"
8182

82-
# 사용자별 디렉토리 생성
8383
user_dir = os.path.join(BASE_UPLOAD_DIR, str(current_user.u_id))
8484
os.makedirs(user_dir, exist_ok=True)
8585

86-
# 원본 파일명 그대로 저장 (동명이인 방지)
8786
saved_filename = orig_filename
8887
saved_path = os.path.join(user_dir, saved_filename)
8988
if os.path.exists(saved_path):
@@ -98,15 +97,13 @@ async def upload_file(
9897
break
9998
counter += 1
10099

101-
# 파일 저장
102100
try:
103101
with open(saved_path, "wb") as buffer:
104102
content = await upload_file.read()
105103
buffer.write(content)
106104
except Exception as e:
107105
raise HTTPException(status_code=500, detail=f"파일 저장 실패: {e}")
108106

109-
# DB에 메타데이터 기록
110107
new_file = FileModel(
111108
user_id=current_user.u_id,
112109
folder_id=folder_id,
@@ -176,6 +173,9 @@ def download_file(
176173
if not os.path.exists(file_path):
177174
raise HTTPException(status_code=404, detail="서버에 파일이 존재하지 않습니다.")
178175

176+
# 원본 파일명 UTF-8 URL 인코딩 처리
177+
quoted_name = urllib.parse.quote(file_obj.original_name, safe='')
178+
content_disposition = f"inline; filename*=UTF-8''{quoted_name}"
179179
# original_name 을 percent-encoding 해서 ASCII 만으로 헤더 구성
180180
filename_quoted = quote(file_obj.original_name)
181181
content_disposition = f"inline; filename*=UTF-8''{filename_quoted}"

0 commit comments

Comments
 (0)