fix: list a nested pictures folder's files as its own model's

This commit is contained in:
Tautvydas Derzinskas committed 2026-10-20 16:14:50 +02:00
1 parent ecc551ef27
commit 67bea149a9
2 files changed
+19 -1

No files matched your search

@@ -125,8 +125,10 @@ async function entriesUnder(folder: string): Promise<{ entries: Entry[]; picture
})),
];
// Another model's files can be in a pictures folder, when a category puts them there; they're listed as its own.
// The deepest folders go first, so a model's pictures folder inside another's keeps its pictures.
const listed = new Set(entries.map((entry) => entry.path));
const pictures = await mapWithConcurrency(homes, PICTURE_FOLDER_READS, async (print) => {
const deepestFirst = homes.toSorted((a, b) => b.assetsPath!.length - a.assetsPath!.length);
const pictures = await mapWithConcurrency(deepestFirst, PICTURE_FOLDER_READS, async (print) => {
const home = toSlash(print.assetsPath!);
return (await listAssetFiles(print.assetsPath!)).map((file) => ({
path: `${home}/${file.path}`,
+16
View File
@@ -166,6 +166,22 @@ describe("another model's files inside a model's pictures folder", () => {
for (const file of foreign) expect(fs.readFileSync(stored(home, file), "utf8")).toBe("guest");
fs.rmSync(stored(path.dirname(home)), { recursive: true, force: true });
});
it("are listed as that model's in the storage browser", async () => {
const hostId = await upload(`nest-host-${stamp}.stl`, "solid nest endsolid");
const guestId = await upload(`nest-guest-${stamp}.stl`, "solid nest endsolid");
const home = (await prisma.print.findUniqueOrThrow({ where: { id: hostId } })).assetsPath!;
const guestHome = path.join(home, "Guest", "Images");
await prisma.print.update({ where: { id: guestId }, data: { assetsPath: guestHome } });
fs.mkdirSync(stored(guestHome), { recursive: true });
fs.writeFileSync(stored(guestHome, "guest.jpg"), "guest");
const listing = await browse(guestHome.split(path.sep).join("/"));
expect(listing.files).toEqual([expect.objectContaining({ name: "guest.jpg", print_id: guestId })]);
for (const id of [guestId, hostId]) await request(app).delete(`/api/print/${id}`).set(auth());
fs.rmSync(stored(path.dirname(home)), { recursive: true, force: true });
});
});
describe("a model saved before pictures moved in beside its files", () => {