4.7 KiB
| phase | plan | type |
|---|---|---|
| 05-image-url-server | 1 | execute |
Purpose: Enable providers like Replicate and fal.ai to receive images as URLs instead of large base64 payloads, improving reliability for larger images and meeting provider API requirements. Output: In-memory image store, serving endpoint, and utility function for URL generation.
<execution_context> ~/.claude/get-shit-done/workflows/execute-phase.md ~/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.mdPrior phase context:
@.planning/phases/03-generate-node-refactor/03-02-SUMMARY.md
Relevant source files:
@src/app/api/generate/route.ts @src/lib/providers/cache.ts
Tech stack available: Next.js API routes, in-memory caching pattern from providers/cache.ts Established patterns: TTL-based caching, API route structure
Constraining decisions:
- Phase 03-02: Server-side provider execution, not client-side
- Phase 02-03: 10-minute cache TTL pattern established
Provider requirements (from discovery):
- Replicate: Accepts data URIs but recommends URLs for files >256KB. Parameter name varies by model (
image,input_image, etc.) - fal.ai: Accepts both URLs and data URIs via
image_urlparameter
No TTL - callers are responsible for cleanup after use. This prevents memory accumulation since images are deleted immediately after provider fetches them.
Parse base64 data URL format: data:{mimeType};base64,{data} to extract mimeType and Buffer.
Export store functions.
TypeScript compiles without errors: npx tsc --noEmit
Image store module exists with storeImage, getImage, deleteImage, deleteImages exports
Route structure follows Next.js App Router dynamic route pattern.
Import getImage from @/lib/images/store.
Build succeeds: npm run build (route compiles correctly)
GET /api/images/[id] returns stored images or 404
The baseUrl parameter allows the caller to provide the server's base URL. Returning the ID enables callers to delete the image after use.
Also create helper to detect if an image should use URL (size threshold):
shouldUseImageUrl(base64DataUrl: string): boolean- Returns true if base64 data exceeds 256KB (Replicate's recommendation threshold)
- This allows callers to decide whether to use URL or pass base64 directly
TypeScript compiles:
npx tsc --noEmituploadImageForUrl (returns url+id) and shouldUseImageUrl functions exported from @/lib/images
<success_criteria>
- All tasks completed
- All verification checks pass
- No TypeScript errors
- Image store, serving endpoint, and utility functions ready for integration </success_criteria>