Files
Alaister YoungandAlaister Young ccd691423b [FE-5114] (part 6) – refactor(studio): migrate platform storage routes (#54033)
## Problem

Studio's `routes/api/platform/storage/**` routes still run legacy Next
Pages Router handlers through `compat/next/api.ts`, and
`buckets/$id/objects/download.ts` has no remaining callers. Part 6 of 7
for
[FE-5114](https://linear.app/supabase/issue/FE-5114/rewrite-api-routes-as-native-tanstack-start-handlers-and-remove-the)
migrates the 14 active storage routes to native TanStack Start handlers
and removes the unused download route.

## Solution

**Changed:**

- Migrated 14 `buckets/**` and `vector-buckets/**` routes to
`createApiHandlers` and `parseJsonBody`
- Replaced the `parseAsInt`/`parseAsString`/`parseAsStringEnum` helpers
in `buckets/index.ts` with a zod query schema that drops invalid values,
keeping the conditional spreads so unset keys aren't sent to storage-js
- Forwarded upstream `StorageError` status codes across all storage and
vector-bucket routes via `storageErrorResponse` /
`getStorageErrorStatus` (falling back to the route's default 400/500
when no valid HTTP status is present)
- Guarded missing/invalid `SUPABASE_PUBLIC_URL` with a `500` error
response in `objects/public-url`, `objects/sign`, and
`objects/sign-multi`
- Typed the `vector-buckets/$id/indexes` POST body from storage-js's
`createIndex` options
- Corrected stale `Allow` headers on `vector-buckets/$id` (`GET,
DELETE`) and `vector-buckets/$id/indexes/$indexName` (`DELETE`) via
`createApiHandlers`

**Added:**

- `lib/api/self-hosted/storage.ts` with `getStorageErrorStatus`,
`storageErrorResponse`, `getStoragePublicOrigin`,
`missingStoragePublicUrlResponse`, and `remapStoragePublicUrl`
- Unit tests for `buckets/index` query parsing,
`buckets/$id/objects/sign-multi` (`SUPABASE_PUBLIC_URL` guard, origin
remapping, and upstream error status), and `vector-buckets` POST
(exercising the real storage client through MSW)

**Removed:**

- Removed unused
`routes/api/platform/storage/$ref/buckets/$id/objects/download.ts` and
regenerated `routeTree.gen.ts`

**Behavior changes vs master:**

- `buckets` GET drops malformed `limit`/`offset`/sort values instead of
`parseInt`-truncating them (e.g. `offset=1.5` is ignored rather than
sent as `1`)
- `vector-buckets` POST validates the body with zod and returns `400`
when `bucketName` is missing or not a string
- Storage routes forward the upstream HTTP status code from
`StorageApiError` instead of hardcoding `400`/`500`
- `objects/public-url`, `objects/sign`, and `objects/sign-multi` return
a `500` JSON error when `SUPABASE_PUBLIC_URL` is unset or invalid
instead of throwing an uncaught `TypeError`
- Unused `buckets/$id/objects/download` route has been removed

## Review instructions

1. Run `pnpm --filter studio exec vitest run
tests/routes/api/platform/storage/`.
2. On self-hosted Studio, create/list/empty/delete a storage bucket,
upload/download/move/sign/delete an object, and check vector bucket
operations.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 22:55:25 +08:00
..
…
…
…
…