Skip to content

feat: 커스텀 주문 이미지 선업로드와 미사용 업로드 정리 크론 - #575

Merged
chanwoo7 merged 3 commits into
developfrom
feat/order-custom-upload
Nov 18, 2026
Merged

chanwoo7 merged 3 commits into
developfrom
feat/order-custom-upload

Conversation

@chanwoo7

Copy link
Copy Markdown
Member

개요

구매자가 커스텀 이미지를 주문 전에 presign으로 올리는 발급 API와, 주문에 쓰이지 않은 업로드를 지우는 정리 크론을 더합니다.

  • 구매자는 3D 렌더·슬롯형 합성·자유 편집 참고 사진을 먼저 올리고 주문 생성 때 URL을 냅니다. 주문에 쓰이지 않은 업로드는 worker가 하루 뒤 S3에서 지우고, 주문된 파일은 보관합니다.
  • 주문 생성의 업로드 연결(소유·용도·상태 검사 후 ATTACHED)은 다음 PR(주문 생성 커스텀 입력 검증)이 붙입니다. 크론의 PURGING 표시·SKIP LOCKED는 그 잠금과 맞물리게 이 PR에 넣었습니다.
  • BE-11을 플랜의 분할 경계(업로드·정리 크론)에서 나눈 2/2 PR입니다. 1/2 PR(feat/order-custom-snapshot, 커스텀 스냅샷 스키마·주문 상세 출력) 위에 쌓았고, 그 PR 머지 뒤 develop 기준으로 올립니다.

변경 사항

  • 선업로드(20261118190324_order_custom_upload)
    • OrderCustomUpload { account_id, purpose(RENDER·COMPOSITE·REFERENCE), object_key unique, content_type, content_length, status(PENDING·ATTACHED·PURGING), attached_at?, purge_started_at? }, (status, created_at)·(status, purge_started_at)·account_id 인덱스. 새 표라 백필이 없습니다.
    • TS UploadPurpose·UPLOAD_POLICIES에 ORDER_CUSTOM_RENDER·ORDER_CUSTOM_COMPOSITE·ORDER_CUSTOM_REFERENCE(order-custom/{renders,composites,references}, 10MB, JPEG·PNG·WebP)를 더했습니다. 판매자·관리자 SDL UploadPurpose에는 섞지 않았습니다.
    • createOrderCustomUploadUrl(purpose: OrderCustomUploadPurpose!, contentType: String!, contentLength: Int!): UploadUrl!
      • 구매자 계정만 씁니다(USER_ONLY, 정지·탈퇴·프로필 없음은 BUYER_ACCOUNT_NOT_ACTIVE).
      • 형식·크기는 S3 정책이 검증합니다(INVALID_CONTENT_TYPE·INVALID_CONTENT_LENGTH·FILE_TOO_LARGE). SDL 설명에 이 오류 코드를 모두 적었습니다.
      • 발급 뒤 PENDING으로 기록하고, 거절되면 기록하지 않습니다.
      • 발급 건수·빈도 상한은 두지 않았습니다. 기존 리뷰·프로필 업로드와 같은 정책이고, 쓰이지 않은 파일은 정리 크론이 지웁니다.
  • 정리 크론(OrderCustomUploadCleanupScheduler, 매시 20분)
    • 역할 게이트(worker만)와 겹친 틱 건너뛰기를 둡니다.
    • PURGING ∧ 1시간 경과, PENDING ∧ 24시간 경과를 상태별 인덱스 범위로 LIMIT 500 FOR UPDATE SKIP LOCKED 잡아 PURGING 표시를 먼저 커밋합니다. 표시 뒤에는 주문이 그 업로드를 붙이지 못하고, 주문 tx가 잡고 있는 행은 건너뜁니다.
    • 그다음 S3Service.deleteObjects로 지우고 지워진 행만 하드 삭제합니다.
    • 실패한 키는 PURGING으로 남아 1시간이 지난 뒤의 정리(매시 크론이라 1~2시간 뒤)에서 다시 지우고, error 경보(key order-custom-upload:purge)를 보냅니다. S3 장애일 수 있어 그 틱에서는 더 잡지 않습니다. 한 틱 최대 20묶음입니다.
    • S3Service.deleteObjects(keys) 신설: 요청당 1,000개, 키별 오류와 요청 자체의 실패를 실패 목록으로 돌려주고 던지지 않습니다.
  • IAM: terraform/aws.tf 앱 정책에 s3:DeleteObject(order-custom/*) statement를 더했습니다. apply는 사람 키로 하는 사용자 작업이라 하지 않았고, 늦으면 크론이 AccessDenied 경보를 내고 업로드가 쌓입니다(유실 없음). terraform fmt 통과.
  • 시드·게이트
    • resetSeedScope: 시드 사용자의 업로드 기록을 지웁니다.
    • model-ownership: OrderCustomUpload(order)
    • enum-sdl-sync에 입력 방향(SDL ⊆ Prisma) 대조를 신설했습니다. 입력 SDL enum에만 값이 늘면 용도 → 업로드 정책 매핑이 비어 500으로 떨어지는데, 기존 대조는 출력 방향(Prisma ⊆ SDL)만 봐 잡지 못했습니다. 첫 쌍은 OrderCustomUploadPurpose입니다.
    • 경계 read·admin Query·감사 대상이 늘지 않아 read-boundary·admin-query-null-inputs·audit 게이트는 그대로입니다.
  • 로컬 DB·크기·커밋
    • 마이그레이션 SQL은 diff로 뽑아 확인한 뒤 로컬 개발 DB에 적용했습니다.
    • 이 PR은 +1,031/−7줄이고 그중 spec이 +592/−5줄입니다(BE-11 전체 +2,541/−198줄).
    • 커밋은 셋입니다: 선업로드·정리 크론 / 입력 enum 동기화 게이트 / 오류 코드 설명·재시도 주석 정정

테스트

  • 정리 크론 7건(S3·경보는 외부라 stub)
    • 대상 경계: PENDING 24h·24h−1ms, PURGING 1h·1h−1ms, ATTACHED 72h 미선택
    • 부분 실패: PURGING 유지·경보·1시간 경과 뒤 재시도
    • 묶음 이어 잡기(500 + 1)·실패 묶음 뒤 중단, 주문 tx가 잡은 행 건너뜀, api 역할 미실행, 겹친 틱, DB 실패 경보
  • S3 deleteObjects 5건(조용한 모드, 키별 오류, 요청 실패, 1,000개 분할, 빈 목록), 주문 커스텀 용도 정책 3종 × 형식 3·초과/형식 거절
  • 발급: 용도 3종 키·기록, 형식·크기 초과·0 거절과 미기록, 판매자 USER_ONLY, 리졸버 1건
  • resetSeedScope: 시드 사용자 업로드 기록만 정리
  • 입력 enum 동기화 2건: 반증(SDL에 값을 더하면 잡는다), 실제 SDL 대조
  • 가드 반증: 하나씩 깨면 해당 테스트가 실패하는 것을 확인하고 되돌렸습니다.
    • 정리 크론의 역할 게이트, ATTACHED 제외, 실패 키 보존(4건 실패)
    • 실제 SDL OrderCustomUploadPurpose에 값을 하나 더하면 입력 enum 대조가 실패(2건)
  • 경로 지정 실행: yarn test src/features/order src/global/storage src/test src/graphql src/prisma 68 suites, 1,145 tests 통과
  • 정적 검사: lint·tsc·dto:check·docs:check·arch:check 통과. 전체 jest는 pre-push에서 돕니다.

플랜 대조

플랜 항목 BE-11 불릿 상태
11절 업로드: TS UploadPurpose·UPLOAD_POLICIES에 ORDER_CUSTOM_RENDER·COMPOSITE·REFERENCE(10MB, JPEG·PNG·WebP) 한 것
11절 업로드: SDL OrderCustomUploadPurpose { RENDER COMPOSITE REFERENCE }(판매자·관리자 UploadPurpose와 분리) 한 것
11절 업로드: OrderCustomUpload 모델과 createOrderCustomUploadUrl(purpose, contentType, contentLength): UploadUrl! 한 것(구매자 계정만)
11절 업로드: attach(주문 tx 안 object_key IN (…) FOR UPDATE, 계정·용도·상태 검사, CUSTOM_UPLOAD_INVALID·CUSTOM_UPLOAD_EXPIRED) 이 PR 범위 밖 — 플랜상 BE-12(persist·attach) 범위입니다. 크론의 PURGING 표시·SKIP LOCKED는 그 잠금과 맞물리게 이 PR에 넣었습니다
정리 크론(매시 20분, 역할 게이트, PENDING 24h·PURGING 1h, LIMIT 500 FOR UPDATE SKIP LOCKED, PURGING 커밋 → 삭제 → 성공 행 하드 삭제, 실패 PURGING 유지 + error 경보) 한 것
S3Service.deleteObjects 신설 한 것
terraform s3:DeleteObject(order-custom/*) statement 한 것(apply는 사용자 작업이라 하지 않음)
BE-01에서 넘어온 항목: resetSeedScope에 order_custom_upload·커스텀 디자인·이미지 정리, seed-reset-scope spec 갱신 한 것(order_custom_upload). 커스텀 디자인·이미지는 분할 1/2 PR에서 함
테스트: 정리 분기·ATTACHED 미선택·S3 실패 stub 경보 한 것
분할 경계(2,500줄 초과 시 업로드·정리 크론에서 분할) 한 것(이 PR이 분할 2/2)
그 밖의 BE-11 불릿(스냅샷 스키마·백필, 상세 출력, 리뷰 Before, 배지, 스냅샷 백필·방어 파싱·Before 테스트) 분할 1/2 PR(feat/order-custom-snapshot)에서 함
OrderItemCustomText·FreeEdit·Attachment writers를 order()로 이 PR 범위 밖 — 플랜상 BE-12(writers) 범위입니다
결정 이 PR에서 한 일 상태
D59 참고 사진 업로드 정책(장당 10MB, JPEG·PNG·WebP) 한 것(건수 한도는 플랜상 BE-12)
D60 슬롯형 합성 이미지 업로드 용도(COMPOSITE) 한 것(저장 자리·대표 이미지는 분할 1/2 PR)
D61 presign 선업로드 발급·기록, 기존 공개 버킷 방식 한 것(주문 생성 때 소유 검증·연결은 플랜상 BE-12)
D62 주문에 쓰이지 않은 업로드를 worker가 하루 뒤 삭제, 주문된 파일 보관 한 것

구매자가 커스텀 이미지(3D 렌더·슬롯형 합성·자유 편집 참고 사진)를 주문 전에 presign으로 올리고 주문 생성 때 URL을 내도록 발급 API와 발급 기록을 둔다. 주문에 쓰이지 않은 업로드는 worker가 하루 뒤 S3에서 지우고, 주문된 파일은 보관한다. 주문 생성의 업로드 연결(소유·용도·상태 검사 후 ATTACHED)은 다음 PR이 붙인다.

변경점
- 스키마·마이그레이션(order_custom_upload): OrderCustomUpload(account_id, purpose RENDER·COMPOSITE·REFERENCE, object_key unique, content_type, content_length, status PENDING·ATTACHED·PURGING, attached_at, purge_started_at), (status, created_at)·(status, purge_started_at)·account_id 인덱스. 새 표라 백필 없음
- 업로드 용도: TS UploadPurpose·UPLOAD_POLICIES에 ORDER_CUSTOM_RENDER·COMPOSITE·REFERENCE(order-custom/{renders,composites,references}, 10MB, JPEG·PNG·WebP). 판매자·관리자 SDL UploadPurpose에는 섞지 않았다
- createOrderCustomUploadUrl(purpose: OrderCustomUploadPurpose!, contentType, contentLength): UploadUrl!. 구매자 계정만(USER_ONLY), 발급 뒤 PENDING으로 기록한다
- S3Service.deleteObjects(keys): 요청당 1000개, 키별 오류와 요청 실패를 실패 목록으로 돌려주고 던지지 않는다
- 정리 크론(매시 20분, 역할 게이트, 겹친 틱 건너뜀): PURGING ∧ 1시간 경과, PENDING ∧ 24시간 경과를 상태별 인덱스 범위로 LIMIT 500 FOR UPDATE SKIP LOCKED로 잡아 PURGING 표시·커밋 → S3 삭제 → 지워진 행만 하드 삭제. 실패한 키는 PURGING으로 남기고 error 경보(key order-custom-upload:purge), 그 틱에서는 더 잡지 않는다. 한 틱 최대 20묶음
- IAM: terraform/aws.tf 앱 정책에 s3:DeleteObject(order-custom/*) statement. apply는 사람 키로 한다
- resetSeedScope: 시드 사용자의 업로드 기록을 지운다. model-ownership: OrderCustomUpload는 order

테스트
- 정리 크론 7건(real DB, S3·경보 stub): 대상 경계(PENDING 24h·24h−1ms, PURGING 1h·1h−1ms, ATTACHED 72h 미선택), 부분 실패 PURGING 유지·경보·1시간 뒤 재시도, 묶음 이어 잡기·실패 뒤 중단, 주문 tx가 잡은 행 건너뜀, api 역할 미실행, 겹친 틱, DB 실패 경보
- S3 deleteObjects 5건(조용한 모드·키별 오류·요청 실패·1000개 분할·빈 목록), 용도 정책 3종 × 형식·크기
- 발급: 용도 3종 키·기록, 형식·크기·0 거절과 미기록, 판매자 USER_ONLY, 리졸버 1건
- resetSeedScope 업로드 기록 1건
입력 SDL enum OrderCustomUploadPurpose에만 값이 늘면 발급 서비스의 용도 → 업로드 정책 매핑이 비어 S3Service에서 TypeError가 나고 500으로 떨어진다. 매핑은 Prisma enum으로만 satisfies 검사되고, enum-sdl-sync는 출력 방향(Prisma ⊆ SDL)만 대조해 이 어긋남을 잡지 못했다.

변경점
- enum-sdl-sync에 입력 쌍 목록(INPUT_PAIRS)을 두고 반대 방향(SDL ⊆ Prisma)을 대조한다. 첫 쌍은 OrderCustomUploadPurpose
- 대조 함수 이름을 방향 중립(missingFrom)으로 바꿨다

테스트
- enum-sdl-sync 20건 통과(입력 방향 2건 추가: 반증 — SDL에 값을 더하면 잡는다, 실제 SDL 대조)
- 반증: 실제 SDL에 SKETCH를 더하면 실제 대조가 실패하는 것을 확인하고 되돌렸다
createOrderCustomUploadUrl 설명이 실제로 나는 오류 코드 일부를 빠뜨렸고, 입력 전용 enum에 출력 enum용 문구가 붙어 있었다. 정리 크론의 재시도 주석은 매시 크론이라 실제로는 1~2시간 뒤 다시 지우는 것을 1시간 뒤로 적고 있었다.

변경점
- SDL 설명: INVALID_CONTENT_LENGTH(크기 0 이하)·BUYER_ACCOUNT_NOT_ACTIVE(정지·탈퇴·프로필 없음) 추가, OrderCustomUploadPurpose 설명에서 출력용 문구 삭제
- 정리 크론: 재시도 시점 주석을 '1시간이 지난 뒤의 정리(1~2시간 뒤)'로 정정(판정 기준 1시간은 그대로)

테스트
- 정리 크론·발급 리졸버 spec 통과, docs:check 통과
@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T20:48:07.372684Z 0dcb9f1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

🧹 knip — dead-code 리포트

Unused exports (3)
Unused exported types (4)
전체 리포트
Unused exports (3)
evaluateProductCustomIssues  src/features/product/index.ts:10:3
validateThreeDDesign         src/features/product/index.ts:15:3
effectiveLeadTimeMinutes     src/features/store/index.ts:12:10 
Unused exported types (4)
RefundRequestedPayload  type  src/features/order/index.ts:19:8  
ProductCustomIssue      type  src/features/product/index.ts:11:8
ThreeDDesignSource      type  src/features/product/index.ts:16:8
ThreeDDesignV1          type  src/features/product/index.ts:17:8

청소 후보(오탐 가능) · 기준 docs/guide/architecture-conventions.md

@github-actions

Copy link
Copy Markdown

🩺 NestJS Doctor — 90/100 (Excellent)

진단 515건 (error 14).

Category error warning info
architecture 2 1 44
correctness 0 275 0
performance 0 43 29
schema 0 0 87
security 12 22 0
architecture / security 상위 항목
  • error security/security/no-hardcoded-secrets: Variable 'SEED_PASSWORD' appears to contain a hardcoded secret.
  • error architecture/architecture/no-manual-instantiation: Manual instantiation of 'AccountNumberReencryptRepository' detected. Use dependency injection instead.
  • warning security/security/no-weak-crypto: Weak hashing algorithm 'md5' used in createHash().
  • error architecture/architecture/no-manual-instantiation: Manual instantiation of 'OutboxRepository' detected. Use dependency injection instead.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal type 'IAuditLogRepository'.
  • warning security/security/no-exposed-env-vars: Direct 'process.env.NODE_ENV' access in 'AuthController'. Use ConfigService instead.
  • warning security/security/require-guards-on-endpoints: Endpoint 'start' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'callback' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'refresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'logout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogin' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerRefresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'devIssueToken' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'adminLogin' has no @UseGuards() at class or method level.

오탐 포함 가능 · 기준 docs/guide/architecture-conventions.md

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage report

St.❔
Category Percentage Covered / Total
🟢 Statements
98.3% (+0.02% 🔼)
12097/12306
🟢 Branches
93.65% (-0.04% 🔻)
4736/5057
🟢 Functions
97.89% (+0.02% 🔼)
2416/2468
🟢 Lines
98.81% (+0.01% 🔼)
10999/11132
Show new covered files 🐣
St.❔
File Statements Branches Functions Lines
🟢
... / order-custom-upload.repository.ts
100% 100% 100% 100%
🟢
... / order-custom-upload-cleanup.scheduler.ts
100% 91.67% 100% 100%
Show files with reduced coverage 🔻
St.❔
File Statements Branches Functions Lines
🟢
... / s3.service.ts
99.02% (+0.17% 🔼)
80.95% (-3.95% 🔻)
100% 100%

Test suite run success

5926 tests passing in 426 suites.

Report generated by 🧪jest coverage report action from 0dcb9f1

@chanwoo7
chanwoo7 merged commit 2c1cd68 into develop Nov 18, 2026
23 of 26 checks passed
@chanwoo7
chanwoo7 deleted the feat/order-custom-upload branch November 18, 2026 20:57
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.25287% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/global/storage/s3.service.ts 75.00% 0 Missing and 4 partials ⚠️
.../services/order-custom-upload-cleanup.scheduler.ts 97.67% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant