@gj-kit/expo-media 레시피
각 코드 블록은 패키지 README에서 이미 타입 검사하는 public-contract 예제를 재사용합니다.
1. 명시적인 업로드 제한으로 media kit 만들기
섹션 제목: “1. 명시적인 업로드 제한으로 media kit 만들기”platform adapter를 붙이기 전에 앱 upload API와 선언된 용량 정책만 연결합니다.
완료 상태: 앱이 업로드 권한을 계속 소유하는 Expo 기반 미디어 kit을 만듭니다.
앱 소유 경계:
앱에서 upload intent와 완료를 담당하는 uploadApi를 구현하고, 파일 제한을 명시합니다.
import { createMediaKit, type MediaUploadApi } from '@gj-kit/expo-media';
type Asset = { readonly id: string };declare const uploadApi: MediaUploadApi<Asset>; // Your app owns auth and upload URLs.
export const media = createMediaKit({ api: uploadApi, limits: { image: { maxBytes: 15 * 1024 * 1024 } },});2. 중단된 업로드를 분류하고 복구하기
섹션 제목: “2. 중단된 업로드를 분류하고 복구하기”앱이 저장소 정합을 처리하기 전에 unknown error를 안전한 recovery metadata로 좁힙니다.
업로드가 중간에 죽으면 오류가 URL 없는 복구 메타데이터로 좁혀집니다. stage와 orphanedObjects(objectName·contentType·sizeBytes·storageState)만 담기고, presigned URL이나 네이티브 예외 원문은 들어가지 않습니다.
import { createMediaKit, mediaUploadFailureInfo } from '@gj-kit/expo-media';import type { MediaUploadApi, MediaUploadFailureInfo } from '@gj-kit/expo-media';
declare const uploadApi: MediaUploadApi<{ readonly id: string }>; // App owns auth + upload URLs.declare function reconcile(failure: MediaUploadFailureInfo): Promise<void>; // App owns cleanup.
// `limits` is required, and there is no numeric escape hatch:// createMediaKit({ api: uploadApi });// -> error TS2345: Argument of type '{ api: MediaUploadApi<...>; }' is not// assignable to parameter of type 'MediaKitConfig<...>'.export const media = createMediaKit({ api: uploadApi, limits: 'server-enforced' });
export async function recover(error: unknown): Promise<void> { const failure = mediaUploadFailureInfo(error); if (!failure) throw error; // Not an upload failure — never swallow it. // failure.stage : 'intent' | 'put' | 'complete' // failure.orphanedObjects : readonly { objectName; contentType; sizeBytes; // storageState: 'uploaded' | 'possibly-uploaded' }[] // No presigned URL and no native error text ever reach this value. await reconcile(failure); throw error;}전체 API reference에서 모든 export와 import path를 확인하세요.