mirror of
https://github.com/TautvydasDerzinskas/Thingport.git
synced 2026-10-21 22:22:24 -05:00
fix: list a nested pictures folder's files as its own model's
This commit is contained in:
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}`,
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in new issue
Block a user