forked from ProjectSegfault/website
new data loading (only announcements for now)
This commit is contained in:
parent
5f458e1905
commit
e0dd7d2bde
@ -5,6 +5,13 @@ import type { Provider } from "@auth/core/providers";
|
|||||||
import type { Profile } from "@auth/core/types";
|
import type { Profile } from "@auth/core/types";
|
||||||
import { redirect, type Handle } from "@sveltejs/kit";
|
import { redirect, type Handle } from "@sveltejs/kit";
|
||||||
import { sequence } from "@sveltejs/kit/hooks";
|
import { sequence } from "@sveltejs/kit/hooks";
|
||||||
|
import { announcements } from "./stores";
|
||||||
|
import axios from "axios";
|
||||||
|
import { Agent } from "https";
|
||||||
|
|
||||||
|
const agent = new Agent({
|
||||||
|
family: 4
|
||||||
|
});
|
||||||
|
|
||||||
const hasAuth =
|
const hasAuth =
|
||||||
!env.AUTH_CLIENT_ID ||
|
!env.AUTH_CLIENT_ID ||
|
||||||
@ -51,3 +58,24 @@ export const handle: Handle = sequence(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const updateMap = async () => {
|
||||||
|
try {
|
||||||
|
const res = await axios(
|
||||||
|
env.KUMA_URL,
|
||||||
|
{ httpsAgent: agent, timeout: 10000 }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
announcements.set(res.data);
|
||||||
|
} else {
|
||||||
|
announcements.set({ error: true, message: "Error: " + res.status });
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
announcements.set({ error: true, message: "Error: " + err });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
updateMap();
|
||||||
|
|
||||||
|
setInterval(updateMap, 30000);
|
@ -1,11 +1,6 @@
|
|||||||
import type { PageServerLoad } from "./$types";
|
import type { PageServerLoad } from "./$types";
|
||||||
import axios from "axios";
|
import { announcements } from "../stores";
|
||||||
import { Agent } from "https";
|
import { get } from "svelte/store";
|
||||||
import { env } from "$env/dynamic/private";
|
|
||||||
|
|
||||||
const agent = new Agent({
|
|
||||||
family: 4
|
|
||||||
});
|
|
||||||
|
|
||||||
export const load = (async () => {
|
export const load = (async () => {
|
||||||
const meta = {
|
const meta = {
|
||||||
@ -13,15 +8,8 @@ export const load = (async () => {
|
|||||||
description: "Open source development and hosted services."
|
description: "Open source development and hosted services."
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
return {
|
||||||
const res = await axios(env.KUMA_URL, { httpsAgent: agent });
|
announcements: get(announcements),
|
||||||
|
...meta
|
||||||
if (res.status === 200) {
|
|
||||||
return { announcements: res.data, ...meta };
|
|
||||||
} else {
|
|
||||||
return { error: true, message: "Error: " + res.status };
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
return { error: true, message: "Error: " + err };
|
|
||||||
}
|
}
|
||||||
}) satisfies PageServerLoad;
|
}) satisfies PageServerLoad;
|
||||||
|
3
src/stores.ts
Normal file
3
src/stores.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { writable, type Writable } from "svelte/store";
|
||||||
|
|
||||||
|
export const announcements: Writable<{}> = writable({});
|
Loading…
Reference in New Issue
Block a user