-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Establish basic file browser and index fallback #2662
Conversation
@Tronic This is the fallback browser solution that I told you I had. LMK is this is what you had in mind. |
Codecov ReportBase: 88.650% // Head: 88.642% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2662 +/- ##
=============================================
- Coverage 88.650% 88.642% -0.009%
=============================================
Files 82 87 +5
Lines 6767 6850 +83
Branches 1156 1171 +15
=============================================
+ Hits 5999 6072 +73
- Misses 531 538 +7
- Partials 237 240 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
The file browser formats fairly lengthy HTML documents by string.format (if I read the code correctly). Maybe we at this time should consider a minimal templating engine, something like html5tagger (my own minimalistic module for creating HTML from Python code), or some more sensible way of handling these? As a bare minimum, filenames and such strings require escaping. I gather the error pages are another place where bare strings are becoming unsustainable, as Sanic doesn't create much other HTML output itself than those and now this browser. |
This is very minimal stuff we're doing. It does not warrant a dependency IMO. |
The (fast) I took the HTML formatting discussion to sanic-repo on Discord as it is clearly off-topic regarding this PR. |
Let's keep this in hold until we resolve the Discord conversation. In short, we are talking about potentially including a minimal lib for html rendering. |
Another somewhat off-topic comment (sorry about my wandering mind). With a file browser Sanic is getting very close to something like |
It already does have this:
What I do want to upgrade is making the argument portion choose between a Sanic instance, a factory method, and a simple server dir without having to specify |
It's looking good, didn't have much to comment on code but I didn't try actually running it yet. |
At the rate Sanic is evolving with your patches, I wouldn't be surprised if this soon also supported multiple return formats, and then offered a JS frontend that fetches file lists in JSON to avoid page reloads while streaming video files to browser for quick playback like Droppy can 😆 |
Yeah. I think we should take your idea a step further and make the styles for this and the error pages common. Probably it's own PR though. It's a nice touch. I've put next to zero thought into file name encoding and how it may impact navigation. We also should think about what the normal config patterns will be and if we need to separate autoindex and index.html fallback. Right now they are both explicit opt in separately. |
I think the file browser and autoindex serve very different functions, and I don't want anyone on the Internet browsing the files of my webapps (that simply have a static index.html at root to serve their frontend), so keep them separated. Regarding filename encoding, that could get really tricky with Unicode (the mentioned Droppy allows uploads with Unicode NFD and saves them on disk, but can then no longer load/touch those files because filenames from URLs become NFC, but that might be some NodeJS internals and not what browsers do). I will look into this once I get to run this [an extremely busy day]. One way that it is [supposed to be] handled is take the filename |
I did some refactoring to break apart the autoindexing and allow for a new common module for our growing list of handlers and pages. |
Great. I was also thinking of that. And it could also have a small Sanic header/footer with the S logo in inline SVG, if we want to push the branding a bit more. |
Co-authored-by: L. Kärkkäinen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #2661
This adds a new opt in pattern when a static directory is being served.
These may be used together or separately.
autoindex
= Whether to show a basic HTML file browserindex_name
= The name of a fallback file in that directory to show, if anyThe logic is as follows:
index_name
set and exists:autoindex
: