From 895d29adf18fcf6a334839aead46bdb4bd9dbbec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma <roeland@famdouma.nl> Date: Wed, 8 Jul 2015 15:49:53 +0200 Subject: [PATCH] Move mimetypemapping.json to mimetypemapping.dist.json This allows users to create their own mapping file to extend our current mappings. This makes sure that custom mappings are not lost on OC upgrades. --- ...mimetypemapping.json => mimetypemapping.dist.json} | 3 +++ lib/private/helper.php | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) rename config/{mimetypemapping.json => mimetypemapping.dist.json} (97%) diff --git a/config/mimetypemapping.json b/config/mimetypemapping.dist.json similarity index 97% rename from config/mimetypemapping.json rename to config/mimetypemapping.dist.json index 49f3d8c9a1..48ec4a56da 100644 --- a/config/mimetypemapping.json +++ b/config/mimetypemapping.dist.json @@ -3,6 +3,9 @@ "_comment2": "The first index in the mime type array is the assumed correct mimetype", "_comment3": "and the second (if present] is a secure alternative", + "_comment4": "Any changes you make here will be overwritten on an update of ownCloud", + "_comment5": "Put any custom mappings in a new file mimetypemapping.json in this directory", + "3gp": ["video/3gpp"], "7z": ["application/x-7z-compressed"], diff --git a/lib/private/helper.php b/lib/private/helper.php index abe1e42ecb..09b319e90c 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -424,8 +424,15 @@ class OC_Helper { */ static public function getMimetypeDetector() { if (!self::$mimetypeDetector) { - $file = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); - $mimetypemapping = get_object_vars(json_decode($file)); + $dist = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.dist.json'); + $mimetypemapping = get_object_vars(json_decode($dist)); + + //Check if need to load custom mappings + if (file_exists(OC::$SERVERROOT . '/config/mimetypemapping.json')) { + $custom = file_get_contents(OC::$SERVERROOT . '/config/mimetypemapping.json'); + $custom_mapping = get_object_vars(json_decode($custom)); + $mimetypemapping = array_merge($mimetypemapping, $custom_mapping); + } self::$mimetypeDetector = new \OC\Files\Type\Detection(); self::$mimetypeDetector->registerTypeArray($mimetypemapping); -- GitLab