more refactor

This commit is contained in:
2025-07-23 09:55:30 -06:00
parent 1885431574
commit aa15b2b335
19 changed files with 48 additions and 54 deletions

View File

@@ -7,7 +7,7 @@ import path from "path";
import { promises as fs } from "fs";
import { courseItemFileStorageService } from "@/features/local/course/courseItemFileStorageService";
import { getCoursePathByName } from "@/features/local/globalSettings/globalSettingsFileStorageService";
import { directoryOrFileExists } from "@/services/fileStorage/utils/fileSystemUtils";
import { directoryOrFileExists } from "@/features/local/utils/fileSystemUtils";
const getAssignmentNames = async (courseName: string, moduleName: string) => {
const courseDirectory = await getCoursePathByName(courseName);

View File

@@ -1,5 +1,5 @@
import path from "path";
import { directoryOrFileExists } from "../../../services/fileStorage/utils/fileSystemUtils";
import { directoryOrFileExists } from "../utils/fileSystemUtils";
import fs from "fs/promises";
import {
LocalAssignment,

View File

@@ -1,9 +1,6 @@
import { promises as fs } from "fs";
import path from "path";
import {
basePath,
directoryOrFileExists,
} from "../../../services/fileStorage/utils/fileSystemUtils";
import { basePath, directoryOrFileExists } from "../utils/fileSystemUtils";
import { AssignmentSubmissionType } from "@/features/local/assignments/models/assignmentSubmissionType";
import {
getCoursePathByName,

View File

@@ -1,6 +1,6 @@
import { promises as fs } from "fs";
import path from "path";
import { basePath } from "../../../services/fileStorage/utils/fileSystemUtils";
import { basePath } from "../utils/fileSystemUtils";
import {
GlobalSettings,
zodGlobalSettings,

View File

@@ -8,7 +8,7 @@ import {
parseLecture,
getLectureWeekName,
lectureToString,
} from "@/services/fileStorage/utils/lectureUtils";
} from "@/features/local/lectures/lectureUtils";
import {
LocalCourseSettings,
getDayOfWeek,

View File

@@ -0,0 +1,48 @@
import { getWeekNumber } from "@/app/course/[courseName]/calendar/calendarMonthUtils";
import { extractLabelValue } from "@/features/local/assignments/models/utils/markdownUtils";
import { Lecture } from "@/features/local/lectures/lectureModel";
import { getDateFromStringOrThrow } from "@/features/local/utils/timeUtils";
export function parseLecture(fileContent: string): Lecture {
try {
const settings = fileContent.split("---\n")[0];
const name = extractLabelValue(settings, "Name");
const date = extractLabelValue(settings, "Date");
const content = fileContent.split("---\n").slice(1).join("---\n").trim();
return {
name,
date,
content,
};
} catch (error) {
console.error("Error parsing lecture: ", fileContent);
throw error;
}
}
export function lectureToString(lecture: Lecture) {
return `Name: ${lecture.name}
Date: ${lecture.date}
---
${lecture.content}`;
}
export const lectureFolderName = "00 - lectures";
export function getLectureWeekName(semesterStart: string, lectureDate: string) {
const startDate = getDateFromStringOrThrow(
semesterStart,
"semester start date in update lecture"
);
const targetDate = getDateFromStringOrThrow(
lectureDate,
"lecture start date in update lecture"
);
const weekNumber = getWeekNumber(startDate, targetDate)
.toString()
.padStart(2, "0");
const weekName = `week-${weekNumber}`;
return weekName;
}

View File

@@ -1,5 +1,5 @@
import { promises as fs } from "fs";
import { lectureFolderName } from "../../../services/fileStorage/utils/lectureUtils";
import { lectureFolderName } from "../lectures/lectureUtils";
import { getCoursePathByName } from "../globalSettings/globalSettingsFileStorageService";
export const moduleFileStorageService = {

View File

@@ -1,9 +1,6 @@
import { promises as fs } from "fs";
import path from "path";
import {
basePath,
directoryOrFileExists,
} from "../../../services/fileStorage/utils/fileSystemUtils";
import { basePath, directoryOrFileExists } from "./fileSystemUtils";
import { quizFileStorageService } from "../quizzes/quizFileStorageService";
import { pageFileStorageService } from "../pages/pageFileStorageService";
import { moduleFileStorageService } from "../modules/moduleFileStorageService";

View File

@@ -0,0 +1,22 @@
import { promises as fs } from "fs";
import { getGlobalSettings } from "../globalSettings/globalSettingsFileStorageService";
export const directoryOrFileExists = async (
directoryPath: string
): Promise<boolean> => {
try {
await fs.access(directoryPath);
return true;
} catch {
return false;
}
};
export async function getCourseNames() {
console.log("loading course ids");
const globalSettings = await getGlobalSettings();
return globalSettings.courses.map((course) => course.name);
}
export const basePath = process.env.STORAGE_DIRECTORY ?? "./storage";
console.log("base path", basePath);