fix(album): enforce signed upload MIME, map duplicate folders, and optimize HEAD
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
@@ -68,27 +69,30 @@ func StaticHandler(bucket *blob.Bucket, prefix string) http.Handler {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
reader, err := bucket.NewReader(r.Context(), key, nil)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
ct := strings.TrimSpace(reader.ContentType())
|
||||
ct := strings.TrimSpace(attrs.ContentType)
|
||||
if ct == "" {
|
||||
ct = defaultStaticContentType
|
||||
}
|
||||
w.Header().Set("Cache-Control", MediaCacheControl)
|
||||
w.Header().Set("Content-Type", ct)
|
||||
if attrs.Size >= 0 {
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(attrs.Size, 10))
|
||||
}
|
||||
if !attach.IsInlineContentType(ct) {
|
||||
w.Header().Set("Content-Disposition", "attachment")
|
||||
} else if cd := safeDisposition(attrs.ContentDisposition); cd != "" {
|
||||
w.Header().Set("Content-Disposition", cd)
|
||||
}
|
||||
if r.Method == http.MethodHead {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
reader, err := bucket.NewReader(r.Context(), key, nil)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer reader.Close()
|
||||
_, _ = io.Copy(w, reader)
|
||||
})
|
||||
}
|
||||
@@ -240,14 +244,15 @@ func SignedUploadHandler(app *backpack.App, svc *Service) http.Handler {
|
||||
|
||||
uploadedBy := tok.CreatedBy
|
||||
item, err := svc.Upload(r.Context(), db, bucket, UploadInput{
|
||||
FileName: tok.ExpectedFilename,
|
||||
Body: r.Body,
|
||||
FolderID: tok.FolderID,
|
||||
Alt: r.URL.Query().Get("alt"),
|
||||
Title: r.URL.Query().Get("title"),
|
||||
Caption: r.URL.Query().Get("caption"),
|
||||
UploadedBy: &uploadedBy,
|
||||
MaxBytes: limit,
|
||||
FileName: tok.ExpectedFilename,
|
||||
Body: r.Body,
|
||||
FolderID: tok.FolderID,
|
||||
Alt: r.URL.Query().Get("alt"),
|
||||
Title: r.URL.Query().Get("title"),
|
||||
Caption: r.URL.Query().Get("caption"),
|
||||
UploadedBy: &uploadedBy,
|
||||
MaxBytes: limit,
|
||||
ExpectedContentType: tok.ExpectedContentType,
|
||||
})
|
||||
if err != nil {
|
||||
var maxErr *http.MaxBytesError
|
||||
|
||||
Reference in New Issue
Block a user