57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
/*
|
|
* Copyright (C) 2026 Jakub Žitník
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
const API_BASE_URL = process.env.ANNOUNCEMENT_API || "http://localhost:3000";
|
|
|
|
export type Announcement = {
|
|
id: number;
|
|
text_content?: string;
|
|
author: string;
|
|
classes: string[];
|
|
flags: Flag[];
|
|
start_date: string;
|
|
end_date: string;
|
|
};
|
|
|
|
export enum Flag {
|
|
SHOW_ALL_ENTRIES
|
|
}
|
|
|
|
export type AnnouncementResponse = {
|
|
[date: string]: Announcement[];
|
|
}
|
|
|
|
export default async function getAnnouncements(dates: string[]): Promise<AnnouncementResponse> {
|
|
if (dates.length === 0) {
|
|
return {};
|
|
}
|
|
|
|
const url = new URL(`/v1/announcements/${dates.join(",")}`, API_BASE_URL).toString();
|
|
|
|
try {
|
|
const response = await fetch(url);
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
return {};
|
|
}
|
|
|
|
return data;
|
|
} catch (e) {
|
|
console.error("Some random ahh error:", e);
|
|
|
|
return {};
|
|
}
|
|
}
|