diff --git a/scripts/generateSnapshot.ts b/scripts/generateSnapshot.ts index fbf626f..cb1cff6 100644 --- a/scripts/generateSnapshot.ts +++ b/scripts/generateSnapshot.ts @@ -1,8 +1,15 @@ +import dotenv from 'dotenv' import fs from 'fs/promises' import path from 'path' +import { dirname } from 'path' +import { fileURLToPath } from 'url' import { getSnapshots } from '@/apis/snapshots' +// eslint-disable-next-line @typescript-eslint/naming-convention +const __dirname = dirname(fileURLToPath(import.meta.url)) +dotenv.config({ path: path.resolve(__dirname, '../.env') }) + const GENERATED_DIR = path.join(process.cwd(), 'src/__generated__') const SNAPSHOTS_DIR = path.join(GENERATED_DIR, 'snapshots') diff --git a/src/__generated__/snapshots/index.json b/src/__generated__/snapshots/index.json index cbfacaf..6e30bfe 100644 --- a/src/__generated__/snapshots/index.json +++ b/src/__generated__/snapshots/index.json @@ -1,5 +1,5 @@ { - "timestamp": "2024-11-25T15:36:13.202Z", + "timestamp": "2024-11-25T16:03:06.656Z", "totalSnapshots": 24, "courses": [ "105749", diff --git a/src/apis/configs/api.ts b/src/apis/configs/api.ts index 9ec625d..e3024a7 100644 --- a/src/apis/configs/api.ts +++ b/src/apis/configs/api.ts @@ -1,14 +1,17 @@ -import dotenv from 'dotenv' - -dotenv.config() - -const API_BASE_URL = process.env.VITE_API_URL +const getApiUrl = () => { + if (typeof process !== 'undefined' && process.env) { + return process.env.VITE_API_URL + } + return import.meta.env.VITE_API_URL +} type RequestOptions = RequestInit & { params?: Record } export async function api(endpoint: string, options: RequestOptions = {}): Promise { + const API_BASE_URL = getApiUrl() + if (!API_BASE_URL) { throw new Error('API_BASE_URL is not defined') } diff --git a/src/services/parser/index.ts b/src/services/parser/index.ts index cc80c4e..e83af53 100644 --- a/src/services/parser/index.ts +++ b/src/services/parser/index.ts @@ -99,7 +99,6 @@ export function parseAssignmentSubmitted( const assignmentTitle = getText($el.find(title)) const endAt = getText($el.find(period)) + ':00' const hasSubmitted = SUBMISSION_STATUS_REGEX.test(getText($el.find(status))) - console.log({ id, assignmentTitle, endAt, hasSubmitted }) return { id, title: assignmentTitle, endAt, hasSubmitted } })