add segfaultapi functionality and use postgres

This commit is contained in:
2022-12-30 19:02:49 +02:00
parent daaca19af8
commit a846dd1e2d
48 changed files with 1576 additions and 377 deletions

View File

@ -1,18 +1,18 @@
import type { PageServerLoad } from "./$types";
import { compile } from "mdsvex";
import { env } from "$env/dynamic/private";
import db from "$lib/db";
export const load: PageServerLoad = async () => {
return {
state: await fetch(
env.VITE_API_URL + "/api/v1/state/announcements"
).then((res) => res.json()).catch(() => ({})),
announcements: await fetch(
env.VITE_API_URL + "/api/v1/announcements"
).then((res) => res.json()).catch(() => ({})),
content: await fetch(env.VITE_API_URL + "/api/v1/announcements")
.then((res) => res.json())
.then((res) => compile(res.title))
.then((res) => res?.code).catch(() => ({})),
};
const Announcements = db.model("Announcements");
const data = await Announcements.findAll().then((docs) => {
return docs.map((doc) => doc.get());
});
if (data.length !== 0 || data[0] !== undefined) {
return {
announcements: data[0],
content: compile(data[0]["title"]).then((compiled) => compiled?.code)
}
}
};