fix(backend): serve original content with byte-range support
deploy / deploy (push) Successful in 1m1s

GetContent streamed the whole file with a plain 200/io.Copy and no
Accept-Ranges, so the browser couldn't seek or scrub audio/video opened
from the viewer. It now serves seekable bodies (the disk store returns an
*os.File) via http.ServeContent, which advertises Accept-Ranges and
answers Range requests with 206 Partial Content; non-seekable bodies
still fall back to a plain stream. Adds an integration test asserting a
ranged request returns 206 with the right Content-Range and bytes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 18:40:49 +03:00
parent cefa33c00d
commit 76dcb8721a
2 changed files with 40 additions and 1 deletions
@@ -955,6 +955,34 @@ func TestImportFromFolder(t *testing.T) {
assert.True(t, ct.Equal(mtime), "content_datetime %v should equal mtime %v", ct, mtime)
}
// TestContentRangeRequests verifies the original-content endpoint answers a
// byte-range request with 206 Partial Content (so the browser can seek within
// audio/video) rather than streaming the whole body.
func TestContentRangeRequests(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}
h := setupSuite(t)
token := h.login("admin", "admin")
file := h.uploadJPEG(token, "clip.jpg")
id := file["id"].(string)
req, err := http.NewRequest("GET", h.url("/files/"+id+"/content?inline=1"), nil)
require.NoError(t, err)
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Range", "bytes=0-9")
resp, err := h.client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusPartialContent, resp.StatusCode)
assert.Equal(t, "bytes", resp.Header.Get("Accept-Ranges"))
assert.Regexp(t, `^bytes 0-9/\d+$`, resp.Header.Get("Content-Range"))
require.Len(t, body, 10)
assert.Equal(t, minimalJPEG()[:10], body)
}
// TestBlockRevokesActiveSessions verifies that blocking a user immediately
// invalidates their outstanding access tokens.
func TestBlockRevokesActiveSessions(t *testing.T) {