- Supabase Storage Helpers: Added
moveStorageFileandcopyStorageFilein supabase-storage.ts using the Supabase REST API endpoints/storage/v1/object/moveand/storage/v1/object/copy. - Sanitization & Renaming Services: Created filename sanitization and renaming helpers in images.ts:
sanitizeFilename()handles accents/diacritics normalization, lowercases, replaces non-alphanumeric chars (including emojis) with hyphens, and falls back to"image"if empty.renameTaskImageIfNeeded()andrenameToolItemImageIfNeeded()compare the current image path to the expected sanitized path (orgs/{orgId}/tasks/{taskId}/{name}.{ext}andorgs/{orgId}/items/{itemId}/{name}.{ext}).- Resolves shared vs unique images: copies in storage if the image is shared by other records (to avoid breaking references), and moves/renames (with database library path updates) if unique.
- Save & Update Hooks:
- Integrated hooks in
saveTaskImagePathandsaveToolItemImagePathin storage.ts to rename images on save. - Integrated hooks in
updateTaskActionandupdateToolItemActionto rename files if the parent task/item name is modified. All triggers are non-blocking and run inside try/catch blocks.
- Integrated hooks in
- Migration Script: Created
scripts/seeds/rename-images.tsto backfill existing records in the database and storage. - Unit Tests: Created a new test suite images-rename.test.ts covering name sanitization and copy/move branch logic.
This allows task and item images in Supabase Storage to be organized descriptively rather than using generic UUIDs or library paths.
Closes #211
- 🐛 Bug fix
- ✨ Enhancement / Feature
- 🔧 Refactor
- 📝 Documentation
- 🎨 UI / Styling
- Run unit tests to verify backend logic:
vitest run __tests__/unit/lib/services/images-rename.test.tsorpnpm test. - Boot up the local dev server (
pnpm dev). - Create/edit a Task or Tool Item, upload an image, and save. Verify in Supabase storage that the image is named after the sanitized name (e.g.
orgs/{orgId}/tasks/{taskId}/deep-clean-fryer.png). - Rename the Task or Tool Item and click Save. Verify the image in storage has been moved/renamed to match the updated name.
- Try the migration seed script:
npx tsx scripts/seeds/rename-images.ts.
No UI changes were introduced. This is a backend and storage-level file renaming enhancement. Examples of before/after storage paths are shown below:
- Before (Task Image):
orgs/org_abc123/images/9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d.png - After (Task Image):
orgs/org_abc123/tasks/task_xyz789/deep-clean-fryer-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d.png - Before (Item Image):
orgs/org_abc123/images/f3c5f2b8-1a4c-4e8f-9a1b-3c4b5d6e7f8a.jpg - After (Item Image):
orgs/org_abc123/items/item_xyz789/glazed-donut-f3c5f2b8-1a4c-4e8f-9a1b-3c4b5d6e7f8a.jpg
- Tested on desktop (Chrome)
- Tested on mobile (iPhone Safari)
- No lint errors (
pnpm lint) - Build passes (
pnpm build) - Smoke test updated (if applicable)
- #