Cursor rule
.cursor/rules/storage.mdcFollow these rules when working on file storage.
Cursor rules
Quality
65/100
Scores the file, not the repository.Length
658 words
15 headings · 3 code blocksRepository
9
— · pushed 394 days agoLast changed
3 days ago
First indexed 3 days ago.12345# Storage Rules67Follow these rules when working with Supabase Storage.89It uses Supabase Storage for file uploads, downloads, and management.1011## General Rules1213- Always use environment variables for bucket names to maintain consistency across environments14- Never hardcode bucket names in the application code15- Always handle file size limits and allowed file types at the application level16- Use the `upsert` method instead of `upload` when you want to replace existing files17- Always implement proper error handling for storage operations18- Use content-type headers when uploading files to ensure proper file handling1920## Organization2122### Buckets2324- Name buckets in kebab-case: `user-uploads`, `profile-images`25- Create separate buckets for different types of files (e.g., `profile-images`, `documents`, `attachments`)26- Document bucket purposes in a central location27- Set appropriate bucket policies (public/private) based on access requirements28- Implement RLS (Row Level Security) policies for buckets that need user-specific access29- Make sure to let me know instructions for setting up RLS policies on Supabase since you can't do this yourself, including the SQL scripts I need to run in the editor3031### File Structure3233- Organize files in folders based on their purpose and ownership34- Use predictable, collision-resistant naming patterns35- Structure: `{bucket}/{userId}/{purpose}/{filename}`36- Example: `profile-images/123e4567-e89b/avatar/profile.jpg`37- Include timestamps in filenames when version history is important38- Example: `documents/123e4567-e89b/contracts/2024-02-13-contract.pdf`3940## Actions4142- When importing storage actions, use `@/actions/storage`43- Name files like `example-storage-actions.ts`44- Include Storage at the end of function names `Ex: uploadFile -> uploadFileStorage`45- Follow the same ActionState pattern as DB actions4647Example of a storage action:4849```ts50"use server"5152import { createClientComponentClient } from "@supabase/auth-helpers-nextjs"53import { ActionState } from "@/types"5455export async function uploadFileStorage(56 bucket: string,57 path: string,58 file: File59): Promise<ActionState<{ path: string }>> {60 try {61 const supabase = createClientComponentClient()6263 const { data, error } = await supabase64 .storage65 .from(bucket)66 .upload(path, file, {67 upsert: false,68 contentType: file.type69 })7071 if (error) throw error7273 return {74 isSuccess: true,75 message: "File uploaded successfully",76 data: { path: data.path }77 }78 } catch (error) {79 console.error("Error uploading file:", error)80 return { isSuccess: false, message: "Failed to upload file" }81 }82}83```8485## File Handling8687### Upload Rules8889- Always validate file size before upload90- Implement file type validation using both extension and MIME type91- Generate unique filenames to prevent collisions92- Set appropriate content-type headers93- Handle existing files appropriately (error or upsert)9495Example validation:9697```ts98const MAX_FILE_SIZE = 10 * 1024 * 1024 // 10MB99const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"]100101function validateFile(file: File): boolean {102 if (file.size > MAX_FILE_SIZE) {103 throw new Error("File size exceeds limit")104 }105106 if (!ALLOWED_TYPES.includes(file.type)) {107 throw new Error("File type not allowed")108 }109110 return true111}112```113114### Download Rules115116- Always handle missing files gracefully117- Implement proper error handling for failed downloads118- Use signed URLs for private files119120### Delete Rules121122- Implement soft deletes when appropriate123- Clean up related database records when deleting files124- Handle bulk deletions carefully125- Verify ownership before deletion126- Always delete all versions/transforms of a file127128## Security129130### Bucket Policies131132- Make buckets private by default133- Only make buckets public when absolutely necessary134- Use RLS policies to restrict access to authorized users135- Example RLS policy:136137```sql138CREATE POLICY "Users can only access their own files"139ON storage.objects140FOR ALL141USING (auth.uid()::text = (storage.foldername(name))[1]);142```143144### Access Control145146- Generate short-lived signed URLs for private files147- Implement proper CORS policies148- Use separate buckets for public and private files149- Never expose internal file paths150- Validate user permissions before any operation151152## Error Handling153154- Implement specific error types for common storage issues155- Always provide meaningful error messages156- Implement retry logic for transient failures157- Log storage errors separately for monitoring158159## Optimization160161- Implement progressive upload for large files162- Clean up temporary files and failed uploads163- Use batch operations when handling multiple files
Also in sportiz91/vibe-template
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| sportiz91/vibe-template.cursor/rules/auth.mdc · 9 | Cursor rules | securitydo-not | 32/100 | 3 days ago | |
| sportiz91/vibe-template.cursor/rules/backend.mdc · 9 | Cursor rules | do-not | 61/100 | 3 days ago | |
| sportiz91/vibe-template.cursor/rules/coding-standards.mdc · 9 | Cursor rules | styletypesui | 36/100 | 3 days ago | |
| sportiz91/vibe-template.cursor/rules/frontend.mdc · 9 | Cursor rules | do-not | 61/100 | 3 days ago | |
| sportiz91/vibe-template.cursor/rules/general.mdc · 9 | Cursor rules | stylearchsecuritydo-not+1 | 69/100 | 3 days ago | |
| sportiz91/vibe-template.cursorrules · 9 | .cursorrules | stylearchsecuritydo-not+1 | 49/100 | 3 days ago | |
| sportiz91/vibe-templateCLAUDE.md · 9 | CLAUDE.md | setuptestlint-formatstyle+7 | 88/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
