summaryrefslogtreecommitdiffstats
path: root/apps/theming
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-08-02 12:05:17 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-08-03 11:49:45 +0200
commit0a046844f657a10f993e35473f3f0bac557db516 (patch)
treeb883ad6bc7b4d8fd3db78b48ee9505a35d5da80a /apps/theming
parentc7c94a39f779cde2f142ba9e057e633f76287790 (diff)
downloadnextcloud-server-0a046844f657a10f993e35473f3f0bac557db516.tar.gz
nextcloud-server-0a046844f657a10f993e35473f3f0bac557db516.zip
feat(theming): add mime accept in Theming image file picker
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming')
-rw-r--r--apps/theming/lib/ImageManager.php2
-rw-r--r--apps/theming/lib/Settings/Admin.php7
-rw-r--r--apps/theming/src/components/admin/FileInputField.vue8
3 files changed, 16 insertions, 1 deletions
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php
index f609e5ef9d4..c987e7f4a9b 100644
--- a/apps/theming/lib/ImageManager.php
+++ b/apps/theming/lib/ImageManager.php
@@ -323,7 +323,7 @@ class ImageManager {
* @param string $key The image key, e.g. "favicon"
* @return string[]
*/
- private function getSupportedUploadImageFormats(string $key): array {
+ public function getSupportedUploadImageFormats(string $key): array {
$supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
if ($key !== 'favicon' || $this->shouldReplaceIcons() === true) {
diff --git a/apps/theming/lib/Settings/Admin.php b/apps/theming/lib/Settings/Admin.php
index 0f0d85c147d..ee46e62114d 100644
--- a/apps/theming/lib/Settings/Admin.php
+++ b/apps/theming/lib/Settings/Admin.php
@@ -28,6 +28,7 @@
namespace OCA\Theming\Settings;
use OCA\Theming\AppInfo\Application;
+use OCA\Theming\Controller\ThemingController;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Http\TemplateResponse;
@@ -75,6 +76,11 @@ class Admin implements IDelegatedSettings {
$errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
}
+ $allowedMimeTypes = array_reduce(ThemingController::VALID_UPLOAD_KEYS, function($carry, $key) {
+ $carry[$key] = $this->imageManager->getSupportedUploadImageFormats($key);
+ return $carry;
+ }, []);
+
$this->initialState->provideInitialState('adminThemingParameters', [
'isThemable' => $themable,
'notThemableErrorMessage' => $errorMessage,
@@ -92,6 +98,7 @@ class Admin implements IDelegatedSettings {
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
+ 'allowedMimeTypes' => $allowedMimeTypes,
]);
Util::addScript($this->appName, 'admin-theming');
diff --git a/apps/theming/src/components/admin/FileInputField.vue b/apps/theming/src/components/admin/FileInputField.vue
index 8af17711141..3d6fda9ec70 100644
--- a/apps/theming/src/components/admin/FileInputField.vue
+++ b/apps/theming/src/components/admin/FileInputField.vue
@@ -71,6 +71,7 @@
</NcNoteCard>
<input ref="input"
+ :accept="acceptMime"
type="file"
@change="onChange">
</div>
@@ -79,6 +80,7 @@
<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
+import { loadState } from '@nextcloud/initial-state'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
@@ -89,6 +91,10 @@ import Upload from 'vue-material-design-icons/Upload.vue'
import FieldMixin from '../../mixins/admin/FieldMixin.js'
+const {
+ allowedMimeTypes,
+} = loadState('theming', 'adminThemingParameters', {})
+
export default {
name: 'FileInputField',
@@ -135,6 +141,8 @@ export default {
data() {
return {
showLoading: false,
+ acceptMime: (allowedMimeTypes[this.name]
+ || ['image/jpeg', 'image/png', 'image/gif', 'image/webp']).join(','),
}
},