Mirrors agents/plugin from caelum0x/scribase: five new one-task skills covering the most common agent requests, a bumped plugin version, a license and privacy policy URL for directory submission, and a sync of the general scribase skill with the X-launch-post addition it was missing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
73 lines
3.2 KiB
Markdown
73 lines
3.2 KiB
Markdown
---
|
|
name: scribase-add-storage
|
|
description: Add file storage to a Scribase project — create a bucket and write row-level-security policies for uploads, avatars, or any user-owned files, then upload and read them back with signed URLs. Use when the user asks to add file upload, storage, buckets, avatars, attachments, images, or object storage to a Scribase or Supabase-compatible app.
|
|
---
|
|
|
|
# Scribase: file storage
|
|
|
|
Storage speaks the same `/storage/v1` API as Supabase, so the app uses
|
|
`supabase.storage.*` unchanged. Access is decided by row level security on
|
|
`storage.objects` — a bucket with no policy is unreadable and unwritable by
|
|
`anon`/`authenticated`, which is the safe default.
|
|
|
|
## 1. Create the bucket
|
|
|
|
MCP (fastest, from the chat session): call `storage.buckets.create` with
|
|
`name` (required) and `public: true` only if the user actually wants files
|
|
served by a public URL with no auth check — default to private. Optional
|
|
`file_size_limit` (bytes) and `allowed_mime_types` (e.g.
|
|
`["image/png", "image/*"]`) cut down what a bad actor can upload. List what
|
|
already exists with `storage.buckets.list` before creating a duplicate.
|
|
|
|
```json
|
|
{ "name": "avatars", "public": false, "allowed_mime_types": ["image/*"], "file_size_limit": 5242880 }
|
|
```
|
|
|
|
Prefer this for a bucket the user wants right now, in a preview or on their
|
|
own project. For anything shipping to production, do it as a migration
|
|
instead (below) so the bucket and its policies are versioned and repeatable.
|
|
|
|
## 2. Policies: scope by the uploader's own folder
|
|
|
|
Convention: the first path segment is the owner's user id, so one policy
|
|
covers every file under it.
|
|
|
|
```sql
|
|
-- 003_avatars.sql
|
|
insert into storage.buckets (id, name, public) values ('avatars', 'avatars', false)
|
|
on conflict (id) do nothing;
|
|
|
|
create policy "avatars: owner reads" on storage.objects for select to authenticated
|
|
using (bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);
|
|
create policy "avatars: owner writes" on storage.objects for insert to authenticated
|
|
with check (bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);
|
|
```
|
|
|
|
Add `for update`/`for delete` the same way only if the user actually needs
|
|
to replace or remove their own files; do not grant more than asked. Apply
|
|
with `migrate.run` (see the general `scribase` skill) or `scribase migrate
|
|
--dir supabase/migrations --apply`. See `scribase-write-rls-policy` for the
|
|
policy-writing rules this storage policy also follows (one policy per
|
|
command, index what a policy filters on, never `using (true)` on a private
|
|
bucket).
|
|
|
|
## 3. Upload and read from the app
|
|
|
|
```ts
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
const path = `${user!.id}/avatar.png`
|
|
await supabase.storage.from('avatars').upload(path, file, { upsert: true, contentType: 'image/png' })
|
|
|
|
// Private bucket: a short-lived signed URL
|
|
const { data } = await supabase.storage.from('avatars').createSignedUrl(path, 60 * 60)
|
|
|
|
// Public bucket only (public: true at creation)
|
|
const { data: pub } = supabase.storage.from('avatars').getPublicUrl(path)
|
|
```
|
|
|
|
## 4. Report back
|
|
|
|
Say which bucket was created, whether it is public or private, exactly which
|
|
policies exist and who they let read/write, and the upload path convention
|
|
the app should follow (`{user_id}/...`).
|