From 5ec471050e426a6b1dfa09eb2e2b35239e342ddd Mon Sep 17 00:00:00 2001 From: diced Date: Wed, 18 Mar 2026 10:22:22 -0700 Subject: [PATCH] fix: #1018 --- src/client/pages/folder/[id]/upload.tsx | 6 ++--- src/server/routes/api/server/folder.ts | 36 ++++++++++--------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/client/pages/folder/[id]/upload.tsx b/src/client/pages/folder/[id]/upload.tsx index 46c0d958..50b190d6 100644 --- a/src/client/pages/folder/[id]/upload.tsx +++ b/src/client/pages/folder/[id]/upload.tsx @@ -8,10 +8,8 @@ import { data, Link, Params, useLoaderData } from 'react-router-dom'; import useSWR from 'swr'; export async function loader({ params }: { params: Params }) { - const res = await fetch(`/api/server/folder/${params.id}?upload=true`); - if (!res.ok) { - throw data('Folder not found', { status: 404 }); - } + const res = await fetch(`/api/server/folder/${params.id}`); + if (!res.ok) throw data('Folder not found', { status: 404 }); return { folder: (await res.json()) as Response['/api/server/folder/[id]'], diff --git a/src/server/routes/api/server/folder.ts b/src/server/routes/api/server/folder.ts index ff93c2f3..7439a43f 100644 --- a/src/server/routes/api/server/folder.ts +++ b/src/server/routes/api/server/folder.ts @@ -14,14 +14,10 @@ export default typedPlugin( PATH, { schema: { - description: - 'Fetch a public view of a folder by ID, including files, child folders, and parent chain when allowed.', + description: 'Fetch a folder by ID. Behavior varies based on public and allowUploads flags.', params: z.object({ id: z.string(), }), - querystring: z.object({ - uploads: z.string().optional(), - }), response: { 200: folderSchema.partial(), }, @@ -29,22 +25,13 @@ export default typedPlugin( }, async (req, res) => { const { id } = req.params; - const { uploads } = req.query; const folder = await prisma.folder.findUnique({ - where: { - id: id, - }, + where: { id }, include: { files: { - select: { - ...fileSelect, - password: true, - tags: false, - }, - orderBy: { - createdAt: 'desc', - }, + select: { ...fileSelect, password: true, tags: false }, + orderBy: { createdAt: 'desc' }, }, children: { where: { public: true }, @@ -55,9 +42,7 @@ export default typedPlugin( createdAt: true, updatedAt: true, public: true, - _count: { - select: { children: true, files: true }, - }, + _count: { select: { children: true, files: true } }, }, }, parent: { @@ -67,9 +52,16 @@ export default typedPlugin( }); if (!folder) throw new ApiError(9002); + if (!folder.public && !folder.allowUploads) throw new ApiError(9002); - if (uploads && !folder.allowUploads) throw new ApiError(3002); - if (!uploads && !folder.public) throw new ApiError(9002); + if (!folder.public && folder.allowUploads) { + return res.send({ + id: folder.id, + name: folder.name, + allowUploads: folder.allowUploads, + public: folder.public, + }); + } if (folder.parentId) { folder.parent = await buildPublicParentChain(folder.parentId);