mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(server,web): remove external path nonsense and make libraries admin-only (#7237)
* remove external path * open-api * make sql * move library settings to admin panel * Add documentation * show external libraries only * fix library list * make user library settings look good * fix test * fix tests * fix tests * can pick user for library * fix tests * fix e2e * chore: make sql * Use unauth exception * delete user library list * cleanup * fix e2e * fix await lint * chore: remove unused code * chore: cleanup * revert docs * fix: is admin stuff * table alignment --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
369acc7bea
commit
efa6efd200
63 changed files with 783 additions and 1111 deletions
|
|
@ -1,416 +0,0 @@
|
|||
<script lang="ts">
|
||||
import Icon from '$lib/components/elements/icon.svelte';
|
||||
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
|
||||
import { locale } from '$lib/stores/preferences.store';
|
||||
import { getBytesWithUnit } from '$lib/utils/byte-units';
|
||||
import { getContextMenuPosition } from '$lib/utils/context-menu';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import {
|
||||
LibraryType,
|
||||
createLibrary,
|
||||
deleteLibrary,
|
||||
getLibraries,
|
||||
getLibraryStatistics,
|
||||
removeOfflineFiles,
|
||||
scanLibrary,
|
||||
updateLibrary,
|
||||
type LibraryResponseDto,
|
||||
type LibraryStatsResponseDto,
|
||||
} from '@immich/sdk';
|
||||
import { mdiDatabase, mdiDotsVertical, mdiUpload } from '@mdi/js';
|
||||
import { onMount } from 'svelte';
|
||||
import { fade, slide } from 'svelte/transition';
|
||||
import Button from '../elements/buttons/button.svelte';
|
||||
import LibraryImportPathsForm from '../forms/library-import-paths-form.svelte';
|
||||
import LibraryRenameForm from '../forms/library-rename-form.svelte';
|
||||
import LibraryScanSettingsForm from '../forms/library-scan-settings-form.svelte';
|
||||
import ConfirmDialogue from '../shared-components/confirm-dialogue.svelte';
|
||||
import ContextMenu from '../shared-components/context-menu/context-menu.svelte';
|
||||
import MenuOption from '../shared-components/context-menu/menu-option.svelte';
|
||||
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
||||
import Portal from '../shared-components/portal/portal.svelte';
|
||||
|
||||
let libraries: LibraryResponseDto[] = [];
|
||||
|
||||
let stats: LibraryStatsResponseDto[] = [];
|
||||
let photos: number[] = [];
|
||||
let videos: number[] = [];
|
||||
let totalCount: number[] = [];
|
||||
let diskUsage: number[] = [];
|
||||
let diskUsageUnit: string[] = [];
|
||||
|
||||
let confirmDeleteLibrary: LibraryResponseDto | null = null;
|
||||
let deletedLibrary: LibraryResponseDto | null = null;
|
||||
|
||||
let editImportPaths: number | null;
|
||||
let editScanSettings: number | null;
|
||||
let renameLibrary: number | null;
|
||||
|
||||
let updateLibraryIndex: number | null;
|
||||
|
||||
let deleteAssetCount = 0;
|
||||
|
||||
let dropdownOpen: boolean[] = [];
|
||||
let showContextMenu = false;
|
||||
let contextMenuPosition = { x: 0, y: 0 };
|
||||
let selectedLibraryIndex = 0;
|
||||
let selectedLibrary: LibraryResponseDto | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
await readLibraryList();
|
||||
});
|
||||
|
||||
const closeAll = () => {
|
||||
editImportPaths = null;
|
||||
editScanSettings = null;
|
||||
renameLibrary = null;
|
||||
updateLibraryIndex = null;
|
||||
showContextMenu = false;
|
||||
|
||||
for (let index = 0; index < dropdownOpen.length; index++) {
|
||||
dropdownOpen[index] = false;
|
||||
}
|
||||
};
|
||||
|
||||
const showMenu = (event: MouseEvent, library: LibraryResponseDto, index: number) => {
|
||||
contextMenuPosition = getContextMenuPosition(event);
|
||||
showContextMenu = !showContextMenu;
|
||||
|
||||
selectedLibraryIndex = index;
|
||||
selectedLibrary = library;
|
||||
};
|
||||
|
||||
const onMenuExit = () => {
|
||||
showContextMenu = false;
|
||||
};
|
||||
const refreshStats = async (listIndex: number) => {
|
||||
stats[listIndex] = await getLibraryStatistics({ id: libraries[listIndex].id });
|
||||
photos[listIndex] = stats[listIndex].photos;
|
||||
videos[listIndex] = stats[listIndex].videos;
|
||||
totalCount[listIndex] = stats[listIndex].total;
|
||||
[diskUsage[listIndex], diskUsageUnit[listIndex]] = getBytesWithUnit(stats[listIndex].usage, 0);
|
||||
};
|
||||
|
||||
async function readLibraryList() {
|
||||
libraries = await getLibraries();
|
||||
|
||||
dropdownOpen.length = libraries.length;
|
||||
|
||||
for (let index = 0; index < libraries.length; index++) {
|
||||
await refreshStats(index);
|
||||
dropdownOpen[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
const handleCreate = async (libraryType: LibraryType) => {
|
||||
try {
|
||||
const createdLibrary = await createLibrary({
|
||||
createLibraryDto: { type: libraryType },
|
||||
});
|
||||
|
||||
notificationController.show({
|
||||
message: `Created library: ${createdLibrary.name}`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to create library');
|
||||
} finally {
|
||||
await readLibraryList();
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdate = async (event: Partial<LibraryResponseDto>) => {
|
||||
if (updateLibraryIndex === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const libraryId = libraries[updateLibraryIndex].id;
|
||||
await updateLibrary({ id: libraryId, updateLibraryDto: { ...event } });
|
||||
closeAll();
|
||||
await readLibraryList();
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to update library');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (confirmDeleteLibrary) {
|
||||
deletedLibrary = confirmDeleteLibrary;
|
||||
}
|
||||
|
||||
if (!deletedLibrary) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteLibrary({ id: deletedLibrary.id });
|
||||
notificationController.show({
|
||||
message: `Library deleted`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to remove library');
|
||||
} finally {
|
||||
confirmDeleteLibrary = null;
|
||||
deletedLibrary = null;
|
||||
await readLibraryList();
|
||||
}
|
||||
};
|
||||
|
||||
const handleScanAll = async () => {
|
||||
try {
|
||||
for (const library of libraries) {
|
||||
if (library.type === LibraryType.External) {
|
||||
await scanLibrary({ id: library.id, scanLibraryDto: {} });
|
||||
}
|
||||
}
|
||||
notificationController.show({
|
||||
message: `Refreshing all libraries`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to scan libraries');
|
||||
}
|
||||
};
|
||||
|
||||
const handleScan = async (libraryId: string) => {
|
||||
try {
|
||||
await scanLibrary({ id: libraryId, scanLibraryDto: {} });
|
||||
notificationController.show({
|
||||
message: `Scanning library for new files`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to scan library');
|
||||
}
|
||||
};
|
||||
|
||||
const handleScanChanges = async (libraryId: string) => {
|
||||
try {
|
||||
await scanLibrary({ id: libraryId, scanLibraryDto: { refreshModifiedFiles: true } });
|
||||
notificationController.show({
|
||||
message: `Scanning library for changed files`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to scan library');
|
||||
}
|
||||
};
|
||||
|
||||
const handleForceScan = async (libraryId: string) => {
|
||||
try {
|
||||
await scanLibrary({ id: libraryId, scanLibraryDto: { refreshAllFiles: true } });
|
||||
notificationController.show({
|
||||
message: `Forcing refresh of all library files`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to scan library');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveOffline = async (libraryId: string) => {
|
||||
try {
|
||||
await removeOfflineFiles({ id: libraryId });
|
||||
notificationController.show({
|
||||
message: `Removing Offline Files`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to remove offline files');
|
||||
}
|
||||
};
|
||||
|
||||
const onRenameClicked = () => {
|
||||
closeAll();
|
||||
renameLibrary = selectedLibraryIndex;
|
||||
updateLibraryIndex = selectedLibraryIndex;
|
||||
};
|
||||
|
||||
const onEditImportPathClicked = () => {
|
||||
closeAll();
|
||||
editImportPaths = selectedLibraryIndex;
|
||||
updateLibraryIndex = selectedLibraryIndex;
|
||||
};
|
||||
|
||||
const onScanNewLibraryClicked = async () => {
|
||||
closeAll();
|
||||
|
||||
if (selectedLibrary) {
|
||||
await handleScan(selectedLibrary.id);
|
||||
}
|
||||
};
|
||||
|
||||
const onScanSettingClicked = () => {
|
||||
closeAll();
|
||||
editScanSettings = selectedLibraryIndex;
|
||||
updateLibraryIndex = selectedLibraryIndex;
|
||||
};
|
||||
|
||||
const onScanAllLibraryFilesClicked = async () => {
|
||||
closeAll();
|
||||
if (selectedLibrary) {
|
||||
await handleScanChanges(selectedLibrary.id);
|
||||
}
|
||||
};
|
||||
|
||||
const onForceScanAllLibraryFilesClicked = async () => {
|
||||
closeAll();
|
||||
if (selectedLibrary) {
|
||||
await handleForceScan(selectedLibrary.id);
|
||||
}
|
||||
};
|
||||
|
||||
const onRemoveOfflineFilesClicked = async () => {
|
||||
closeAll();
|
||||
if (selectedLibrary) {
|
||||
await handleRemoveOffline(selectedLibrary.id);
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteLibraryClicked = async () => {
|
||||
closeAll();
|
||||
|
||||
if (selectedLibrary && confirm(`Are you sure you want to delete ${selectedLibrary.name} library?`) == true) {
|
||||
await refreshStats(selectedLibraryIndex);
|
||||
if (totalCount[selectedLibraryIndex] > 0) {
|
||||
deleteAssetCount = totalCount[selectedLibraryIndex];
|
||||
confirmDeleteLibrary = selectedLibrary;
|
||||
} else {
|
||||
deletedLibrary = selectedLibrary;
|
||||
await handleDelete();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if confirmDeleteLibrary}
|
||||
<ConfirmDialogue
|
||||
title="Warning!"
|
||||
prompt="Are you sure you want to delete this library? This will DELETE all {deleteAssetCount} contained assets and cannot be undone."
|
||||
on:confirm={handleDelete}
|
||||
on:cancel={() => (confirmDeleteLibrary = null)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<section class="my-4">
|
||||
<div class="flex flex-col gap-2" in:fade={{ duration: 500 }}>
|
||||
{#if libraries.length > 0}
|
||||
<table class="w-full text-left">
|
||||
<thead
|
||||
class="mb-4 flex h-12 w-full rounded-md border bg-gray-50 text-immich-primary dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-primary"
|
||||
>
|
||||
<tr class="flex w-full place-items-center">
|
||||
<th class="w-1/6 text-center text-sm font-medium">Type</th>
|
||||
<th class="w-1/3 text-center text-sm font-medium">Name</th>
|
||||
<th class="w-1/5 text-center text-sm font-medium">Assets</th>
|
||||
<th class="w-1/6 text-center text-sm font-medium">Size</th>
|
||||
<th class="w-1/6 text-center text-sm font-medium" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="block w-full overflow-y-auto rounded-md border dark:border-immich-dark-gray">
|
||||
{#each libraries as library, index (library.id)}
|
||||
<tr
|
||||
class={`flex h-[80px] w-full place-items-center text-center dark:text-immich-dark-fg ${
|
||||
index % 2 == 0
|
||||
? 'bg-immich-gray dark:bg-immich-dark-gray/75'
|
||||
: 'bg-immich-bg dark:bg-immich-dark-gray/50'
|
||||
}`}
|
||||
>
|
||||
<td class="w-1/6 px-10 text-sm">
|
||||
{#if library.type === LibraryType.External}
|
||||
<Icon path={mdiDatabase} size="40" title="External library (created on {library.createdAt})" />
|
||||
{:else if library.type === LibraryType.Upload}
|
||||
<Icon path={mdiUpload} size="40" title="Upload library (created on {library.createdAt})" />
|
||||
{/if}</td
|
||||
>
|
||||
|
||||
<td class="w-1/3 text-ellipsis px-4 text-sm">{library.name}</td>
|
||||
{#if totalCount[index] == undefined}
|
||||
<td colspan="2" class="flex w-1/3 items-center justify-center text-ellipsis px-4 text-sm">
|
||||
<LoadingSpinner size="40" />
|
||||
</td>
|
||||
{:else}
|
||||
<td class="w-1/6 text-ellipsis px-4 text-sm">
|
||||
{totalCount[index].toLocaleString($locale)}
|
||||
</td>
|
||||
<td class="w-1/6 text-ellipsis px-4 text-sm">{diskUsage[index]} {diskUsageUnit[index]}</td>
|
||||
{/if}
|
||||
|
||||
<td class="w-1/6 text-ellipsis px-4 text-sm">
|
||||
<button
|
||||
class="rounded-full bg-immich-primary p-3 text-gray-100 transition-all duration-150 hover:bg-immich-primary/75 dark:bg-immich-dark-primary dark:text-gray-700"
|
||||
on:click|stopPropagation|preventDefault={(e) => showMenu(e, library, index)}
|
||||
>
|
||||
<Icon path={mdiDotsVertical} size="16" />
|
||||
</button>
|
||||
|
||||
{#if showContextMenu}
|
||||
<Portal target="body">
|
||||
<ContextMenu {...contextMenuPosition} on:outclick={onMenuExit}>
|
||||
<MenuOption on:click={onRenameClicked} text={`Rename`} />
|
||||
|
||||
{#if selectedLibrary && selectedLibrary.type === LibraryType.External}
|
||||
<MenuOption on:click={onEditImportPathClicked} text="Edit Import Paths" />
|
||||
<MenuOption on:click={onScanSettingClicked} text="Scan Settings" />
|
||||
<hr />
|
||||
<MenuOption on:click={onScanNewLibraryClicked} text="Scan New Library Files" />
|
||||
<MenuOption
|
||||
on:click={onScanAllLibraryFilesClicked}
|
||||
text="Re-scan All Library Files"
|
||||
subtitle={'Only refreshes modified files'}
|
||||
/>
|
||||
<MenuOption
|
||||
on:click={onForceScanAllLibraryFilesClicked}
|
||||
text="Force Re-scan All Library Files"
|
||||
subtitle={'Refreshes every file'}
|
||||
/>
|
||||
<hr />
|
||||
<MenuOption on:click={onRemoveOfflineFilesClicked} text="Remove Offline Files" />
|
||||
<MenuOption on:click={onDeleteLibraryClicked}>
|
||||
<p class="text-red-600">Delete library</p>
|
||||
</MenuOption>
|
||||
{/if}
|
||||
</ContextMenu>
|
||||
</Portal>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{#if renameLibrary === index}
|
||||
<div transition:slide={{ duration: 250 }}>
|
||||
<LibraryRenameForm
|
||||
{library}
|
||||
on:submit={({ detail }) => handleUpdate(detail)}
|
||||
on:cancel={() => (renameLibrary = null)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if editImportPaths === index}
|
||||
<div transition:slide={{ duration: 250 }}>
|
||||
<LibraryImportPathsForm
|
||||
{library}
|
||||
on:submit={({ detail }) => handleUpdate(detail)}
|
||||
on:cancel={() => (editImportPaths = null)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if editScanSettings === index}
|
||||
<div transition:slide={{ duration: 250 }} class="mb-4 ml-4 mr-4">
|
||||
<LibraryScanSettingsForm
|
||||
{library}
|
||||
on:submit={({ detail }) => handleUpdate(detail.library)}
|
||||
on:cancel={() => (editScanSettings = null)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{/if}
|
||||
<div class="my-2 flex justify-end gap-2">
|
||||
<Button size="sm" on:click={() => handleScanAll()}>Scan All Libraries</Button>
|
||||
<Button size="sm" on:click={() => handleCreate(LibraryType.External)}>Create External Library</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -66,14 +66,6 @@
|
|||
required={false}
|
||||
/>
|
||||
|
||||
<SettingInputField
|
||||
inputType={SettingInputFieldType.TEXT}
|
||||
label="EXTERNAL PATH"
|
||||
disabled={true}
|
||||
value={editedUser.externalPath || ''}
|
||||
required={false}
|
||||
/>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<Button type="submit" size="sm" on:click={() => handleSaveProfile()}>Save</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
import AppearanceSettings from './appearance-settings.svelte';
|
||||
import ChangePasswordSettings from './change-password-settings.svelte';
|
||||
import DeviceList from './device-list.svelte';
|
||||
import LibraryList from './library-list.svelte';
|
||||
import MemoriesSettings from './memories-settings.svelte';
|
||||
import OAuthSettings from './oauth-settings.svelte';
|
||||
import PartnerSettings from './partner-settings.svelte';
|
||||
|
|
@ -43,10 +42,6 @@
|
|||
<DeviceList bind:devices />
|
||||
</SettingAccordion>
|
||||
|
||||
<SettingAccordion key="libraries" title="Libraries" subtitle="Manage your asset libraries">
|
||||
<LibraryList />
|
||||
</SettingAccordion>
|
||||
|
||||
<SettingAccordion key="memories" title="Memories" subtitle="Manage what you see in your memories.">
|
||||
<MemoriesSettings user={$user} />
|
||||
</SettingAccordion>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue