Verified Commit 0fb3e1f3 authored by Jakob Moser's avatar Jakob Moser
Browse files

Fall back to linking protocol for today when no metadata is available

parent 3d9b44b2
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -2,7 +2,10 @@ import { Base } from "./Base.mjs"
import { Agenda } from "../pieces/Agenda.mjs"
import { getKey } from "../../account.mjs"
import { ButtonAndTextLink } from "../pieces/ButtonAndTextLink.mjs"
import { getLatestProtocolMetadata } from "../../gitlab.mjs"
import {
    getLatestProtocolMetadata,
    getProtocolEditLink,
} from "../../gitlab.mjs"

const items = {
    all: null,
@@ -55,12 +58,19 @@ export const Fachschaftssitzung = {
                m(
                    "p",
                    m(ButtonAndTextLink, {
                        href: latestProtocol.meta?.editLink,
                        href:
                            latestProtocol.meta?.editLink ||
                            getProtocolEditLink(
                                new Date().toISOString().split("T")[0],
                            ),
                        icon: "fa-solid fa-file-pen",
                        name: "Aktuelles Protokoll bearbeiten",
                        name: latestProtocol.meta
                            ? "Aktuelles Protokoll bearbeiten"
                            : "Heutiges Protokoll bearbeiten",
                    }),
                ),
                latestProtocol.meta && m(
                latestProtocol.meta &&
                    m(
                        "p",
                        m(ButtonAndTextLink, {
                            href: latestProtocol.meta?.downloadLink,
+5 −1
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ async function waitUntilRendered(img) {
    })
}

export function getProtocolEditLink(dateIso) {
    return `https://gitlab.cl.uni-heidelberg.de/-/ide/project/fachschaft/protokolle/edit/master/-/${dateIso.slice(0, 4)}/${dateIso}.md`
}

/**
 * Return an object with metadata about the latest protocol, or null, if the metadata cannot be accessed
 * (e.g., because the user is not logged in to GitLab, is logged in but has no access to the repo, or an error occurred in the pipeline).
@@ -113,7 +117,7 @@ export async function getLatestProtocolMetadata() {

    const dateIso = toIsoString(year, month, day)

    const editLink = `https://gitlab.cl.uni-heidelberg.de/-/ide/project/fachschaft/protokolle/edit/master/-/${year}/${dateIso}.md`
    const editLink = getProtocolEditLink(dateIso)
    const downloadLink = `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${dateIso}.pdf?job=convert-to-pdf`
    const resolutionDownloadLink = containsResolution
        ? `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${dateIso}_nur_Beschlüsse.pdf?job=convert-to-pdf`