ColorWalk Upload & Cleanup Implementation Summary (2026-03-24)
ColorWalk Upload & Cleanup Implementation Summary (2026-03-24)
Scope Completed
- Unified temp-photo upload behavior across:
- Check-in dialog upload flow
- My Photos upload/replace flow
- Added cancelable upload support and leave-page protection during active uploads.
- Added backend compensation and stronger idempotent handling for temp photo binding.
- Added explicit scheduled cleanup automation (GitHub Actions) and cleanup observability.
- Verified current Cloudflare worker schedule status via API.
Cloudflare Verification Findings
- Checked Worker:
the-color-walk - Cloudflare API result for schedules:
schedules: [](no active worker cron schedule found). - Confirmed cleanup endpoint is callable and functional:
POST https://thecolorwalk.com/api/colorwalk/photos/cleanup-temp- Returned
code=0during manual test.
Frontend Changes
1) New shared upload session hook
- Added file:
src/shared/hooks/use-colorwalk-temp-upload.ts - New capabilities:
- Unified upload state machine:
processing/uploading/uploaded/error/canceled AbortControllercancellation for in-flight uploadsbeforeunloadprotection while uploads are in progress- Best-effort discard of uploaded temp photos
- Reusable operations:
uploadFilesremoveItemcancelAndCleanupdiscardTempPhotoIdsreset
- Unified upload state machine:
2) Check-in dialog flow migrated to shared hook
- Updated file:
src/shared/blocks/colorwalk/color-walk-spin.tsx - What changed:
- Removed duplicated per-file temp upload implementation.
- Replaced local upload state machinery with shared hook state/actions.
- Close behavior now:
- Prompts user if upload or complete-submit is in progress
- Cancels in-flight requests
- Discards uploaded temp photos
- Added support display for canceled upload status.
beforeunloadnow protects both:- check-in completion in progress
- upload in progress
3) My Photos flow migrated to shared hook
- Updated file:
src/app/[locale]/(landing)/my-color-walk/photos-client.tsx - What changed:
- Replaced local temp upload logic with shared hook.
- Added compensation cleanup if bind step fails after temp upload succeeds.
- Added upload-in-progress warning in dialog controls.
- Added close confirmation behavior while uploads are active.
Backend Changes
4) Idempotent-safe temp photo binding improvements
- Updated file:
src/shared/models/color_walk.ts bindTempPhotosToCheckinimprovements:- Handles retry safely when temp photos are already bound to the same check-in.
- Still rejects invalid states (expired, cleaned, or bound to a different check-in).
- Only inserts newly bindable rows and updates
boundAtfor newly bound rows.
5) API-level compensation cleanup
- Updated file:
src/app/api/colorwalk/checkins/[checkinId]/photos/route.ts- On POST failure, performs best-effort
discardTempPhotosForUser.
- On POST failure, performs best-effort
- Updated file:
src/app/api/colorwalk/checkin/complete/route.ts- On failure, performs best-effort cleanup of provided
tempPhotoIds.
- On failure, performs best-effort cleanup of provided
6) Cleanup endpoint hardening + observability
- Updated file:
src/app/api/colorwalk/photos/cleanup-temp/route.ts - Changes:
- In production, cleanup token is required.
- Added structured cleanup logs:
scanned,cleaned, failed count, duration
- Logs failed item details when present.
Scheduled Cleanup Automation
- Added workflow:
.github/workflows/colorwalk-temp-photo-cleanup.yml - Schedule:
- Hourly cron:
0 * * * *
- Hourly cron:
- Behavior:
- Calls cleanup endpoint with token header.
- Fails workflow if response
code != 0.
- Required secrets for this workflow:
COLORWALK_APP_URLCOLORWALK_CLEANUP_TOKEN
Validation Performed
pnpm buildpassed after changes.prettier --checkpassed for all modified/new files.pnpm lintcould not run due to repo-level ESLint v9 config mismatch (existing project setup issue, not introduced by this change).
Required Post-Deploy Configuration
- Cloudflare Worker env var:
COLORWALK_CLEANUP_TOKEN(must be set in production)
- If using GitHub cron workflow:
- GitHub Actions Secrets:
COLORWALK_APP_URLCOLORWALK_CLEANUP_TOKEN(same value as Cloudflare env)
- GitHub Actions Secrets:
Notes
- Upload functionality can be tested before setting cleanup token.
- Without cleanup token in production:
- cleanup endpoint will reject requests (
unauthorized). - scheduled cleanup automation will fail until token is configured.
- cleanup endpoint will reject requests (