From 2e7cee0b843567eb873e4c06807282118d36d552 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Tue, 14 Oct 2025 21:37:06 +0900 Subject: [PATCH] =?UTF-8?q?docs:=201-2=EB=8B=A8=EA=B3=84=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EC=84=B8=EB=B6=80=EC=82=AC=ED=95=AD=20=EB=B3=B4?= =?UTF-8?q?=EC=B6=A9=20(DB=20=EC=A0=91=EA=B7=BC,=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=A7=81,=20import)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../251014_slack_lists_file_attachment.md | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/troubleshooting/251014_slack_lists_file_attachment.md b/troubleshooting/251014_slack_lists_file_attachment.md index 783c290..373831e 100644 --- a/troubleshooting/251014_slack_lists_file_attachment.md +++ b/troubleshooting/251014_slack_lists_file_attachment.md @@ -24,25 +24,30 @@ coldmail_briefing.py:207에서 document_id를 attachment에 전달하지만, Sla ### 1단계: skill-rag-file 다운로드 API 추가 **파일**: skill-rag-file/app/api/download.py (신규) -**참고**: upload.py:80-87 (storage_path 생성 로직) -**구현**: -- `@router.get("/download/{document_id}")`: UUID로 문서 조회 -- DB에서 TeamDocument.storage_path 가져오기 (upload.py:108 참고) -- `FileResponse(storage_path, media_type="application/pdf")` 반환 -**등록**: skill-rag-file/app/main.py:55 이후 추가 +**import**: upload.py:1, 10, 12 참고 (FastAPI, get_db, TeamDocument) +**router**: `@router.get("/download/{document_id}")` +**DB 조회**: upload.py:60-65 패턴 사용 +- `select(TeamDocument).where(TeamDocument.id == document_id)` +- `db.execute(stmt)`, `result.scalar_one_or_none()` +- 없으면 HTTPException(404) +**반환**: `FileResponse(document.storage_path, media_type="application/pdf")` +**등록**: skill-rag-file/app/main.py:55 이후 +- `from app.api import upload, search, download` - `app.include_router(download.router, prefix="/api", tags=["download"])` ### 2단계: skill-slack 파일 업로드 API 추가 **파일**: skill-slack/app/api/endpoints/files.py (신규) -**참고**: lists.py:47-82 (엔드포인트 구조), slack_lists_service (서비스 패턴) -**구현**: -- `@router.post("/files/upload", dependencies=[Depends(verify_api_key)])`: UploadFile 받기 -- 파라미터: file (UploadFile), title (str), token (Optional[str]) -- WebClient(token).files_upload_v2(file=file.file, title=title) 호출 -- 반환: `{"file_id": str, "url_private": str}` -**등록**: skill-slack/app/api/__init__.py 수정 -- 4번 줄: `from .endpoints import summary, digest, actions, messages, lists, files` -- 13번 줄 이후: `router.include_router(files.router, tags=["Files"])` +**import**: lists.py:4-9 참고 (FastAPI, settings, verify_api_key) +- `from slack_sdk import WebClient` (test_lists_with_file.py:4) +**router**: `@router.post("/files/upload", dependencies=[Depends(verify_api_key)])` +**파라미터**: file (UploadFile), title (str), token (Optional[str]) +**업로드**: test_lists_with_file.py:18, 21-24 패턴 +- `client = WebClient(token or settings.SLACK_BOT_TOKEN)` +- 임시 파일 저장 → `client.files_upload_v2(file=temp_path, title=title)` +- 업로드 후 임시 파일 삭제 +**반환**: `{"file_id": result["file"]["id"], "url_private": result["file"]["url_private"]}` +**에러**: HTTPException(400 or 500) +**등록**: skill-slack/app/api/__init__.py:4, 13 수정 ### 3단계: coldmail_briefing.py 통합