From 2a8c6dbba51f30020d4046d764608349a4abb4ef Mon Sep 17 00:00:00 2001 From: ildyria Date: Wed, 16 Oct 2024 10:00:18 +0200 Subject: [PATCH] Lychee SE in easy settings --- .../Controllers/Admin/SettingsController.php | 2 +- .../components/forms/users/CreateEditUser.vue | 3 +- .../js/components/settings/EasySettings.vue | 99 ++++++++++- .../js/composables/preview/getPreviewInfo.ts | 65 +++++++ resources/js/menus/LeftMenu.vue | 162 ++++++++++-------- resources/js/views/Statistics.vue | 18 +- 6 files changed, 274 insertions(+), 75 deletions(-) create mode 100644 resources/js/composables/preview/getPreviewInfo.ts diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index 89558a99e6..1d4c14537d 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -20,7 +20,7 @@ class SettingsController extends Controller public function getAll(GetAllConfigsRequest $request): ConfigCollectionResource { $editable_configs = Configs::query() - ->when(!$request->is_se(), fn ($q) => $q->where('level', '=', 0)) + ->when(!$request->is_se() && !Configs::getValueAsBool('enable_se_preview'), fn ($q) => $q->where('level', '=', 0)) ->orderBy('cat', 'asc')->get(); return new ConfigCollectionResource($editable_configs); diff --git a/resources/js/components/forms/users/CreateEditUser.vue b/resources/js/components/forms/users/CreateEditUser.vue index 04a58b4523..1ca0f22f29 100644 --- a/resources/js/components/forms/users/CreateEditUser.vue +++ b/resources/js/components/forms/users/CreateEditUser.vue @@ -20,7 +20,7 @@
- +
@@ -71,6 +71,7 @@ import Dialog from "primevue/dialog"; import { useLycheeStateStore } from "@/stores/LycheeState"; import { storeToRefs } from "pinia"; import Textarea from "../basic/Textarea.vue"; +import SETag from "@/components/icons/SETag.vue"; const lycheeStore = useLycheeStateStore(); const { is_se_preview_enabled, is_se_enabled } = storeToRefs(lycheeStore); diff --git a/resources/js/components/settings/EasySettings.vue b/resources/js/components/settings/EasySettings.vue index 91370947c2..39c1889207 100644 --- a/resources/js/components/settings/EasySettings.vue +++ b/resources/js/components/settings/EasySettings.vue @@ -11,6 +11,49 @@
+
+ +

+ Get exclusive features and support the development of Lychee. Unlock the + SE edition. +

+
+
+ + + + + Invalid license key +
+ +
+

+ + +

+

+ + + If enabled, the only way to register your license key will be via + the More Tab above. Changes are applied on page reload. +

+

In order to import photos from your Dropbox, you need a valid drop-ins app key from their website. @@ -23,7 +66,9 @@ - +

@@ -186,6 +231,10 @@ import SelectField from "../forms/settings/SelectField.vue"; import BoolField from "../forms/settings/BoolField.vue"; import { useToast } from "primevue/usetoast"; import Textarea from "../forms/basic/Textarea.vue"; +import { useLycheeStateStore } from "@/stores/LycheeState"; +import { storeToRefs } from "pinia"; +import InputText from "../forms/basic/InputText.vue"; +import MaintenanceService from "@/services/maintenance-service"; const toast = useToast(); @@ -214,9 +263,19 @@ const location_decoding = ref(undefined); const location_show_public = ref(undefined); +const disable_se_call_for_actions = ref(undefined); +const enable_se_preview = ref(undefined); +const licenseKey = ref(undefined); +const licenseKeyIsInvValid = ref(false); +const isValidRegistrationForm = computed(() => { + return licenseKey.value !== undefined && licenseKey.value !== ""; +}); + const css = ref(undefined); const js = ref(undefined); // Map stuff +const lycheeStore = useLycheeStateStore(); +const { is_se_preview_enabled, is_se_enabled, is_se_info_hidden } = storeToRefs(lycheeStore); function save(configKey: string, value: string) { SettingsService.setConfigs({ @@ -268,6 +327,10 @@ function load() { location_decoding.value = configurations.find((config) => config.key === "location_decoding"); location_show.value = configurations.find((config) => config.key === "location_show"); location_show_public.value = configurations.find((config) => config.key === "location_show_public"); + + disable_se_call_for_actions.value = configurations.find((config) => config.key === "disable_se_call_for_actions")?.value === "1"; + enable_se_preview.value = configurations.find((config) => config.key === "enable_se_preview")?.value === "1"; + licenseKey.value = configurations.find((config) => config.key === "license_key")?.value ?? ""; }); SettingsService.getCss() @@ -301,6 +364,40 @@ function saveDarkMode(_configKey: string, value: string) { } } +function savePreview() { + save("enable_se_preview", enable_se_preview.value ? "1" : "0"); +} + +function saveHideC4A() { + save("disable_se_call_for_actions", disable_se_call_for_actions.value ? "1" : "0"); +} + +function register() { + if (licenseKey.value === undefined || licenseKey.value === "") { + return; + } + + MaintenanceService.register(licenseKey.value) + .then((response) => { + if (response.data.success) { + is_se_enabled.value = true; + is_se_preview_enabled.value = false; + is_se_info_hidden.value = false; + toast.add({ + severity: "success", + summary: "Thank you for your support.", + detail: "Reload your page for full functionalities.", + life: 5000, + }); + } else { + licenseKeyIsInvValid.value = true; + } + }) + .catch(() => { + licenseKeyIsInvValid.value = true; + }); +} + function saveCss() { SettingsService.setCss(css.value ?? "") .then(() => { diff --git a/resources/js/composables/preview/getPreviewInfo.ts b/resources/js/composables/preview/getPreviewInfo.ts new file mode 100644 index 0000000000..03a7f39cfa --- /dev/null +++ b/resources/js/composables/preview/getPreviewInfo.ts @@ -0,0 +1,65 @@ +import AlbumService from "@/services/album-service"; + +export function usePreviewData() { + function getSizeVariantSizeData(): App.Http.Resources.Statistics.Sizes[] { + return [ + { + type: 0, + label: "Original", + size: Math.floor(Math.random() * 1000_000_000_000), + }, + { + type: 1, + label: "Medium HiDPI", + size: Math.floor(Math.random() * 1_000_000_000), + }, + { + type: 2, + label: "Medium", + size: Math.floor(Math.random() * 100_000_000_000), + }, + { + type: 4, + label: "Thumb", + size: Math.floor(Math.random() * 10_000_000_000), + }, + { + type: 5, + label: "Square thumb HiDPI", + size: Math.floor(Math.random() * 1_000_000_000), + }, + { + type: 6, + label: "Square thumb", + size: Math.floor(Math.random() * 1_000_000_000), + }, + ]; + } + + function getAlbumSizeData(): Promise { + let data = [] as App.Http.Resources.Statistics.Album[]; + + return AlbumService.getTargetListAlbums(null).then((response) => { + for (let i = 0; i < response.data.length; i++) { + let album = response.data[i]; + data.push({ + username: "demo", + title: album.original, + is_nsfw: false, + left: 2 * i + 1, + right: 2 * i + 2, + num_photos: Math.floor(Math.random() * 100), + num_descendants: Math.floor(Math.random() * 100), + size: Math.floor(Math.random() * 1000000), + }); + } + + return data; + }); + } + + return { + getSizeVariantSizeData, + getAlbumSizeData, + }; +} diff --git a/resources/js/menus/LeftMenu.vue b/resources/js/menus/LeftMenu.vue index dc32dffa27..ee028caf23 100644 --- a/resources/js/menus/LeftMenu.vue +++ b/resources/js/menus/LeftMenu.vue @@ -1,6 +1,9 @@