a shared link is a URL, not a key

Create, edit and revoke shared links from the album header, the selection
bar and the Sharing panel. Password, expiry, and the three flags that
decide what the person opening it can do.

The panel showed a bare key because this plugin never learned the
instance's public address. It does not need to store one: Immich has
`externalDomain` in its own admin settings, `/server/config` already
returns it, and it is the same field Immich's own copy-link button reads,
so the two cannot disagree. Empty is a real state and the UI says so
rather than inventing a host.

Payload shapes came from the live instance's spec.json, not from memory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-02 18:16:02 +01:00
co-authored by Claude Opus 5
parent 470bb42fe8
commit 70fc2b08c6
7 changed files with 598 additions and 41 deletions
+37 -1
View File
@@ -1,4 +1,4 @@
import type { Album } from './shared';
import type { Album, SharedLink, SharedLinkCreate, SharedLinkEdit } from './shared';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useClient } from 'hooks/useClient';
import { toast } from 'sonner';
@@ -120,6 +120,39 @@ export function useAssetActions() {
onError: fail('rename the album'),
});
// ── Shared links ──
//
// The only thing in this file that produces a PUBLIC address, which is why the create dialog sends every
// flag explicitly instead of letting Immich's defaults apply. Immich defaults `allowDownload` and
// `showMetadata` to true and the expiry to never; a form that silently inherits those is a form that
// shares more than it appears to.
const createSharedLink = useMutation({
mutationFn: (body: SharedLinkCreate) => post<SharedLink>('/photos/_officer/shared-links', body),
onSuccess: invalidate,
onError: fail('create the link'),
});
const updateSharedLink = useMutation({
mutationFn: ({ id, ...body }: SharedLinkEdit & { id: string }) =>
patch<SharedLink>(`/photos/_officer/shared-links/${id}`, body),
onSuccess: () => {
invalidate();
toast.success('Link updated');
},
onError: fail('update the link'),
});
// Revoke, not delete: the link stops working for everybody holding it, and nothing about the photos changes.
const deleteSharedLink = useMutation({
mutationFn: (id: string) => del(`/photos/_officer/shared-links/${id}`),
onSuccess: () => {
invalidate();
toast.success('Link revoked');
},
onError: fail('revoke the link'),
});
return {
setFavorite,
setArchived,
@@ -132,5 +165,8 @@ export function useAssetActions() {
createAlbum,
deleteAlbum,
renameAlbum,
createSharedLink,
updateSharedLink,
deleteSharedLink,
};
}