Skip to content

Commit

Permalink
feat(theming): add mime accept in Theming image file picker
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 3, 2023
1 parent c7c94a3 commit 0a04684
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/theming/lib/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private function shouldOptimizeBackgroundImage(string $mimeType, int $contentSiz
* @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) {
Expand Down
7 changes: 7 additions & 0 deletions apps/theming/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +76,11 @@ public function getForm(): TemplateResponse {
$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,
Expand All @@ -92,6 +98,7 @@ public function getForm(): TemplateResponse {
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
'allowedMimeTypes' => $allowedMimeTypes,
]);

Util::addScript($this->appName, 'admin-theming');
Expand Down
8 changes: 8 additions & 0 deletions apps/theming/src/components/admin/FileInputField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
</NcNoteCard>

<input ref="input"
:accept="acceptMime"
type="file"
@change="onChange">
</div>
Expand All @@ -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'
Expand All @@ -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',
Expand Down Expand Up @@ -135,6 +141,8 @@ export default {
data() {
return {
showLoading: false,
acceptMime: (allowedMimeTypes[this.name]
|| ['image/jpeg', 'image/png', 'image/gif', 'image/webp']).join(','),
}
},
Expand Down
4 changes: 2 additions & 2 deletions dist/1929-1929.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/1929-1929.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/theming-admin-theming.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/theming-admin-theming.js.map

Large diffs are not rendered by default.

0 comments on commit 0a04684

Please sign in to comment.