This commit is contained in:
diced
2026-03-18 10:22:22 -07:00
parent 842dac2660
commit 5ec471050e
2 changed files with 16 additions and 26 deletions

View File

@@ -8,10 +8,8 @@ import { data, Link, Params, useLoaderData } from 'react-router-dom';
import useSWR from 'swr';
export async function loader({ params }: { params: Params<string> }) {
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]'],

View File

@@ -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);