mirror of
https://github.com/diced/zipline.git
synced 2026-04-28 10:43:06 -07:00
fix: #1018
This commit is contained in:
@@ -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]'],
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user