mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
more refactor
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
parseLecture,
|
||||
getLectureWeekName,
|
||||
lectureToString,
|
||||
} from "@/services/fileStorage/utils/lectureUtils";
|
||||
} from "@/features/local/lectures/lectureUtils";
|
||||
import {
|
||||
LocalCourseSettings,
|
||||
getDayOfWeek,
|
||||
|
||||
48
src/features/local/lectures/lectureUtils.ts
Normal file
48
src/features/local/lectures/lectureUtils.ts
Normal 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;
|
||||
}
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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";
|
||||
|
||||
22
src/features/local/utils/fileSystemUtils.ts
Normal file
22
src/features/local/utils/fileSystemUtils.ts
Normal 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);
|
||||
Reference in New Issue
Block a user