Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show images and other media in the editor instead of loading the binary #22

Open
etnguyen03 opened this issue Sep 30, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@etnguyen03
Copy link
Contributor

etnguyen03 commented Sep 30, 2020

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?

@etnguyen03 etnguyen03 added the enhancement New feature or request label Sep 30, 2020
@ghost
Copy link

ghost commented Sep 30, 2020

This is potentially doable, but a little tricky.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant