diff --git a/netlify.toml b/netlify.toml index 96e4b97d..572afda1 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,3 @@ [build] command = "npm run build" - publish = "build" - - -[functions."lectiodelay"] - schedule = "@hourly" \ No newline at end of file + publish = "build" \ No newline at end of file diff --git a/netlify/functions/lectiodelay.mjs b/netlify/functions/lectiodelay.mjs deleted file mode 100644 index 3e1e2f92..00000000 --- a/netlify/functions/lectiodelay.mjs +++ /dev/null @@ -1,116 +0,0 @@ -/* eslint-disable array-bracket-spacing */ -/* eslint-disable camelcase */ -import { addDoc, collection, getDocs, getFirestore } from 'firebase/firestore'; -import { deleteApp, getApp, getApps, initializeApp } from 'firebase/app'; -const QuickChart = require('quickchart-js'); -const chart = new QuickChart(); - -const firebaseConfig = { - apiKey: 'AIzaSyA0PfQiXswZmGxwoyMVGrs3r7ocwv73Ako', - authDomain: 'betterlectio-36bb9.firebaseapp.com', - projectId: 'betterlectio-36bb9', - storageBucket: 'betterlectio-36bb9.appspot.com', - messagingSenderId: '1068596128158', - appId: '1:1068596128158:web:9dffe9cfdf8bb8d2b80e8f' -}; - -let firebase; -if (!getApps().length) { - firebase = initializeApp(firebaseConfig); -} else { - firebase = getApp(); - deleteApp(firebase); - firebase = initializeApp(firebaseConfig); -} - -// this function is called by Netlify Functions every hour to log the current Lectio latency -// it will later be used to create a graph of Lectio latency over time -export default async req => { - console.log('Received'); - - const startmillis = Date.now(); - await fetch('https://lectio.dk'); - const endmillis = Date.now(); - - console.log(`Current Lectio delay: ${endmillis - startmillis}ms`); - - const db = getFirestore(); - const delayRef = collection(db, 'Lectio Delay'); - - // get the last 100 documents from the Lectio Delay collection - const querySnapshot = await getDocs(delayRef); - const docs = []; - querySnapshot.forEach(doc => { - docs.push(doc.data()); - }); - - // fort the docs by time.seconds - docs.sort((a, b) => a.time.seconds - b.time.seconds); - - // if over 50 documents, only use the - if (docs.length > 50) docs.splice(0, docs.length - 50); - - const labels = []; - const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - const wordLength = 8; - - docs.forEach(doc => { - let word = ''; - for (let i = 0; i < wordLength; i++) { - const randomIndex = Math.floor(Math.random() * characters.length); - word += characters[randomIndex]; - } - labels.push(word); - }); - - const data = []; - docs.forEach(doc => { - data.push(doc.delay); - }); - - // create a graph of Lectio latency over time - chart.setWidth(100); - chart.setHeight(48); - chart.setVersion('2'); - - chart.setConfig({ - type: 'line', - data: { - labels, - datasets: [{ - data, - fill: false, - borderColor: '#000000', - borderWidth: 2, - pointRadius: 0 - }] - }, - options: { - legend: { display: false }, - scales: { - xAxes: [{ - display: false, - gridLines: { display: false } - }], - yAxes: [{ - display: false, - gridLines: { display: false } - }] - } - } - }); - - // Print the chart URL - console.log(chart.getUrl()); - - // open the Lectio Delay collection - // add a document to the collection with the time and delay - const docRef = await addDoc(delayRef, { - time: new Date(), - delay: endmillis - startmillis, - imgUrl: chart.getUrl() - }); - - console.log(`Document written with ID: ${docRef.id}`); -}; - diff --git a/package-lock.json b/package-lock.json index f08c5556..dabbee0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "betterlectio", - "version": "0.10.132", + "version": "0.10.136", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "betterlectio", - "version": "0.10.132", + "version": "0.10.136", "dependencies": { "@event-calendar/core": "^1.5.0", "@event-calendar/time-grid": "^1.5.0", diff --git a/src/routes/api/getdelay/+server.js b/src/routes/api/getdelay/+server.js deleted file mode 100644 index 1be9dad8..00000000 --- a/src/routes/api/getdelay/+server.js +++ /dev/null @@ -1,36 +0,0 @@ -import { collection, getDocs, getFirestore } from 'firebase/firestore'; -import { deleteApp, getApp, getApps, initializeApp } from 'firebase/app'; - -const firebaseConfig = { - apiKey: 'AIzaSyA0PfQiXswZmGxwoyMVGrs3r7ocwv73Ako', - authDomain: 'betterlectio-36bb9.firebaseapp.com', - projectId: 'betterlectio-36bb9', - storageBucket: 'betterlectio-36bb9.appspot.com', - messagingSenderId: '1068596128158', - appId: '1:1068596128158:web:9dffe9cfdf8bb8d2b80e8f' -}; - -let firebase; -if (!getApps().length) { - firebase = initializeApp(firebaseConfig); -} else { - firebase = getApp(); - deleteApp(firebase); - firebase = initializeApp(firebaseConfig); -} - -/** @type {import('./$types').RequestHandler} */ -export async function GET() { - // firebase stuff - const db = getFirestore(); - const delayRef = collection(db, 'Lectio Delay'); - const querySnapshot = await getDocs(delayRef); - const docs = querySnapshot.docs.map(doc => doc.data()); - const doc = docs[0]; - let docIndex = 0; - docs.forEach(doc => { - if (doc.time.seconds > docs[docIndex].time.seconds) docIndex = docs.indexOf(doc); - }); - - return new Response(JSON.stringify(docs[docIndex])); -} diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index f60c2134..87c95de8 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -131,16 +131,6 @@ console.log(`Error scanning file. Reason: ${err}`); }); } - - let delayGraphUrl = ''; - let delayGraphAvailable = false; - let delay = 0; - fetch('/api/getdelay').then(res => res.json()).then(json => { - delayGraphUrl = json.imgUrl; - delay = json.delay; - console.log(delayGraphUrl); - if (delayGraphUrl !== '' && delayGraphUrl.includes('https://quickchart.io/chart?c=')) delayGraphAvailable = true; - });
@@ -257,19 +247,7 @@ Servicevilkår & Privatlivspolitik

-
- {#if delayGraphAvailable} - {#key delayGraphUrl} -
- -
-

{delay} ms

-

gns. Lectio responstid

-

Graf over de sidste 50 timer

-
-
- {/key} - {/if} +