From 96197e3f37bea8fd06e80c7dce1016fe2ea6fa0a Mon Sep 17 00:00:00 2001 From: Valentyne Stigloher Date: Thu, 1 May 2025 12:24:28 +0200 Subject: [PATCH] (refactor) use sha256 instead of md5 for calendar summary --- server/calendar.ts | 2 +- src/calendar/helpers.ts | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/server/calendar.ts b/server/calendar.ts index 592f9b434..445b275d9 100644 --- a/server/calendar.ts +++ b/server/calendar.ts @@ -64,7 +64,7 @@ const run = async (config: Config, baseUrl: string): Promise => { const prev = fs.existsSync(prevPath) ? JSON.parse(fs.readFileSync(prevPath, 'utf-8')) : {}; const localEvents = (await import(`../locale/${config.locale}/calendar/events.ts`)).default; - const current = buildCalendar(localEvents, process.env.NUXT_PUBLIC_BASE_URL!).buildSummary(); + const current = await buildCalendar(localEvents, process.env.NUXT_PUBLIC_BASE_URL!).buildSummary(); const changedYears = new Set(); for (const day of Object.keys(current)) { const year = day.substring(0, 4); diff --git a/src/calendar/helpers.ts b/src/calendar/helpers.ts index 1a112402c..a4f0a0ec6 100644 --- a/src/calendar/helpers.ts +++ b/src/calendar/helpers.ts @@ -1,10 +1,8 @@ import type { EventAttributes } from 'ics'; -import md5 from 'js-md5'; import nepali from 'nepali-calendar-js'; import { v5 as uuid5 } from 'uuid'; -import { newDate } from '../helpers.ts'; - +import { newDate, sha256 } from '~/src/helpers.ts'; import type { Translator } from '~/src/translator.ts'; export class Day { @@ -448,16 +446,13 @@ export class Calendar { } } - buildSummary(): Record { + async buildSummary(): Promise> { const summary: Record = {}; for (const year of this.getAllYears()) { for (let month = 1; month <= 12; month++) { for (const day of iterateMonth(year.year, month)) { - const events = []; - for (const event of year.eventsByDate[day.toString()] || []) { - events.push(event.name); - } - summary[day.toString()] = md5(JSON.stringify(events)); + const events = (year.eventsByDate[day.toString()] || []).map((event) => event.name); + summary[day.toString()] = await sha256(JSON.stringify(events)); } } }