Enables seeding "assets" file types via the CLI locally.
Improves consistency between Studio upload behavior and CLI bucket seeding behavior.
What is the current behavior?
While using storage seeding on a project, I noticed an issue with the CLI's behavior. My goal was to seed some "assets" into a public bucket. Although this worked in staging via the dashboard, the generated URL locally always had a text/plain content-type instead of text/javascript.
The bug stemmed from two issues:
Outdated Studio image: The Studio image was out of date and was fixed in a version where the generated URL for a file didn't account for the file's "content-type." This has been resolved in the latest Studio container image release.
Inconsistent file type inference: Depending on the upload method (via the Studio web app or db reset and seeding), file types were inferred differently. The web app properly assigned the correct file type (e.g., text/javascript, text/html), while seeding did not.
This discrepancy occurs because, at seed time in the CLI, we use http.DetectContentType, which follows the mimesniff convention. This convention intentionally avoids assigning certain MIME types, such as text/javascript, for security reasons
However, these restrictions don't apply in our case because:
We already allow this content type to be uploaded via the platform.
We control who can upload files to a dedicated bucket.
What is the new behavior?
To enable automatic seeding of these file types without disrupting existing setups, I've introduced a new extension_detector option in the bucket definition. When enabled, this option attempts to detect the file type based on the file's extension. If successful, it overrides the type detected via content sniffing.
This solution was chosen after evaluating multiple alternative packages, which did not outperform our current file type detection approach (mimetypes, filetype).
Additional context
The motivation behind uploading text/javascript files was to experiment with using Supabase buckets as both storage and a hosting provider. The goal was to rely solely on Supabase to deploy a website, without needing additional services like Vercel or other hosting providers.
What kind of change does this PR introduce?
What is the current behavior?
While using storage seeding on a project, I noticed an issue with the CLI's behavior. My goal was to seed some "assets" into a public bucket. Although this worked in staging via the dashboard, the generated URL locally always had a
text/plain
content-type instead oftext/javascript
.The bug stemmed from two issues:
Outdated Studio image: The Studio image was out of date and was fixed in a version where the generated URL for a file didn't account for the file's "content-type." This has been resolved in the latest Studio container image release.
Inconsistent file type inference: Depending on the upload method (via the Studio web app or
db reset
and seeding), file types were inferred differently. The web app properly assigned the correct file type (e.g.,text/javascript
,text/html
), while seeding did not.This discrepancy occurs because, at seed time in the CLI, we use
http.DetectContentType
, which follows themimesniff
convention. This convention intentionally avoids assigning certain MIME types, such astext/javascript
, for security reasons However, these restrictions don't apply in our case because:We already allow this content type to be uploaded via the platform.
We control who can upload files to a dedicated bucket.
What is the new behavior?
To enable automatic seeding of these file types without disrupting existing setups, I've introduced a new
extension_detector
option in the bucket definition. When enabled, this option attempts to detect the file type based on the file's extension. If successful, it overrides the type detected via content sniffing.This solution was chosen after evaluating multiple alternative packages, which did not outperform our current file type detection approach (
mimetypes
,filetype
).Additional context
The motivation behind uploading
text/javascript
files was to experiment with using Supabase buckets as both storage and a hosting provider. The goal was to rely solely on Supabase to deploy a website, without needing additional services like Vercel or other hosting providers.