[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79GK82QXS5NVS215F80VGJX":3,"skill-same:01M79GK82QXS5NVS215F80VGJX":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M79GK82QXS5NVS215F80VGJX","saasaloy-file-uploads",null,"Work on the file-uploads feature in this project — the storage_objects record, the \u002Ffiles routes, the public image path, the upload block, and the sweep job. Use when adding or changing anything that records, lists, serves or deletes an uploaded file, when a public image will not render, or when a public upload is refused.","mimukit\u002Fsaasaloy","mimukit","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F11677026?v=4","01M79GFSERAQQ77QPQMC1N0Y6M","Mukitul Islam Mukit","01M79GFSFA4WMGEEBHA68N59WV",4,"MIT","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fmodules\u002Ffile-uploads\u002Fskills\u002Fsaasaloy-file-uploads\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: saasaloy-file-uploads\ndescription: Work on the file-uploads feature in this project — the storage_objects record, the \u002Ffiles routes, the public image path, the upload block, and the sweep job. Use when adding or changing anything that records, lists, serves or deletes an uploaded file, when a public image will not render, or when a public upload is refused.\n---\n\n# saasaloy-file-uploads\n\n`storage` moves bytes. `file-uploads` remembers them.\n\nThe capability can PUT an object and GET it back, and then knows nothing about it: no route can list a tenant's files, tell a finished upload from an abandoned one, or say whether an object is world-readable. This module adds the record that answers all three, plus the two ways a file comes back out — a short-lived signed link for a private file, a stable CDN-cached URL for a public image.\n\n## What landed\n\n| File | What it owns |\n|---|---|\n| `packages\u002Fdb\u002Fsrc\u002Fschema\u002Ffile-uploads.ts` | The `storage_objects` table. One dialect variant landed; its twin is in the module. |\n| `packages\u002Fdb\u002Fsrc\u002Frepositories\u002Fobjects.ts` | Every query against that table, and the access boundary. |\n| `packages\u002Fvalidators\u002Fsrc\u002Ffile-uploads.ts` | The upload request and list query schemas. |\n| `apps\u002Fapi\u002Fsrc\u002Flib\u002Ffile-uploads.ts` | `resolveTenant`, `resolveScope`, the two key scopes, `publicUrl`, `publicImageUrl`. |\n| `apps\u002Fapi\u002Fsrc\u002Froutes\u002Ffiles.ts` | Five authenticated routes and one deliberately unauthenticated one. |\n| `packages\u002Fui\u002Fsrc\u002Fblocks\u002Ffile-uploads.tsx` | The screen's markup. Presentational, as every block is. |\n| `packages\u002Fui\u002Fsrc\u002Flib\u002Fpublic-image.ts` | `imageUrl(url, options, enabled)`, the browser half of the image path. |\n| `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` | The `\u002Ffiles` screen, and the three-step upload. |\n| `packages\u002Ffile-uploads\u002Fsrc\u002Fsweep.ts` | The daily housekeeping sweep, written against a port. |\n| `packages\u002Ffile-uploads\u002Fsrc\u002Fjob.ts` | The sweep as the `queue` capability registers it. |\n| `apps\u002Fapi\u002Fsrc\u002Flib\u002Fstorage-sweep.ts` | That port, over the real Drizzle client and the bucket. |\n\n## The routes\n\n| Route | Auth | What it does |\n|---|---|---|\n| `GET \u002Ffiles` | session | The scope's list, newest first, keyset-paginated. A ready public row carries `url`. |\n| `POST \u002Ffiles\u002Fuploads` | session | Records a `pending` row and returns an upload target. |\n| `POST \u002Ffiles\u002Fuploads\u002F:id\u002Fcomplete` | session | Heads the real object, verifies it, marks `ready` or `rejected`. |\n| `GET \u002Ffiles\u002F:id\u002Fdownload` | session | A signed link for a **private** object. Refuses a public id. |\n| `DELETE \u002Ffiles\u002F:id` | session | `deleting` → delete the object → `deleted`. |\n| `GET \u002Ffiles\u002Fpublic\u002F*` | **none** | Serves a `public-uploads` key with no token and no session. |\n\n## An upload is two calls, and the second one is the point\n\n`POST \u002Ffiles\u002Fuploads` writes the row before the object exists, then hands back a target. `POST \u002Ffiles\u002Fuploads\u002F:id\u002Fcomplete` heads what actually arrived and compares its size and content type against what was declared. A mismatch deletes the object and marks the row `rejected`.\n\nDo not shorten this to one call. A presigned R2 PUT carries no size cap — S3 query signing has nothing to enforce one with — so the cap checked at step one is a claim by the client and nothing more. `complete` is the only place reality is checked. `modules\u002Fstorage`'s own skill names this window; this is what closes it.\n\nThe row is written first, not last, so an upload abandoned halfway leaves a `pending` row the sweep can find rather than an orphan in the bucket.\n\n## Tenant scoping\n\nEvery key is `t\u002F\u003CtenantId>\u002F\u003Cscope>\u002F\u003Cid>\u002F\u003Cfilename>`, and every request-path query filters on an `ObjectScope`: the tenant, plus the owner when no organization is active.\n\n`resolveTenant(session)` in `apps\u002Fapi\u002Fsrc\u002Flib\u002Ffile-uploads.ts` is the only place that knows where the tenant id comes from. It reads the session's `activeOrganizationId` — the column `auth` declares on `sessions` whether or not `multitenant` is installed — and falls back to the literal `default`. There is no import of `multitenant`, no dynamic import, and no branch on what is installed, because there is nothing to branch on: the column is always there and it is always nullable.\n\n`resolveScope(session)` turns that into the query scope. With an active organization the scope is the organization, and every member lists, downloads and deletes all of its objects. With none, the tenant is `default`, which every user of the project shares, so the scope adds the session user as owner and a user acts only on the objects they uploaded. The public route takes no scope: a public object is readable by anyone who holds its key, whoever uploaded it.\n\n**This is weaker than `forTenant`, on purpose.** `multitenant` wraps the query builder so a cross-tenant read cannot be written; depending on it would make organizations a precondition for uploading a file. What carries the guarantee here instead is that `packages\u002Fdb\u002Fsrc\u002Frepositories\u002Fobjects.ts` is the only read path and every request-path function in it takes an `ObjectScope`. A route that writes its own `db.select().from(storageObjects)` removes the boundary. Treat one as a review failure, not a style preference.\n\nA project that adds `multitenant` later keeps its existing objects under `t\u002Fdefault\u002F`. Nothing migrates them: a key cannot be rewritten, and any other choice orphans the bytes. Each one stays reachable by its owner with no organization active.\n\n## Public objects\n\nVisibility is chosen once, at `POST \u002Ffiles\u002Fuploads`, and frozen. The marker lives in the key's `scope` segment — `t\u002F\u003CtenantId>\u002Fpublic-uploads\u002F\u003Cid>\u002F\u003Cfilename>` — so flipping it would have to rewrite the object. There is no un-publish short of deleting the file and uploading it again.\n\n**A public object is world-readable by anyone who learns its key.** The key is the access control: `crypto.randomUUID()` gives the `\u003Cid>` segment 122 random bits, so enumeration is infeasible, but a leaked URL cannot be revoked. Say that out loud to anyone who asks for \"public but only for logged-in users\" — that is a private object with a signed link, which is the other half of this module.\n\n`STORAGE_PUBLIC_URL` gates a public upload, not the provider. Unset, `POST \u002Ffiles\u002Fuploads` refuses `visibility: \"public\"` and names the variable in the message. Nothing falls back to private: storing a file the uploader believes is shareable is worse than refusing.\n\n### Two ways a public object is served\n\nIn production `STORAGE_PUBLIC_URL` points at an **R2 custom domain** (`https:\u002F\u002Ffiles.example.com`) and the bytes never touch the Worker. In dev it points at this module's own route (`http:\u002F\u002Flocalhost:4000\u002Ffiles\u002Fpublic`) and the Worker streams them.\n\nThe key is appended verbatim in both cases, all five segments of it, so the same record resolves through either:\n\n```\nhttps:\u002F\u002Ffiles.example.com\u002Ft\u002Facme\u002Fpublic-uploads\u002Fabc\u002Flogo.png\nhttp:\u002F\u002Flocalhost:4000\u002Ffiles\u002Fpublic\u002Ft\u002Facme\u002Fpublic-uploads\u002Fabc\u002Flogo.png\n```\n\nThe two differ in their prefix, not in the key. That is the part that must not drift: rewrite the path in dev and a record that works locally 404s in production, which is exactly the bug this arrangement exists to prevent. In dev `STORAGE_PUBLIC_URL` therefore carries the `\u002Ffiles\u002Fpublic` path as well as the origin; in production it is an origin and nothing else.\n\nThe local route is never gated off in production. It is the slower path, not the less safe one, and it refuses twice before it touches the database: the scope segment has to be `public-uploads`, and the key has to pass `assertValidKey`.\n\n### Production setup\n\n1. **Attach a custom domain to the bucket.** R2 → your bucket → Settings → Public access → Custom domains. Set `STORAGE_PUBLIC_URL` to that origin, with no path.\n2. **Add a Cache Rule** on the zone, matching URI path `\u002Ft\u002F*\u002Fpublic-*\u002F*`, setting `Edge TTL` and a browser `cache-control`. The header has to come from here: the browser does the PUT, not the Worker, so no code path in this module ever touches the object and `PutOptions` carries `contentType` and `metadata` only.\n3. **Enable image transformations** if you want `publicImageUrl` to resize. Images → Transformations → pick the zone → enable. Then set `STORAGE_IMAGE_TRANSFORMS=true`.\n\nChecked against Cloudflare's own docs on 2026-09-23: **transformations need no Pro plan.** Every account gets 5,000 unique transformations a month. On the Images Free plan that is a ceiling rather than an overage — past it, already-cached variants keep serving and a *new* variant returns error 9422 until you move to Images Paid, where the same transformations cost $0.50 per 1,000. A unique transformation is one source image plus one option set, counted once per calendar month, so three widths of one avatar is three of them.\n\nWith `STORAGE_IMAGE_TRANSFORMS` off — the default — `publicImageUrl` returns the plain public URL and ignores its options. Every image still renders, just unresized. That is deliberate: the `\u002Fcdn-cgi\u002Fimage\u002F` prefix 404s on a zone that has not enabled the feature, and a broken `\u003Cimg>` is worse than a large one.\n\n### Why there is no `images` module\n\nCloudflare Images is a second product with a second binding, its own ids and its own subscription, and using it would store the same bytes twice. An object already in R2 transforms on the way out through a URL prefix on the zone. Revisit only for signed variants, background thumbnails or moderation — none of which this module claims.\n\n## The sweep\n\nThe sweep runs at 04:00 UTC daily and makes three bounded passes: finish `deleting` rows, remove `pending` rows older than 24 hours along with anything at their key, and purge `deleted` rows past `STORAGE_PURGE_AFTER_DAYS` (30 by default).\n\n**It runs only with the `queue` capability**, and `queue` is deliberately not in `dependsOn`: garbage collection is not a precondition for uploading a file, and `queue` brings a provider choice and a Cron Trigger with it. Without it everything still works — upload, list, download, delete — and what you lose is the tidying. Abandoned rows accumulate, soft-deleted rows are never dropped, and a row whose object delete died halfway stays in `deleting`. That is untidy, not broken.\n\nThe three files always land; only the two `plugin-array` registrations need `queue`. In a project without it, `saasaloy add file-uploads` warns that three patch targets are missing — `packages\u002Fqueue\u002Fpackage.json` once and `packages\u002Fqueue\u002Fsrc\u002Findex.ts` twice, each printed both in the plan and again at apply time — and `packages\u002Ffile-uploads\u002Fsrc\u002Fjob.ts` is dead code. That is the expected output, not a failure — a patch carries no `onlyWith` condition the way a file does. Add `queue` later and run `saasaloy add file-uploads --force`; a plain re-run answers \"already installed\" and changes nothing, while `--force` re-applies the patches, which are idempotent.\n\nThe sweep is split across three files for two reasons worth knowing before you move any of it. A file targeting `@queue\u002F...` cannot ship conditionally, because the applier resolves the alias before it applies `onlyWith`, so the job would break `add` in every project with no queue. And a job file inside `packages\u002Fqueue` that imported `@repo\u002Fdb` would pull the schema barrel's `import.meta.glob` into a workspace that does not compile with Vite's types. So `packages\u002Ffile-uploads` holds the sweep and the registration with zero runtime dependencies, and `apps\u002Fapi\u002Fsrc\u002Flib\u002Fstorage-sweep.ts` implements the port. It is `packages\u002Fsubscription`'s arrangement, for the same reasons.\n\n## Wire-up\n\nThe applier writes `packages\u002Fui\u002Fsrc\u002Fblocks\u002Ffile-uploads.tsx` and then stops. It never edits a page.\n\nThe admin screen needs no wiring: `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` landed with the module and the router plugin makes `\u002Ffiles` reachable on its own. Putting it in the nav panel is the separate, optional step `apps\u002Fadmin\u002Fsrc\u002Fcomponents\u002Fnav.ts` describes. Add one line to the `Manage` group in `NAV_AREAS`:\n\n```ts\n{ to: \"\u002Ffiles\", label: \"Files\", icon: FolderIcon },\n```\n\nNo patch does it for you, because `NAV_AREAS` is a nested structure and the `const-array` codemod appends to a flat one.\n\nThe rest of this section is for putting the block on a *second* surface, such as a user-facing page in `apps\u002Fweb`.\n\n1. **The file to edit:** `apps\u002Fweb\u002Fsrc\u002Fpages\u002Faccount.astro`, or whichever page should carry the uploader.\n2. **The import line, verbatim** — and note that the page imports an app-side island, not the block:\n\n   ```ts\n   import FileUploadsPanel from \"@web\u002Fcomponents\u002FFileUploadsPanel\";\n   ```\n\n   You write that island yourself. The block is presentational: it takes rows and three callbacks and calls them, and `packages\u002Fui` imports no api package and no http client. Copy the three-step upload out of `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` — ask the api for a target, PUT the bytes to it with `credentials: \"omit\"`, then call `complete`.\n\n3. **The tag, verbatim, with its client directive:**\n\n   ```astro\n   \u003CFileUploadsPanel client:load \u002F>\n   ```\n\n   `client:load` rather than `client:visible` because the panel holds a file input and its own upload state; hydrating it late would mean a control that looks ready and is not.\n\n4. **A suggested anchor:** after the profile card, or wherever you want it. Placement is yours.\n\n`saasaloy remove file-uploads` deletes the block file and leaves the import you added. Take that line out by hand.\n\n## Things that will bite you\n\n- **A migration is yours to run.** Dropping the schema file into `packages\u002Fdb\u002Fsrc\u002Fschema\u002F` gets it into the barrel; it does not touch your database. Run `pnpm db:generate`, read the migration, then apply it.\n- **`STORAGE_URL_SECRET` is still required**, by `storage`, not by this module. Without it the first upload throws while signing the target.\n- **The public route answers 404 for every refusal.** A bad scope, a malformed key, a missing row and a missing object all look identical from outside. That is intentional: an unauthenticated caller learns nothing about which check it failed.\n- **`GET \u002Ffiles\u002F:id\u002Fdownload` refuses a public id** with a 400 rather than signing one. The list response already carries `url` for a public row; a second, expiring URL would imply a revocability this module does not have.\n- **The list is keyset-paginated, not offset-paginated.** The cursor carries the last row's `createdAt` *and* `id`, because two rows can share a millisecond. Treat it as opaque; an unreadable one falls back to the first page.\n- **`size` on a `pending` row is what the client claimed.** Only after `complete` does it hold the real number.\n\n## Next\n\nRun `saasaloy-app` to put the upload block on a customer screen.\n","# saasaloy-file-uploads\n\n`storage` moves bytes. `file-uploads` remembers them.\n\nThe capability can PUT an object and GET it back, and then knows nothing about it: no route can list a tenant's files, tell a finished upload from an abandoned one, or say whether an object is world-readable. This module adds the record that answers all three, plus the two ways a file comes back out — a short-lived signed link for a private file, a stable CDN-cached URL for a public image.\n\n## What landed\n\n| File | What it owns |\n|---|---|\n| `packages\u002Fdb\u002Fsrc\u002Fschema\u002Ffile-uploads.ts` | The `storage_objects` table. One dialect variant landed; its twin is in the module. |\n| `packages\u002Fdb\u002Fsrc\u002Frepositories\u002Fobjects.ts` | Every query against that table, and the access boundary. |\n| `packages\u002Fvalidators\u002Fsrc\u002Ffile-uploads.ts` | The upload request and list query schemas. |\n| `apps\u002Fapi\u002Fsrc\u002Flib\u002Ffile-uploads.ts` | `resolveTenant`, `resolveScope`, the two key scopes, `publicUrl`, `publicImageUrl`. |\n| `apps\u002Fapi\u002Fsrc\u002Froutes\u002Ffiles.ts` | Five authenticated routes and one deliberately unauthenticated one. |\n| `packages\u002Fui\u002Fsrc\u002Fblocks\u002Ffile-uploads.tsx` | The screen's markup. Presentational, as every block is. |\n| `packages\u002Fui\u002Fsrc\u002Flib\u002Fpublic-image.ts` | `imageUrl(url, options, enabled)`, the browser half of the image path. |\n| `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` | The `\u002Ffiles` screen, and the three-step upload. |\n| `packages\u002Ffile-uploads\u002Fsrc\u002Fsweep.ts` | The daily housekeeping sweep, written against a port. |\n| `packages\u002Ffile-uploads\u002Fsrc\u002Fjob.ts` | The sweep as the `queue` capability registers it. |\n| `apps\u002Fapi\u002Fsrc\u002Flib\u002Fstorage-sweep.ts` | That port, over the real Drizzle client and the bucket. |\n\n## The routes\n\n| Route | Auth | What it does |\n|---|---|---|\n| `GET \u002Ffiles` | session | The scope's list, newest first, keyset-paginated. A ready public row carries `url`. |\n| `POST \u002Ffiles\u002Fuploads` | session | Records a `pending` row and returns an upload target. |\n| `POST \u002Ffiles\u002Fuploads\u002F:id\u002Fcomplete` | session | Heads the real object, verifies it, marks `ready` or `rejected`. |\n| `GET \u002Ffiles\u002F:id\u002Fdownload` | session | A signed link for a **private** object. Refuses a public id. |\n| `DELETE \u002Ffiles\u002F:id` | session | `deleting` → delete the object → `deleted`. |\n| `GET \u002Ffiles\u002Fpublic\u002F*` | **none** | Serves a `public-uploads` key with no token and no session. |\n\n## An upload is two calls, and the second one is the point\n\n`POST \u002Ffiles\u002Fuploads` writes the row before the object exists, then hands back a target. `POST \u002Ffiles\u002Fuploads\u002F:id\u002Fcomplete` heads what actually arrived and compares its size and content type against what was declared. A mismatch deletes the object and marks the row `rejected`.\n\nDo not shorten this to one call. A presigned R2 PUT carries no size cap — S3 query signing has nothing to enforce one with — so the cap checked at step one is a claim by the client and nothing more. `complete` is the only place reality is checked. `modules\u002Fstorage`'s own skill names this window; this is what closes it.\n\nThe row is written first, not last, so an upload abandoned halfway leaves a `pending` row the sweep can find rather than an orphan in the bucket.\n\n## Tenant scoping\n\nEvery key is `t\u002F\u003CtenantId>\u002F\u003Cscope>\u002F\u003Cid>\u002F\u003Cfilename>`, and every request-path query filters on an `ObjectScope`: the tenant, plus the owner when no organization is active.\n\n`resolveTenant(session)` in `apps\u002Fapi\u002Fsrc\u002Flib\u002Ffile-uploads.ts` is the only place that knows where the tenant id comes from. It reads the session's `activeOrganizationId` — the column `auth` declares on `sessions` whether or not `multitenant` is installed — and falls back to the literal `default`. There is no import of `multitenant`, no dynamic import, and no branch on what is installed, because there is nothing to branch on: the column is always there and it is always nullable.\n\n`resolveScope(session)` turns that into the query scope. With an active organization the scope is the organization, and every member lists, downloads and deletes all of its objects. With none, the tenant is `default`, which every user of the project shares, so the scope adds the session user as owner and a user acts only on the objects they uploaded. The public route takes no scope: a public object is readable by anyone who holds its key, whoever uploaded it.\n\n**This is weaker than `forTenant`, on purpose.** `multitenant` wraps the query builder so a cross-tenant read cannot be written; depending on it would make organizations a precondition for uploading a file. What carries the guarantee here instead is that `packages\u002Fdb\u002Fsrc\u002Frepositories\u002Fobjects.ts` is the only read path and every request-path function in it takes an `ObjectScope`. A route that writes its own `db.select().from(storageObjects)` removes the boundary. Treat one as a review failure, not a style preference.\n\nA project that adds `multitenant` later keeps its existing objects under `t\u002Fdefault\u002F`. Nothing migrates them: a key cannot be rewritten, and any other choice orphans the bytes. Each one stays reachable by its owner with no organization active.\n\n## Public objects\n\nVisibility is chosen once, at `POST \u002Ffiles\u002Fuploads`, and frozen. The marker lives in the key's `scope` segment — `t\u002F\u003CtenantId>\u002Fpublic-uploads\u002F\u003Cid>\u002F\u003Cfilename>` — so flipping it would have to rewrite the object. There is no un-publish short of deleting the file and uploading it again.\n\n**A public object is world-readable by anyone who learns its key.** The key is the access control: `crypto.randomUUID()` gives the `\u003Cid>` segment 122 random bits, so enumeration is infeasible, but a leaked URL cannot be revoked. Say that out loud to anyone who asks for \"public but only for logged-in users\" — that is a private object with a signed link, which is the other half of this module.\n\n`STORAGE_PUBLIC_URL` gates a public upload, not the provider. Unset, `POST \u002Ffiles\u002Fuploads` refuses `visibility: \"public\"` and names the variable in the message. Nothing falls back to private: storing a file the uploader believes is shareable is worse than refusing.\n\n### Two ways a public object is served\n\nIn production `STORAGE_PUBLIC_URL` points at an **R2 custom domain** (`https:\u002F\u002Ffiles.example.com`) and the bytes never touch the Worker. In dev it points at this module's own route (`http:\u002F\u002Flocalhost:4000\u002Ffiles\u002Fpublic`) and the Worker streams them.\n\nThe key is appended verbatim in both cases, all five segments of it, so the same record resolves through either:\n\n```\nhttps:\u002F\u002Ffiles.example.com\u002Ft\u002Facme\u002Fpublic-uploads\u002Fabc\u002Flogo.png\nhttp:\u002F\u002Flocalhost:4000\u002Ffiles\u002Fpublic\u002Ft\u002Facme\u002Fpublic-uploads\u002Fabc\u002Flogo.png\n```\n\nThe two differ in their prefix, not in the key. That is the part that must not drift: rewrite the path in dev and a record that works locally 404s in production, which is exactly the bug this arrangement exists to prevent. In dev `STORAGE_PUBLIC_URL` therefore carries the `\u002Ffiles\u002Fpublic` path as well as the origin; in production it is an origin and nothing else.\n\nThe local route is never gated off in production. It is the slower path, not the less safe one, and it refuses twice before it touches the database: the scope segment has to be `public-uploads`, and the key has to pass `assertValidKey`.\n\n### Production setup\n\n1. **Attach a custom domain to the bucket.** R2 → your bucket → Settings → Public access → Custom domains. Set `STORAGE_PUBLIC_URL` to that origin, with no path.\n2. **Add a Cache Rule** on the zone, matching URI path `\u002Ft\u002F*\u002Fpublic-*\u002F*`, setting `Edge TTL` and a browser `cache-control`. The header has to come from here: the browser does the PUT, not the Worker, so no code path in this module ever touches the object and `PutOptions` carries `contentType` and `metadata` only.\n3. **Enable image transformations** if you want `publicImageUrl` to resize. Images → Transformations → pick the zone → enable. Then set `STORAGE_IMAGE_TRANSFORMS=true`.\n\nChecked against Cloudflare's own docs on 2026-09-23: **transformations need no Pro plan.** Every account gets 5,000 unique transformations a month. On the Images Free plan that is a ceiling rather than an overage — past it, already-cached variants keep serving and a *new* variant returns error 9422 until you move to Images Paid, where the same transformations cost $0.50 per 1,000. A unique transformation is one source image plus one option set, counted once per calendar month, so three widths of one avatar is three of them.\n\nWith `STORAGE_IMAGE_TRANSFORMS` off — the default — `publicImageUrl` returns the plain public URL and ignores its options. Every image still renders, just unresized. That is deliberate: the `\u002Fcdn-cgi\u002Fimage\u002F` prefix 404s on a zone that has not enabled the feature, and a broken `\u003Cimg>` is worse than a large one.\n\n### Why there is no `images` module\n\nCloudflare Images is a second product with a second binding, its own ids and its own subscription, and using it would store the same bytes twice. An object already in R2 transforms on the way out through a URL prefix on the zone. Revisit only for signed variants, background thumbnails or moderation — none of which this module claims.\n\n## The sweep\n\nThe sweep runs at 04:00 UTC daily and makes three bounded passes: finish `deleting` rows, remove `pending` rows older than 24 hours along with anything at their key, and purge `deleted` rows past `STORAGE_PURGE_AFTER_DAYS` (30 by default).\n\n**It runs only with the `queue` capability**, and `queue` is deliberately not in `dependsOn`: garbage collection is not a precondition for uploading a file, and `queue` brings a provider choice and a Cron Trigger with it. Without it everything still works — upload, list, download, delete — and what you lose is the tidying. Abandoned rows accumulate, soft-deleted rows are never dropped, and a row whose object delete died halfway stays in `deleting`. That is untidy, not broken.\n\nThe three files always land; only the two `plugin-array` registrations need `queue`. In a project without it, `saasaloy add file-uploads` warns that three patch targets are missing — `packages\u002Fqueue\u002Fpackage.json` once and `packages\u002Fqueue\u002Fsrc\u002Findex.ts` twice, each printed both in the plan and again at apply time — and `packages\u002Ffile-uploads\u002Fsrc\u002Fjob.ts` is dead code. That is the expected output, not a failure — a patch carries no `onlyWith` condition the way a file does. Add `queue` later and run `saasaloy add file-uploads --force`; a plain re-run answers \"already installed\" and changes nothing, while `--force` re-applies the patches, which are idempotent.\n\nThe sweep is split across three files for two reasons worth knowing before you move any of it. A file targeting `@queue\u002F...` cannot ship conditionally, because the applier resolves the alias before it applies `onlyWith`, so the job would break `add` in every project with no queue. And a job file inside `packages\u002Fqueue` that imported `@repo\u002Fdb` would pull the schema barrel's `import.meta.glob` into a workspace that does not compile with Vite's types. So `packages\u002Ffile-uploads` holds the sweep and the registration with zero runtime dependencies, and `apps\u002Fapi\u002Fsrc\u002Flib\u002Fstorage-sweep.ts` implements the port. It is `packages\u002Fsubscription`'s arrangement, for the same reasons.\n\n## Wire-up\n\nThe applier writes `packages\u002Fui\u002Fsrc\u002Fblocks\u002Ffile-uploads.tsx` and then stops. It never edits a page.\n\nThe admin screen needs no wiring: `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` landed with the module and the router plugin makes `\u002Ffiles` reachable on its own. Putting it in the nav panel is the separate, optional step `apps\u002Fadmin\u002Fsrc\u002Fcomponents\u002Fnav.ts` describes. Add one line to the `Manage` group in `NAV_AREAS`:\n\n```ts\n{ to: \"\u002Ffiles\", label: \"Files\", icon: FolderIcon },\n```\n\nNo patch does it for you, because `NAV_AREAS` is a nested structure and the `const-array` codemod appends to a flat one.\n\nThe rest of this section is for putting the block on a *second* surface, such as a user-facing page in `apps\u002Fweb`.\n\n1. **The file to edit:** `apps\u002Fweb\u002Fsrc\u002Fpages\u002Faccount.astro`, or whichever page should carry the uploader.\n2. **The import line, verbatim** — and note that the page imports an app-side island, not the block:\n\n   ```ts\n   import FileUploadsPanel from \"@web\u002Fcomponents\u002FFileUploadsPanel\";\n   ```\n\n   You write that island yourself. The block is presentational: it takes rows and three callbacks and calls them, and `packages\u002Fui` imports no api package and no http client. Copy the three-step upload out of `apps\u002Fadmin\u002Fsrc\u002Froutes\u002Ffiles.tsx` — ask the api for a target, PUT the bytes to it with `credentials: \"omit\"`, then call `complete`.\n\n3. **The tag, verbatim, with its client directive:**\n\n   ```astro\n   \u003CFileUploadsPanel client:load \u002F>\n   ```\n\n   `client:load` rather than `client:visible` because the panel holds a file input and its own upload state; hydrating it late would mean a control that looks ready and is not.\n\n4. **A suggested anchor:** after the profile card, or wherever you want it. Placement is yours.\n\n`saasaloy remove file-uploads` deletes the block file and leaves the import you added. Take that line out by hand.\n\n## Things that will bite you\n\n- **A migration is yours to run.** Dropping the schema file into `packages\u002Fdb\u002Fsrc\u002Fschema\u002F` gets it into the barrel; it does not touch your database. Run `pnpm db:generate`, read the migration, then apply it.\n- **`STORAGE_URL_SECRET` is still required**, by `storage`, not by this module. Without it the first upload throws while signing the target.\n- **The public route answers 404 for every refusal.** A bad scope, a malformed key, a missing row and a missing object all look identical from outside. That is intentional: an unauthenticated caller learns nothing about which check it failed.\n- **`GET \u002Ffiles\u002F:id\u002Fdownload` refuses a public id** with a 400 rather than signing one. The list response already carries `url` for a public row; a second, expiring URL would imply a revocability this module does not have.\n- **The list is keyset-paginated, not offset-paginated.** The cursor carries the last row's `createdAt` *and* `id`, because two rows can share a millisecond. Treat it as opaque; an unreadable one falls back to the first page.\n- **`size` on a `pending` row is what the client claimed.** Only after `complete` does it hold the real number.\n\n## Next\n\nRun `saasaloy-app` to put the upload block on a customer screen.\n",{"name":5,"description":7},"main","5ecf3d110b216ef678e06a1630f6b63a8e730bb5","modules\u002Ffile-uploads\u002Fskills\u002Fsaasaloy-file-uploads",0,"https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy","https:\u002F\u002Fsaasaloy.com","https:\u002F\u002Fgithub.com\u002Fmimukit","https:\u002F\u002Fmimukit.com","Senior Software Engineer · 9+ yrs Fullstack (TS\u002FNode\u002FReact) · AI integrations, distributed systems · Building @saasaloy & @codealoy · Bangladesh 🇧🇩 \u002F Remote","2026-11-13 20:39:28",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add mimukit\u002Fsaasaloy --skill saasaloy-file-uploads",{"tool":40,"command":41},"bunx","bunx skills add mimukit\u002Fsaasaloy --skill saasaloy-file-uploads",{"tool":43,"command":44},"pnpm","pnpm dlx skills add mimukit\u002Fsaasaloy --skill saasaloy-file-uploads","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fmodules\u002Ffile-uploads\u002Fskills\u002Fsaasaloy-file-uploads\u002FSKILL.md",true,[],[49,56,63,70,77,83],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M7BE75C34XHSPVJNQC8FY4Q0","saasaloy-subscription","Runbook for the subscription capability — provider-agnostic subscriptions in packages\u002Fsubscription, with a plan file, a projection table, a billable-subject file, plan entitlements and per-provider modules. Use when adding a plan, adding a plan feature or a numeric limit, gating an API route with requireFeature or requireWithinLimit, reading the 402 it returns, working out why a subject resolves to the free plan, wiring a checkout or portal route, reading a SubscriptionError, choosing or switching SUBSCRIPTION_PROVIDER, registering a webhook in the vendor's dashboard, writing a third subscription provider, or upgrading a project that still has `billing` installed.","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fmodules\u002Fsubscription\u002Fskills\u002Fsaasaloy-subscription\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7BE68MJ8H47JZKTBDFYR6JD","saasaloy-notification","Runbook for the notification module, in-app notifications for apps\u002Fapp. It owns the notifications and notification_opt_outs tables, notify() in apps\u002Fapi\u002Fsrc\u002Flib\u002Fnotify.ts, the \u002Fnotifications api routes, the bell in the app header, the sidebar badge, the \u002Fnotifications page with Inbox and Preferences tabs, the notification config section, and the daily prune. Use when sending a notification from an api route, adding or changing a category, changing retention, debugging a badge or bell count that does not move, or removing the module.","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fmodules\u002Fnotification\u002Fskills\u002Fsaasaloy-notification\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7BE53PDQV0YDPG8RNVGTPEQ","saasaloy-cms","Runbook for the cms module, the in-house CMS behind apps\u002Fadmin. Covers code-defined collections, the Tiptap editor, drafts, revisions and redirects, the publish-time renderer, the public blog on apps\u002Fweb and its 60-second cache. Use when adding a collection or a field, rendering a stored body, reusing the editor, renderer or media field from another module, moving the blog to another path, re-rendering live posts after a renderer upgrade or a STORAGE_PUBLIC_URL change, or working out why a published post is not live yet.","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fmodules\u002Fcms\u002Fskills\u002Fsaasaloy-cms\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M79GQ03M63V5EKSST92B3S5X","saasaloy-beta","The beta module's own procedure.","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fpackages\u002Fcli\u002Ftest\u002Ffixtures\u002Fregistry-clean\u002Fbeta\u002Fsaasaloy-beta\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M79GPXV3K8YF3M4VA0KGVE0B","helper","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fpackages\u002Fcli\u002Ftest\u002Ffixtures\u002Fregistry-broken\u002Fbad-skill\u002Fhelper\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M79GPR8EVS1YX0W8X33Q9YD8","saasaloy-update","Runbook for an AI agent that updates this project to a newer Saasaloy CLI and newer module versions with saasaloy update. Use when the owner says \"update saasaloy\", \"upgrade the CLI\", \"pull the latest modules\", \"update the base template\", \"work the merge plan\", \"clear the update notes\", when saasaloy update or saasaloy outdated --check exits 3 or 2, when a merge plan or .saasaloy\u002Fmerge-plan.md is handed to you, or when an adopted project takes its first update. Covers the CLI upgrade, the preview, --out, the file merges, the update notes and \"Notes that may apply\", --resolved and --done, a file deleted locally and --restore, a three-way or two-way base, an update that skips releases, --from, the verify commands, and the exit codes.","https:\u002F\u002Fgithub.com\u002Fmimukit\u002Fsaasaloy\u002Fblob\u002Fmain\u002Fpackages\u002Fcli\u002Ftemplates\u002Fbase\u002F_agents\u002Fskills\u002Fsaasaloy-update\u002FSKILL.md",[],[]]