Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/storage/FileServing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ func TestServeFile(t *testing.T) {
} else {
test.ResponseBodyContains(t, w, "<a href=\"http")
}
r = httptest.NewRequest("GET", "/", nil)
w = httptest.NewRecorder()
file, result = GetFile("awsTest1234567890123")
test.IsEqualBool(t, result, true)
ServeFile(file, w, r, false, true, true)
if aws.IsMockApi {
test.ResponseBodyContains(t, w, "https://redirect.url")
} else {
test.ResponseBodyContains(t, w, "<a href=\"http")
}
testconfiguration.DisableS3()
}
newFile, err := createTestFile()
Expand Down
10 changes: 7 additions & 3 deletions internal/storage/filesystem/s3filesystem/aws/Aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ func Stream(writer io.Writer, file models.File) error {
// ServeFile either redirects the user to a pre-signed download url (default) or downloads the file and serves it as a proxy (depending
// on configuration). Returns true if blocking operation (to set download status) or false if non-blocking.
func ServeFile(w http.ResponseWriter, r *http.Request, file models.File, forceDownload, forceDecryption bool) (bool, error) {
if forceDecryption {
return true, serveDecryptedFile(w, file)
}
needsDecryption := forceDecryption && file.Encryption.IsEncrypted
if awsConfig.ProxyDownload {
if needsDecryption {
return true, serveDecryptedFile(w, file)
}
return true, proxyDownload(w, file, forceDownload)
}
if needsDecryption {
return true, serveDecryptedFile(w, file)
}
return false, redirectToDownload(w, r, file, forceDownload)
}

Expand Down