mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
pointer
This commit is contained in:
@@ -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);
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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 })
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user