From b2bb64e83d296c0054692ae6125d4e1b10a0cc30 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 22 May 2023 22:35:29 -0700 Subject: [PATCH] admin: allow preview configuration (close #587) Signed-off-by: Varun Patil --- lib/SystemConfigDefault.php | 6 ++- lib/Util.php | 10 +++- src/components/admin/AdminTypes.ts | 4 ++ src/components/admin/sections/FileSupport.vue | 52 +++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/lib/SystemConfigDefault.php b/lib/SystemConfigDefault.php index 311d14e6..b1709bf5 100644 --- a/lib/SystemConfigDefault.php +++ b/lib/SystemConfigDefault.php @@ -62,7 +62,11 @@ return [ // 1080 => 1080p (and so on) 'memories.video_default_quality' => '0', - // Preview providers for Nextcloud // Memories only provides an admin interface for these + // https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#previews 'enabledPreviewProviders' => [], + 'preview_max_x' => 4096, + 'preview_max_y' => 4096, + 'preview_max_memory' => 128, + 'preview_max_filesize_image' => 50, ]; diff --git a/lib/Util.php b/lib/Util.php index 08199761..06b51e68 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -370,6 +370,9 @@ class Util throw new \InvalidArgumentException("Invalid system config key: {$key}"); } + // Key belongs to memories namespace + $isAppKey = str_starts_with($key, Application::APPNAME.'.'); + // Check if the value has the correct type if (null !== $value && \gettype($value) !== \gettype($defaults[$key])) { $expected = \gettype($defaults[$key]); @@ -378,7 +381,12 @@ class Util throw new \InvalidArgumentException("Invalid type for system config {$key}, expected {$expected}, got {$got}"); } - if ($value === $defaults[$key] || null === $value) { + // Do not allow null for non-app keys + if (!$isAppKey && null === $value) { + throw new \InvalidArgumentException("Invalid value for system config {$key}, null is not allowed"); + } + + if ($isAppKey && ($value === $defaults[$key] || null === $value)) { $config->deleteSystemValue($key); } else { $config->setSystemValue($key, $value); diff --git a/src/components/admin/AdminTypes.ts b/src/components/admin/AdminTypes.ts index 941f7496..12c73042 100644 --- a/src/components/admin/AdminTypes.ts +++ b/src/components/admin/AdminTypes.ts @@ -24,6 +24,10 @@ export type ISystemConfig = { 'memories.vod.nvenc.scale': string; enabledPreviewProviders: string[]; + preview_max_x: number; + preview_max_y: number; + preview_max_memory: number; + preview_max_filesize_image: number; }; export type IBinaryStatus = 'ok' | 'not_found' | 'not_executable' | 'test_ok' | string; diff --git a/src/components/admin/sections/FileSupport.vue b/src/components/admin/sections/FileSupport.vue index 537993bd..95b72bcf 100644 --- a/src/components/admin/sections/FileSupport.vue +++ b/src/components/admin/sections/FileSupport.vue @@ -25,6 +25,43 @@ + +
+ + {{ t('memories', 'Max preview size (trade-off between quality and storage requirements).') }} + + {{ t('memories', 'Documentation.') }} + +
+ {{ size }}px + + + + + @@ -54,6 +91,8 @@ export default defineComponent({ name: t('memories', 'Videos (ffmpeg)'), }, }, + + previewSizes: [512, 1024, 2048, 4096, 8192], }), methods: { @@ -76,6 +115,19 @@ export default defineComponent({ this.update('enabledPreviewProviders'); }, + + async updatePreviewSize(size: number) { + this.update('preview_max_x', size); + await new Promise((resolve) => setTimeout(resolve, 1000)); // Hack to prevent config race + this.update('preview_max_y', size); + }, }, }); + +