Skip to content

A self-hosted media server and file management system

feat: ui to set download privacy settings

aminnausin637ceddb8ea2
diff --git a/resources/js/components/cards/data/LibraryCard.vue b/resources/js/components/cards/data/LibraryCard.vue
index 01f6eeb6..770a2920 100644
--- a/resources/js/components/cards/data/LibraryCard.vue
+++ b/resources/js/components/cards/data/LibraryCard.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { CategoryResource, FolderResource } from '@/types/resources';
-import { startScanFilesTask, startVerifyFilesTask, toggleCategoryPrivacy } from '@/service/siteAPI';
+import { setLibraryDownloadSettings, startScanFilesTask, startVerifyFilesTask, toggleCategoryPrivacy } from '@/service/siteAPI';
import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { computed, ref, useTemplateRef, watch } from 'vue';
import { useQueryClient } from '@tanstack/vue-query';
@@ -13,6 +13,7 @@ import LibraryCardMenu from '@/components/menus/LibraryCardMenu.vue';
import LazyImage from '@/components/lazy/LazyImage.vue';
import ProiconsMoreVertical from '~icons/proicons/more-vertical';
+import TablerDownload from '~icons/tabler/download';
import ProiconsLock from '~icons/proicons/lock';
const props = defineProps<{ data?: CategoryResource }>();
@@ -86,6 +87,42 @@ const handleTogglePrivacy = async (id: number, currentValue: boolean) => {
}
};
+const handleToggleDownloads = async (id: number, currentValue: boolean) => {
+ if (processing.value || !props.data?.id || currentValue !== props.data.allow_downloads) return;
+
+ try {
+ processing.value = true;
+
+ await setLibraryDownloadSettings(id, { allow_downloads: !currentValue });
+ await queryClient.invalidateQueries({ queryKey: ['categories'] });
+
+ toast.success(`${currentValue ? 'Disabled' : 'Enabled'} Library Downloads.`);
+ processing.value = false;
+ } catch (error) {
+ toast('Failure', { type: 'danger', description: 'Unable to set download settings.' });
+ console.error(error);
+ processing.value = false;
+ }
+};
+
+const handleToggleDownloadPrivacy = async (id: number, currentValue: boolean) => {
+ if (processing.value || !props.data?.id || currentValue !== props.data.require_login_for_downloads) return;
+
+ try {
+ processing.value = true;
+
+ await setLibraryDownloadSettings(id, { require_login_for_downloads: !currentValue });
+ await queryClient.invalidateQueries({ queryKey: ['categories'] });
+
+ toast.success(`${currentValue ? 'Disabled' : 'Enabled'} Library Downloads for Guest Users.`);
+ processing.value = false;
+ } catch (error) {
+ toast('Failure', { type: 'danger', description: 'Unable to set download settings.' });
+ console.error(error);
+ processing.value = false;
+ }
+};
+
watch(
() => props.data,
() => {
@@ -105,13 +142,18 @@ watch(
:src="handleStorageURL(defaultFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
alt="Folder Cover Art"
/>
- <span class="ring-primary/90 absolute inset-0 h-full w-full rounded-t-xl p-2.5 transition duration-(--duration-input) ease-in-out ring-inset hover:ring-2">
+ <span
+ class="ring-primary/90 absolute inset-0 flex h-full w-full flex-col items-end gap-2 rounded-t-xl p-2.5 transition duration-(--duration-input) ease-in-out ring-inset hover:ring-2"
+ >
+ <div v-show="data?.is_private" class="bg-surface-2 text-primary dark:text-foreground-0 ring-r-button size-7 shrink-0 rounded-full p-1 ring-1" title="is private">
+ <ProiconsLock class="size-5" />
+ </div>
<div
- v-show="data?.is_private"
- class="bg-surface-2 text-primary dark:text-foreground-0 ring-r-button ml-auto size-7 shrink-0 rounded-full p-1 ring-1"
- title="is private"
+ v-show="data?.allow_downloads"
+ class="bg-surface-2 text-primary dark:text-foreground-0 ring-r-button size-7 shrink-0 rounded-full p-1 pt-0.5 ring-1"
+ title="is downloadable"
>
- <ProiconsLock class="size-5" />
+ <TablerDownload class="size-5" />
</div>
</span>
</RouterLink>
@@ -132,6 +174,8 @@ watch(
:handle-set-default-folder="handleSetDefaultFolder"
:handle-start-scan="handleStartScan"
:handle-toggle-privacy="handleTogglePrivacy"
+ :handle-toggle-downloads="handleToggleDownloads"
+ :handle-toggle-download-privacy="handleToggleDownloadPrivacy"
/>
</template>
</BasePopover>
diff --git a/resources/js/components/cards/data/LibraryFolderCard.vue b/resources/js/components/cards/data/LibraryFolderCard.vue
index 4e7ce62f..cfac8f71 100644
--- a/resources/js/components/cards/data/LibraryFolderCard.vue
+++ b/resources/js/components/cards/data/LibraryFolderCard.vue
@@ -2,18 +2,51 @@
import type { FolderResource } from '@/types/resources';
import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
-import { useTemplateRef } from 'vue';
+import { computed, ref, useTemplateRef } from 'vue';
+import { setSeriesDownloadSettings } from '@/service/siteAPI';
+import { useDashboardStore } from '@/stores/DashboardStore';
+import { useQueryClient } from '@tanstack/vue-query';
import { BasePopover } from '@/components/cedar-ui/popover';
+import { storeToRefs } from 'pinia';
import { ButtonIcon } from '@/components/cedar-ui/button';
+import { toast } from '@aminnausin/cedar-ui';
import LibraryFolderCardMenu from '@/components/menus/LibraryFolderCardMenu.vue';
import LazyImage from '@/components/lazy/LazyImage.vue';
import ProiconsMoreVertical from '~icons/proicons/more-vertical';
+import TablerDownload from '~icons/tabler/download';
import CircumShare1 from '~icons/circum/share-1';
-defineProps<{ data: FolderResource }>();
+const { stateLibraryId, stateLibraries } = storeToRefs(useDashboardStore());
+
+const props = defineProps<{ data: FolderResource }>();
const popover = useTemplateRef('popover');
+
+const queryClient = useQueryClient();
+const processing = ref(false);
+
+const stateLibraryIsDownloadable = computed(() => {
+ return stateLibraries.value.find((lib) => lib.id === stateLibraryId.value)?.allow_downloads ?? false;
+});
+
+const handleToggleDownloads = async (id: number, currentValue: boolean) => {
+ if (processing.value || !props.data?.id || currentValue !== props.data.series?.allow_downloads) return;
+
+ try {
+ processing.value = true;
+
+ await setSeriesDownloadSettings(id, { allow_downloads: !currentValue });
+ await queryClient.invalidateQueries({ queryKey: ['libraryFolders', stateLibraryId.value] });
+
+ toast.success(`${currentValue ? 'Disabled' : 'Enabled'} Folder Downloads.`);
+ processing.value = false;
+ } catch (error) {
+ toast('Failure', { type: 'danger', description: 'Unable to set download settings.' });
+ console.error(error);
+ processing.value = false;
+ }
+};
</script>
<template>
@@ -25,11 +58,21 @@ const popover = useTemplateRef('popover');
alt="Folder Cover Art"
/>
- <span class="ring-primary/90 absolute top-0 left-0 h-full w-full rounded-t-md ring-inset hover:ring-2"></span>
+ <span
+ class="ring-primary/90 absolute inset-0 flex h-full w-full flex-col items-end gap-2 rounded-t-xl p-2.5 transition duration-(--duration-input) ease-in-out ring-inset hover:ring-2"
+ >
+ <div
+ v-show="data.series?.allow_downloads && stateLibraryIsDownloadable"
+ class="bg-surface-2 text-primary dark:text-foreground-0 ring-r-button size-7 shrink-0 rounded-full p-1 pt-0.5 ring-1"
+ title="is downloadable"
+ >
+ <TablerDownload class="size-5" />
+ </div>
+ </span>
</RouterLink>
<section class="flex h-full flex-1 flex-col gap-2 p-3" v-if="data">
<div class="xs:flex-nowrap flex flex-wrap items-start justify-between gap-1">
- <h3 class="group-hover:text-primary capitalize">{{ data.id }} - {{ data?.title ?? data?.name }}</h3>
+ <h3 class="group-hover:text-primary capitalize">{{ data.id }} - {{ data?.title ?? data?.name }} {{ stateLibraryIsDownloadable }}</h3>
<span class="flex gap-2 text-sm *:h-6">
<ButtonIcon :title="'Open Folder In New Tab'" :to="`/${encodeURI(data.path)}`" :target="'_blank'" class="size-6 p-0">
<template #icon><CircumShare1 class="size-4" /></template>
@@ -39,7 +82,14 @@ const popover = useTemplateRef('popover');
<ProiconsMoreVertical class="size-4" />
</template>
<template #content>
- <LibraryFolderCardMenu :data="data" :handle-close-popover="popover?.handleClose" @clickAction="$emit('clickAction', data?.id)" />
+ <LibraryFolderCardMenu
+ :data="data"
+ :processing="processing"
+ :library-downloads-enabled="stateLibraryIsDownloadable"
+ :handle-close-popover="popover?.handleClose"
+ :handle-toggle-downloads="handleToggleDownloads"
+ @clickAction="$emit('clickAction', data?.id)"
+ />
</template>
</BasePopover>
</span>
diff --git a/resources/js/components/menus/LibraryCardMenu.vue b/resources/js/components/menus/LibraryCardMenu.vue
index 8ebeafb2..13f01247 100644
--- a/resources/js/components/menus/LibraryCardMenu.vue
+++ b/resources/js/components/menus/LibraryCardMenu.vue
@@ -12,6 +12,9 @@ import CircumFolderOn from '~icons/circum/folder-on';
import ProiconsDelete from '~icons/proicons/delete';
import ProiconsLock from '~icons/proicons/lock';
+import TablerDownloadOff from '~icons/tabler/download-off';
+import TablerDownload from '~icons/tabler/download';
+
const props = withDefaults(
defineProps<{
data?: CategoryResource;
@@ -21,6 +24,8 @@ const props = withDefaults(
handleSetDefaultFolder: (newFolder: { value: number }) => Promise<void>;
handleStartScan: (verifyOnly?: boolean) => Promise<void>;
handleTogglePrivacy: (id: number, currentValue: boolean) => Promise<void>;
+ handleToggleDownloads: (id: number, currentValue: boolean) => Promise<void>;
+ handleToggleDownloadPrivacy: (id: number, currentValue: boolean) => Promise<void>;
}>(),
{},
);
@@ -65,6 +70,22 @@ const props = withDefaults(
<p class="flex-1 text-start">Manage Folders</p>
<template #icon> <CircumFolderOn class="order-1 size-4" /></template>
</ButtonText>
+
+ <ButtonText :title="'Toggle Downloads'" @click="handleToggleDownloads(data.id, data.allow_downloads)" :disabled="processing">
+ <p class="flex-1 text-start">{{ data.allow_downloads ? 'Disable Downloads' : 'Enable Downloads' }}</p>
+ <template #icon> <TablerDownloadOff v-if="!data.allow_downloads" class="size-4" /> <TablerDownload v-else class="size-4" /></template>
+ </ButtonText>
+
+ <ButtonText
+ v-if="data.allow_downloads"
+ :title="`${data.require_login_for_downloads ? 'Enable' : 'Disable'} Guest Downloads`"
+ @click="handleToggleDownloadPrivacy(data.id, data.require_login_for_downloads)"
+ :disabled="processing"
+ >
+ <p class="flex-1 text-start">{{ data.require_login_for_downloads ? 'Guest Downloads' : 'Private Downloads' }}</p>
+ <template #icon> <TablerDownloadOff v-if="!data.require_login_for_downloads" class="size-4" /> <TablerDownload v-else class="size-4" /></template>
+ </ButtonText>
+
<ButtonText
:title="'Toggle Privacy'"
@click="handleTogglePrivacy(data.id, data.is_private ?? false)"
diff --git a/resources/js/components/menus/LibraryFolderCardMenu.vue b/resources/js/components/menus/LibraryFolderCardMenu.vue
index f6db376a..4293c8f9 100644
--- a/resources/js/components/menus/LibraryFolderCardMenu.vue
+++ b/resources/js/components/menus/LibraryFolderCardMenu.vue
@@ -1,11 +1,24 @@
<script setup lang="ts">
+import type { FolderResource } from '@/contracts/media';
+
import { ButtonText } from '@/components/cedar-ui/button';
import { FLAGS } from '@/config/featureFlags';
+import TablerDownloadOff from '~icons/tabler/download-off';
+import TablerDownload from '~icons/tabler/download';
import ProiconsDelete from '~icons/proicons/delete';
-import ProiconsLock from '~icons/proicons/lock';
import CircumEdit from '~icons/circum/edit';
-const props = withDefaults(defineProps<{ handleClosePopover?: () => void }>(), {});
+
+const props = withDefaults(
+ defineProps<{
+ handleClosePopover?: () => void;
+ data: FolderResource;
+ processing: boolean;
+ libraryDownloadsEnabled: boolean;
+ handleToggleDownloads: (id: number, currentValue: boolean) => Promise<void>;
+ }>(),
+ {},
+);
</script>
<template>
@@ -28,10 +41,17 @@ const props = withDefaults(defineProps<{ handleClosePopover?: () => void }>(), {
<p class="flex-1 text-start">Edit Folder</p>
<template #icon> <CircumEdit class="size-4" /></template>
</ButtonText>
- <ButtonText title="Manage Metadata Settings" disabled>
- <p class="flex-1 text-start">Manage Metadata</p>
- <template #icon> <ProiconsLock class="size-4" /></template>
+
+ <ButtonText
+ v-if="libraryDownloadsEnabled && data.series"
+ :title="'Toggle Downloads'"
+ @click="handleToggleDownloads(data.series.id, data.series.allow_downloads ?? false)"
+ :disabled="processing"
+ >
+ <p class="flex-1 text-start">{{ data.series?.allow_downloads ? 'Disable Downloads' : 'Enable Downloads' }}</p>
+ <template #icon> <TablerDownload v-if="data.series?.allow_downloads" class="size-4" /> <TablerDownloadOff v-else class="size-4" /></template>
</ButtonText>
+
<ButtonText v-if="FLAGS.USE_REMOVABLE_FOLDERS" class="text-danger dark:text-foreground-0 dark:bg-danger-3! dark:hocus:bg-danger!" title="Remove From Server" disabled>
<p class="flex-1 text-start">Remove Folder</p>
<template #icon> <ProiconsDelete class="size-4" /></template>