Skip to content

Conversation

@pixelsama
Copy link
Contributor

Important

  1. Read CONTRIBUTING.md
  2. Ensure issue exists and you're assigned
  3. Link correctly: Fixes #<issue number>

What & Why

What: Add Supabase Storage bucket infrastructure for local image uploads in the admin content editor

Why: Currently, the admin content editor's image component only supports external URLs (like Unsplash). This PR creates the foundational storage infrastructure to enable users to upload and manage their own local images directly within the platform, reducing dependency on external image hosting services.

Fixes #250

Pre-PR Checklist

Run these:

  • pnpm type-check
  • pnpm format:check
  • pnpm lint
  • pnpm build
  • pnpm i18n:check (if applicable - N/A, no i18n changes)

Type

  • 🐛 Bug fix
  • ✨ Feature
  • 💥 Breaking change
  • 📚 Docs
  • ♻️ Refactor
  • ⚡ Performance

Changes

Database Migration

  • Create content-images storage bucket with public access
  • Set file size limit to 10MB (larger than avatar bucket's 5MB)
  • Support image formats: JPEG, PNG, WebP, GIF
  • Add RLS policies for authenticated users:
    • Upload: Users can only upload to user-{userId}/ folder
    • Select: Public read access (anyone can view images via URL)
    • Update: Users can only update their own files
    • Delete: Users can only delete their own files

Technical Details

File: supabase/migrations/20250930172735_setup_content_images_storage.sql

Bucket Configuration:

bucket_id: 'content-images'
public: true  -- ✅ Images accessible via public URL
file_size_limit: 10485760 bytes (10MB)
allowed_mime_types: ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/gif']

Path Structure: user-{userId}/{timestamp}-{uuid}.{ext}

Security: RLS policies ensure users can only manage files in their own directories while maintaining public read access for displaying images on content pages.

Implementation Plan

This is PR #1 of a 5-part implementation:

Testing Notes

  • Migration syntax validated
  • Follows existing pattern from avatars bucket
  • Type checking passed
  • No breaking changes to existing functionality

…itor

- Create content-images bucket with public access
- Set file size limit to 10MB
- Support image formats: JPEG, PNG, WebP, GIF
- Add RLS policies for authenticated users
- Users can only upload/delete files in their own folder (user-{userId}/)

Related to ifLabX#250

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Sep 30, 2025

@pixelsama is attempting to deploy a commit to the zhang's projects Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 30, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pixelsama, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes the foundational storage infrastructure necessary to enable local image uploads directly within the admin content editor. By introducing a new Supabase Storage bucket, content-images, with specific configurations for public accessibility, file size limits, and supported image types, the platform reduces its dependency on external image hosting services. Crucially, it integrates comprehensive Row Level Security policies to ensure secure and user-specific management of uploaded files, allowing users to manage their own content while making images publicly viewable.

Highlights

  • New Storage Bucket: A new Supabase Storage bucket named content-images has been added to support local image uploads for the admin content editor.
  • Bucket Configuration: The content-images bucket is configured for public access, allows files up to 10MB, and supports JPEG, PNG, WebP, and GIF image formats.
  • Row Level Security (RLS): Robust RLS policies are implemented to ensure authenticated users can only upload, update, and delete images within their own user-{userId}/ directory, while maintaining public read access for all images.
  • Foundational Step: This pull request is the first of a five-part implementation plan to fully integrate local image upload capabilities into the content editor.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the type:feature Request for a brand-new capability. label Sep 30, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Supabase storage bucket content-images for the admin content editor, along with the necessary RLS policies. The migration script is well-structured and idempotent. I've provided a couple of suggestions to improve the robustness of the RLS policies and the maintainability of the bucket creation statement. Overall, this is a solid addition that lays the foundation for image uploads.

Apply Gemini Code Assist review suggestions:
- Use owner column instead of foldername for UPDATE/DELETE policies
- Use EXCLUDED pseudo-table in ON CONFLICT clause for better maintainability

Changes:
- UPDATE policy: auth.uid() = owner (more secure and decoupled)
- DELETE policy: auth.uid() = owner (more secure and decoupled)
- ON CONFLICT: Use EXCLUDED.* to reference inserted values (DRY principle)

Benefits:
- Enhanced security by using Supabase's standard owner column
- Decoupled security from file path structure
- Improved code maintainability
- Follows Supabase best practices

Related to ifLabX#250

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added the lgtm Looks good to me; approved by a reviewer. label Sep 30, 2025
@lyzno1 lyzno1 merged commit f0e7218 into ifLabX:main Sep 30, 2025
14 of 15 checks passed
pixelsama added a commit to pixelsama/AgentifUI that referenced this pull request Sep 30, 2025
Add core business logic for content image uploads:

Service Layer (lib/services/content-image-upload-service.ts):
- validateImageFile(): Validate file type (JPEG, PNG, WebP, GIF) and size (10MB max)
- generateContentImagePath(): Generate unique file paths (user-{userId}/{timestamp}-{uuid}.ext)
- uploadContentImage(): Upload images to content-images bucket
- deleteContentImage(): Delete images from storage
- listUserContentImages(): List user's uploaded images
- extractFilePathFromUrl(): Extract file path from Supabase URLs

Hook Layer (lib/hooks/use-content-image-upload.ts):
- useContentImageUpload(): React hook for state management
- State management: loading, error, progress tracking
- Operations: uploadImage, deleteImage, validateFile, resetState
- Type-safe interfaces for state and results

Technical Details:
- Bucket: content-images (created in PR ifLabX#278)
- Max file size: 10MB
- Supported formats: JPEG, JPG, PNG, WebP, GIF
- Path structure: user-{userId}/{timestamp}-{uuid}.{ext}
- Cache control: 3600s
- Follows existing pattern from use-avatar-upload.ts

Related to ifLabX#250

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Looks good to me; approved by a reviewer. size:M This PR changes 30-99 lines, ignoring generated files. type:feature Request for a brand-new capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Admin content editor images component should support local image upload

2 participants