Skip to content

Commit 75237a7

Browse files
committed
🔧 Config injected supported file extensions and filename lengths.
1 parent d662c61 commit 75237a7

File tree

6 files changed

+77
-25
lines changed

6 files changed

+77
-25
lines changed

api/r0/upload_async.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
2424
mediaId := _routers.GetParam("mediaId", r)
2525
filename := filepath.Base(r.URL.Query().Get("filename"))
2626
// GK CUSTOMIZATION: Sanitize the filename
27-
if len(filename) > 24 {
27+
if len(filename) > rctx.Config.Uploads.MaxFilenameLength {
2828
return &_responses.ErrorResponse{
2929
Code: common.ErrCodeBadRequest,
3030
Message: "Filename too long.",
@@ -50,7 +50,7 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
5050
InternalCode: common.ErrCodeBadRequest,
5151
}
5252
}
53-
if !util.IsSupportedFileType(kind.Extension) {
53+
if !util.IsSupportedFileType(kind.Extension, rctx.Config.Uploads.SupportedFileTypes) {
5454
return &_responses.ErrorResponse{
5555
Code: common.ErrCodeBadRequest,
5656
Message: "Unsupported file type.",

api/r0/upload_sync.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type MediaUploadedResponse struct {
2727
func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
2828
filename := filepath.Base(r.URL.Query().Get("filename"))
2929
// GK CUSTOMIZATION: Sanitize the filename
30-
if len(filename) > 24 {
30+
if len(filename) > rctx.Config.Uploads.MaxFilenameLength {
3131
return &_responses.ErrorResponse{
3232
Code: common.ErrCodeBadRequest,
3333
Message: "Filename too long.",
@@ -53,7 +53,7 @@ func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimet
5353
InternalCode: common.ErrCodeBadRequest,
5454
}
5555
}
56-
if !util.IsSupportedFileType(kind.Extension) {
56+
if !util.IsSupportedFileType(kind.Extension, rctx.Config.Uploads.SupportedFileTypes) {
5757
return &_responses.ErrorResponse{
5858
Code: common.ErrCodeBadRequest,
5959
Message: "Unsupported file type.",

common/config/conf_min_shared.go

+34
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,40 @@ func NewDefaultMinimumRepoConfig() MinimumRepoConfig {
2020
TargetBytesPerPart: 209715200, // 200mb
2121
},
2222
Uploads: UploadsConfig{
23+
MaxFilenameLength: 24,
24+
SupportedFileTypes: []string{
25+
"docx",
26+
"doc",
27+
"xlsx",
28+
"xls",
29+
"odt",
30+
"ods",
31+
"odp",
32+
"csv",
33+
"txt",
34+
"pdf",
35+
"ppr",
36+
"pptx",
37+
"ppt",
38+
"jpg",
39+
"png",
40+
"gif",
41+
"heic",
42+
"bmp",
43+
"webp",
44+
"svg",
45+
"mpeg4",
46+
"mpeg",
47+
"h264",
48+
"webm",
49+
"mkv",
50+
"avi",
51+
"mov",
52+
"mp3",
53+
"wav",
54+
"flac",
55+
"zip",
56+
},
2357
MaxSizeBytes: 104857600, // 100mb
2458
MinSizeBytes: 100,
2559
ReportedMaxSizeBytes: 0,

common/config/models_domain.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ type QuotasConfig struct {
1919
}
2020

2121
type UploadsConfig struct {
22+
MaxFilenameLength int `yaml:"maxFilenameLength"`
23+
SupportedFileTypes []string `yaml:"supportedFileTypes"`
2224
MaxSizeBytes int64 `yaml:"maxBytes"`
2325
MinSizeBytes int64 `yaml:"minBytes"`
2426
ReportedMaxSizeBytes int64 `yaml:"reportedMaxBytes"`

config.sample.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,42 @@ archiving:
232232

233233
# The file upload settings for the media repository
234234
uploads:
235+
# GK CUSTOMIZATION
236+
maxFilenameLength: 24
237+
supportedFileTypes:
238+
- "docx"
239+
- "doc"
240+
- "xlsx"
241+
- "xls"
242+
- "odt"
243+
- "ods"
244+
- "odp"
245+
- "csv"
246+
- "txt"
247+
- "pdf"
248+
- "ppr"
249+
- "pptx"
250+
- "ppt"
251+
- "jpg"
252+
- "png"
253+
- "gif"
254+
- "heic"
255+
- "bmp"
256+
- "webp"
257+
- "svg"
258+
- "mpeg4"
259+
- "mpeg"
260+
- "h264"
261+
- "webm"
262+
- "mkv"
263+
- "avi"
264+
- "mov"
265+
- "mp3"
266+
- "wav"
267+
- "flac"
268+
- "zip"
269+
##################
270+
235271
# The maximum individual file size a user can upload.
236272
maxBytes: 104857600 # 100MB default, 0 to disable
237273

util/mxc.go

+1-21
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,7 @@ func MxcUri(origin string, mediaId string) string {
44
return "mxc://" + origin + "/" + mediaId
55
}
66

7-
// GK CUSTOMIZATION: Supported file types
8-
var supportedFileTypes = []string{
9-
"docx",
10-
"doc",
11-
"xlsx",
12-
"csv",
13-
"txt",
14-
"pdf",
15-
"ppr",
16-
"ppt",
17-
"jpg",
18-
"png",
19-
"gif",
20-
"heic",
21-
"mpeg4",
22-
"mpeg",
23-
"h264",
24-
"avi",
25-
}
26-
27-
func IsSupportedFileType(fileType string) bool {
7+
func IsSupportedFileType(fileType string, supportedFileTypes []string) bool {
288
for _, v := range supportedFileTypes {
299
if v == fileType {
3010
return true

0 commit comments

Comments
 (0)