-
Notifications
You must be signed in to change notification settings - Fork 40
file upload endpoints #69
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
Conversation
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.
Left various comments above.
One more piece is needed here, though, to avoid orphan uploads by associating uploads with posts in sogs: see #65.
af17900
to
022b82f
Compare
9bcb943
to
c259466
Compare
One other thing: we should clean up the |
e22b90f
to
3b13c31
Compare
#77 should be ready for merge or cherry-picking now, which adds the |
f606123
to
6e2a637
Compare
9c337d2
to
e68b026
Compare
b5285f6
to
6ac7266
Compare
Makes the filename not required (we just put in a null if not provided) for upload or download.
send_file() has optimizations that won't work through an onion request (in particular, we can't extract the response body from such a response, but we need that for onion requests). This changes it to build a flask.Response that streams it via Python file iteration instead, which is a bit less efficient, but allows extracting the body where needed for onion request handling. (It should still stream, rather than slam everything into memory, when invoked directly).
We return some valid non-200 responses (like 201, 304) that shouldn't be producing log spam.
Changes the file upload to only strip bad characters from the filename we use to generate the path on disk, but not the suggested filename we store in the database and return to the user. Also changes the test suite to interpret the random byte filename as latin1 so that it ends up as utf-8 for flask. Otherwise flask does the latin1 conversion itself, and returns utf-8 back, but that breaks the test (because what we get back has gone through an unexpected latin1 -> utf-8 encoding).
In practice it is probably already null, but in theory you could upload a post attachment and then pin that.
operator precedence in comparison fixup
1. Flask's test client is doing something strange when setting a header property starting with \\. Just bypass it entirely at set the header ourself using filename*=UTF-8''... encoding (flask understands this, but doesn't produce it). 2. Make random filename tests deterministic (to avoid intermittent failures), and increase the count to 500 and length to 32 (instead of 128 and 16) so that we're (hopefully) hitting more weird cases. 3. Add a specific test with leading backslashes in the filename because that specifically was causing issues with flask (see point 1). 4. Replace \0 and / with unicode replacement characters in the uploaded filename because those aren't valid filename characters *anywhere*. 5. Do the expected local path filename cleanup and verify that we stored at the expected path (even for utf8 or unsafe filenames).
It wasn't obvious how seconds()/minutes()/etc. worked (I got it wrong the first time I tried it), so rename it inside a `from_now` class that makes it more self-descriptive.
If called after `.room` had been accessed it would return None instead of the id.
Add tests for cross-room file references. We were correctly handling not allowing cross-room references of post attachments, but cross-room references of the room image was allowed (now fixed).
6ac7266
to
27ce595
Compare
add room file upload and room file fetching endpoints with unit tests
Fixes #65 #80