invisal / libsql-studio

A lightweight LibSQL/rqlite graphical client on your browser
https://libsqlstudio.com
MIT License
162 stars 13 forks source link

feat: better file type detection #63

Closed rin-yato closed 3 months ago

rin-yato commented 3 months ago

Description

Add better file type detection for /api/upload. This is done using the magic-bytes package which has support for browser environment and a tons of file type support.

We need to use a package that support browser api as we are running on edge.


Caveat

Currently we store the filename in our user_files table. But in the case that let's say user upload a file of type jpeg. But the file name is instead filename.pdf. In this case we correct the file type but we still store the filename as filename.pdf, do you have any suggestion for this?

image

Demo (1.4x speed):

In the demo, I renamed a jpeg screenshot into .pdf but the api detected it as jpeg, and use that instead.

https://github.com/invisal/libsql-studio/assets/106462074/57cf68e8-a645-4e89-83ed-c22a7aeca72a

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **libsql-viewer** | ⬜️ Ignored ([Inspect](https://vercel.com/invisals-projects/libsql-viewer/BYog3TDviZuTawRDMvg8hK4mwS2a)) | [Visit Preview](https://libsql-viewer-git-better-filetype-invisals-projects.vercel.app) | | Mar 30, 2024 5:03pm |
rin-yato commented 3 months ago

Pls merge #62 first before merging this