This commit is contained in:
2025-11-11 14:19:03 -07:00
parent 7fec0424d7
commit 890e08d1b2
6 changed files with 46 additions and 16 deletions

View File

@@ -25,4 +25,13 @@ export const directoriesRouter = router({
.query(async ({ input: { folderPath } }) => {
return await fileStorageService.settings.folderIsCourse(folderPath);
}),
directoryExists: publicProcedure
.input(
z.object({
relativePath: z.string(),
})
)
.query(async ({ input: { relativePath } }) => {
return await fileStorageService.directoryExists(relativePath);
}),
});

View File

@@ -72,4 +72,15 @@ export const fileStorageService = {
}
return { files, folders };
},
async directoryExists(relativePath: string): Promise<boolean> {
const fullPath = path.join(basePath, relativePath);
// Security: ensure fullPath is inside basePath
const resolvedBase = path.resolve(basePath);
const resolvedFull = path.resolve(fullPath);
if (!resolvedFull.startsWith(resolvedBase)) {
return false;
}
return await directoryOrFileExists(fullPath);
},
};

View File

@@ -23,3 +23,10 @@ export const useDirectoryIsCourseQuery = (folderPath: string) => {
trpc.directories.directoryIsCourse.queryOptions({ folderPath })
);
};
export const useDirectoryExistsQuery = (relativePath: string) => {
const trpc = useTRPC();
return useQuery(
trpc.directories.directoryExists.queryOptions({ relativePath })
);
};