Add API to serve blob or LFS file content#19689
Conversation
Gusted
left a comment
There was a problem hiding this comment.
I think we would need to test cases for all the different codepaths(etag handling, normal raw file, lfs object, redirection for lfs), to ensure they return the correct content.
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
|
I still think we should have some test-cases for these API's. |
|
I tried this now for a while, but I don't get it working because I don't know how to store an LFS object in a test repo. Any idea how I can do this to get the file afterwards? |
We already should have tests that works closely with LFS(look at the references of |
|
|
||
| reqLFS := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/"+lfs) | ||
| respLFS := MakeRequestNilResponseRecorder(t, reqLFS, http.StatusOK) | ||
| assert.Equal(t, littleSize, respLFS.Length) |
There was a problem hiding this comment.
I'm not sure, but seems like we need to do some cleanup here in order to not conflict with other tests.
There was a problem hiding this comment.
I changed it t create a new repo and delete it afterwards.
1. Avoid reading the blob data multiple times 2. Ensure that caching is only checked when about to serve the blob/lfs 3. Avoid nesting by returning early 4. Make log message a bit more clear 5. Ensure that the dataRc is closed by defer when passed to ServeData Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath
left a comment
There was a problem hiding this comment.
I've pushed a slight restructure of the code up - this ensures that the caching is not checked until we know what we're actually going to serve. (The previous code had a potential to re-serve a pointer file if the LFSMetaObject entry was fixed in the intervening time.)
|
make L-G-T-M work. |
* giteaofficial/main: Add API to serve blob or LFS file content (go-gitea#19689) Disable unnecessary mirroring elements (go-gitea#18527) [skip ci] Updated translations via Crowdin Remove customized (unmaintained) dropdown, improve aria a11y for dropdown (go-gitea#19861) Set Setpgid on child git processes (go-gitea#19865)
* Add LFS API * Update routers/api/v1/repo/file.go Co-authored-by: Gusted <williamzijl7@hotmail.com> * Apply suggestions * Apply suggestions * Update routers/api/v1/repo/file.go Co-authored-by: Gusted <williamzijl7@hotmail.com> * Report errors * ADd test * Use own repo for test * Use different repo name * Improve handling * Slight restructures 1. Avoid reading the blob data multiple times 2. Ensure that caching is only checked when about to serve the blob/lfs 3. Avoid nesting by returning early 4. Make log message a bit more clear 5. Ensure that the dataRc is closed by defer when passed to ServeData Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Add an endpoint to get file content or to serve LFS object directly. Code is mainly from the web UI endpoint.
Closes #19685