diff options
author | Adam Szatyin <szatyinadam@gmail.com> | 2021-05-10 22:38:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 16:38:08 -0400 |
commit | d86d12332269c0d8b13ab2ea70c688640e44946e (patch) | |
tree | ce6ba2d457a53894ee1e73896417f8bbe59232ca /modules | |
parent | 2f65c6b2f03d4b8908422e63788d8775b5d64a8f (diff) | |
download | gitea-d86d12332269c0d8b13ab2ea70c688640e44946e.tar.gz gitea-d86d12332269c0d8b13ab2ea70c688640e44946e.zip |
Add mimetype mapping settings (#15133)
* Fix APK's Content-Type header
* Fix case sensitive comparison
* Add custom mime type mapping for downloadable files
* Add documentation for MIME type mapping
* Rename download.mimetype.mapping configuration to repository.mimetype_mapping
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/setting/mime_type_map.go | 31 | ||||
-rw-r--r-- | modules/setting/setting.go | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/modules/setting/mime_type_map.go b/modules/setting/mime_type_map.go new file mode 100644 index 0000000000..5c1fc7f71a --- /dev/null +++ b/modules/setting/mime_type_map.go @@ -0,0 +1,31 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package setting + +import "strings" + +var ( + // MimeTypeMap defines custom mime type mapping settings + MimeTypeMap = struct { + Enabled bool + Map map[string]string + }{ + Enabled: false, + Map: map[string]string{}, + } +) + +func newMimeTypeMap() { + sec := Cfg.Section("repository.mimetype_mapping") + keys := sec.Keys() + m := make(map[string]string, len(keys)) + for _, key := range keys { + m[strings.ToLower(key.Name())] = key.Value() + } + MimeTypeMap.Map = m + if len(keys) > 0 { + MimeTypeMap.Enabled = true + } +} diff --git a/modules/setting/setting.go b/modules/setting/setting.go index aef0d86700..4244b55939 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1177,4 +1177,5 @@ func NewServices() { newTaskService() NewQueueService() newProject() + newMimeTypeMap() } |