can add existing courses

This commit is contained in:
2025-07-22 14:23:40 -06:00
parent 67b67100c1
commit 704a5ae404
18 changed files with 209 additions and 30 deletions

View File

@@ -47,6 +47,7 @@ export const fileStorageService = {
await fs.mkdir(courseDirectory, { recursive: true });
},
async createModuleFolderForTesting(courseName: string, moduleName: string) {
const courseDirectory = path.join(basePath, courseName, moduleName);
@@ -57,6 +58,12 @@ export const fileStorageService = {
relativePath: string
): Promise<{ files: string[]; folders: string[] }> {
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 { files: [], folders: [] };
}
if (!(await directoryOrFileExists(fullPath))) {
throw new Error(`Directory ${fullPath} does not exist`);
}