mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
restructuring file storage service
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export const hasFileSystemEntries = async (
|
||||
directoryPath: string
|
||||
@@ -19,6 +20,32 @@ export const directoryOrFileExists = async (directoryPath: string): Promise<bool
|
||||
}
|
||||
};
|
||||
|
||||
export async function getCourseNames() {
|
||||
console.log("loading course ids");
|
||||
const courseDirectories = await fs.readdir(basePath, {
|
||||
withFileTypes: true,
|
||||
});
|
||||
const coursePromises = await Promise.all(
|
||||
courseDirectories
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map(async (dirent) => {
|
||||
const coursePath = path.join(basePath, dirent.name);
|
||||
const settingsPath = path.join(coursePath, "settings.yml");
|
||||
const hasSettings = await directoryOrFileExists(settingsPath);
|
||||
return {
|
||||
dirent,
|
||||
hasSettings,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const courseNamesFromDirectories = coursePromises
|
||||
.filter(({ hasSettings }) => hasSettings)
|
||||
.map(({ dirent }) => dirent.name);
|
||||
|
||||
return courseNamesFromDirectories;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const basePath = process.env.STORAGE_DIRECTORY ?? "./storage";
|
||||
|
||||
Reference in New Issue
Block a user