Create Gallery on a folder means the files inside it

It stored the folder. What somebody right-clicks is a directory; what a gallery
holds is pictures — obvious the moment you look at the result, and not before.

Expanded by the server, because that side already knows which extensions are
media and how to walk the tree. It is the same `listOriginals` the sync uses, so
a gallery cannot end up holding a file the pipeline would never convert.

Recursive, deliberately: a folder of folders is still "these pictures", and
refusing to descend would silently miss most of what was pointed at.

An expansion that returns nothing creates nothing. Falling back to the folder
itself is exactly the bug being fixed, and doing it quietly is worse than doing
nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-29 21:16:05 +01:00
co-authored by Claude Opus 5
parent f61653f7af
commit a610f93189
2 changed files with 51 additions and 3 deletions
+26 -2
View File
@@ -43,8 +43,32 @@ export const fileActions: FileAction[] = [
const directories = entries.filter((entry) => entry.type === 'directory').length;
return directories === 0 || (directories === 1 && entries.length === 1);
},
run: (entries) => {
const paths = entries.map((entry) => relativeTo(entry.path)).filter((path): path is string => Boolean(path));
run: async (entries) => {
/*
A folder is expanded into the files inside it.
What somebody right-clicked is the directory; what a gallery holds is pictures. Without this the
gallery gets one item — the folder — which is what shipped first and is obviously wrong the
moment you look at it.
Expanded by the SERVER, because that side already knows which extensions are media and how to
walk the tree: it is the same `listOriginals` the sync uses, so a gallery cannot end up holding
a file the pipeline would never convert.
*/
const chosen = entries.map((entry) => relativeTo(entry.path)).filter((path): path is string => Boolean(path));
let paths = chosen;
if (entries.length === 1 && entries[0]!.type === 'directory') {
const response = await fetch(
`/api/fofos-admin/_config/media/files?path=${encodeURIComponent(chosen[0] ?? '')}`,
{ credentials: 'same-origin' },
).catch(() => null);
const body = response?.ok ? ((await response.json()) as { files?: string[] }) : null;
// Falling back to the folder itself would create the wrong gallery quietly. Nothing is better.
if (!body?.files?.length) return;
paths = body.files;
}
/*
Handed over in the URL, and the Galleries panel does the asking.