You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if the editor recognized binary files and didn't attempt to show them as a text file.
Perhaps show a "download this file" link and the line "this is a binary file"? Or, for images (perhaps by identifying them using MIME types?), show a preview in the editor, or for videos, maybe show a video player?
The text was updated successfully, but these errors were encountered:
What makes things like this hard is that you would have to propagate the information up a long chain. It goes like this:
The files helper (which chroots into the site directory, and for security reasons is the ONLY thing that can EVER directly interact with the site files)
The orchestrator Flask app, which runs the files helper and propagates the results up
The view in the manager, which essentially just pipes through the results from the orchestrator
The manager JS, which has to handle this specially.
Here's my suggestion for implementation:
Send a new header (or possibly a URL parameter) from the JS, propagated all the way down into the files helper that indicates the MIME type that the browser is expecting from this file. Initially, this is text/plain.
When the files helper opens the file, it should use libmagic (which may actually not be possible, or at least be tricky, given how it runs) to identify the file type. If this isn't on a predetermined list (images, videos, PDFs, etc.), it assumes text/plain (so that files with obscure filetypes don't trigger false positives).
If the files helper sees a mismatch between the real vs. expected MIME types, it returns an error (again, propagated up) that the JS handles specially. Maybe something like UNEXPECTED MIME TYPE: image/png.
When the JS sees that, it re-requests the file with the new MIME type.
The reason you need the request; re-request model is because the JS needs to handle different files differently. Text files get loaded into memory, then placed in a code editor. Other files should probably be opened in an iframe. The JS needs to know that up-front when it makes the request.
It would be nice if the editor recognized binary files and didn't attempt to show them as a text file.
Perhaps show a "download this file" link and the line "this is a binary file"? Or, for images (perhaps by identifying them using MIME types?), show a preview in the editor, or for videos, maybe show a video player?
The text was updated successfully, but these errors were encountered: