mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Linter fix
This commit is contained in:
parent
76c8d39370
commit
78b127d016
|
|
@ -305,7 +305,30 @@ func (r *downloadRequest) respondFromLocalFile(
|
|||
}).Info("Responding with file")
|
||||
responseFile = file
|
||||
responseMetadata = r.MediaMetadata
|
||||
if err := r.addDownloadFilenameToHeaders(w, responseMetadata); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", string(responseMetadata.ContentType))
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(int64(responseMetadata.FileSizeBytes), 10))
|
||||
contentSecurityPolicy := "default-src 'none';" +
|
||||
" script-src 'none';" +
|
||||
" plugin-types application/pdf;" +
|
||||
" style-src 'unsafe-inline';" +
|
||||
" object-src 'self';"
|
||||
w.Header().Set("Content-Security-Policy", contentSecurityPolicy)
|
||||
|
||||
if _, err := io.Copy(w, responseFile); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to copy from cache")
|
||||
}
|
||||
return responseMetadata, nil
|
||||
}
|
||||
|
||||
func (r *downloadRequest) addDownloadFilenameToHeaders(
|
||||
w http.ResponseWriter,
|
||||
responseMetadata *types.MediaMetadata,
|
||||
) error {
|
||||
// If the requestor supplied a filename to name the download then
|
||||
// use that, otherwise use the filename from the response metadata.
|
||||
filename := string(responseMetadata.UploadName)
|
||||
|
|
@ -316,7 +339,7 @@ func (r *downloadRequest) respondFromLocalFile(
|
|||
if len(filename) > 0 {
|
||||
unescaped, err := url.PathUnescape(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("url.PathUnescape: %w", err)
|
||||
return fmt.Errorf("url.PathUnescape: %w", err)
|
||||
}
|
||||
|
||||
isASCII := true // Is the string ASCII or UTF-8?
|
||||
|
|
@ -352,21 +375,7 @@ func (r *downloadRequest) respondFromLocalFile(
|
|||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", string(responseMetadata.ContentType))
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(int64(responseMetadata.FileSizeBytes), 10))
|
||||
contentSecurityPolicy := "default-src 'none';" +
|
||||
" script-src 'none';" +
|
||||
" plugin-types application/pdf;" +
|
||||
" style-src 'unsafe-inline';" +
|
||||
" object-src 'self';"
|
||||
w.Header().Set("Content-Security-Policy", contentSecurityPolicy)
|
||||
|
||||
if _, err := io.Copy(w, responseFile); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to copy from cache")
|
||||
}
|
||||
return responseMetadata, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Note: Thumbnail generation may be ongoing asynchronously.
|
||||
|
|
|
|||
Loading…
Reference in a new issue