mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
prevent lectures from dropping on each other
This commit is contained in:
@@ -57,7 +57,10 @@ export async function updateLecture(
|
||||
"lecture start date in update lecture"
|
||||
);
|
||||
|
||||
const weekFolderName = getLectureWeekName(courseSettings.startDate, lecture.date);
|
||||
const weekFolderName = getLectureWeekName(
|
||||
courseSettings.startDate,
|
||||
lecture.date
|
||||
);
|
||||
const weekPath = path.join(courseLectureRoot, weekFolderName);
|
||||
if (!(await directoryExists(weekPath))) {
|
||||
await fs.mkdir(weekPath, { recursive: true });
|
||||
@@ -71,6 +74,41 @@ export async function updateLecture(
|
||||
await fs.writeFile(lecturePath, lectureContents);
|
||||
}
|
||||
|
||||
export async function deleteLecture(
|
||||
courseName: string,
|
||||
courseSettings: LocalCourseSettings,
|
||||
dayAsString: string
|
||||
) {
|
||||
console.log("deleting lecture", courseName, dayAsString);
|
||||
const lectureDate = getDateFromStringOrThrow(
|
||||
dayAsString,
|
||||
"lecture start date in update lecture"
|
||||
);
|
||||
|
||||
const weekFolderName = getLectureWeekName(
|
||||
courseSettings.startDate,
|
||||
dayAsString
|
||||
);
|
||||
|
||||
const courseLectureRoot = path.join(basePath, courseName, lectureFolderName);
|
||||
const weekPath = path.join(courseLectureRoot, weekFolderName);
|
||||
const lecturePath = path.join(
|
||||
weekPath,
|
||||
`${lectureDate.getDay()}-${getDayOfWeek(lectureDate)}.md`
|
||||
);
|
||||
try {
|
||||
await fs.access(lecturePath); // throws error if no file
|
||||
await fs.unlink(lecturePath);
|
||||
console.log(`File deleted: ${lecturePath}`);
|
||||
} catch (error: any) {
|
||||
if (error?.code === "ENOENT") {
|
||||
console.log(`Cannot delete lecture, file does not exist: ${lecturePath}`);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const directoryExists = async (path: string): Promise<boolean> => {
|
||||
try {
|
||||
const stat = await fs.stat(path);
|
||||
|
||||
Reference in New Issue
Block a user