[#164] serve common media files inline and fix svg content-type

This commit is contained in:
Gani Georgiev
2022-07-21 12:56:17 +03:00
parent 1a5180d7d3
commit 5d8fc939e2
15 changed files with 138 additions and 57 deletions
+6 -1
View File
@@ -7,6 +7,7 @@ import (
"mime/multipart"
"net/http"
"path/filepath"
"regexp"
"github.com/pocketbase/pocketbase/tools/security"
)
@@ -15,6 +16,8 @@ import (
// will be used when parsing a form request body.
const DefaultMaxMemory = 32 << 20 // 32mb
var extensionInvalidCharsRegex = regexp.MustCompile(`[^\w\.\*\-\+\=\#]+`)
// UploadedFile defines a single multipart uploaded file instance.
type UploadedFile struct {
name string
@@ -65,8 +68,10 @@ func FindUploadedFiles(r *http.Request, key string) ([]*UploadedFile, error) {
return nil, err
}
ext := extensionInvalidCharsRegex.ReplaceAllString(filepath.Ext(fh.Filename), "")
result[i] = &UploadedFile{
name: fmt.Sprintf("%s%s", security.RandomString(32), filepath.Ext(fh.Filename)),
name: fmt.Sprintf("%s%s", security.RandomString(32), ext),
header: fh,
bytes: buf.Bytes(),
}