make a small server that gathers and merges data and stuff like that

This commit is contained in:
MeowcaTheoRange 2024-05-29 00:16:02 -05:00
parent 0e375aaee0
commit 3a1ac18187
9 changed files with 137 additions and 9565 deletions

4
.gitignore vendored
View file

@ -1 +1,3 @@
node_modules
node_modules
eventmapper_config.json
data

View file

@ -0,0 +1,8 @@
import "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"; // window.L
var map = L.map('leaflet-map').setView([0, 0], 2);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

View file

@ -0,0 +1,14 @@
body, html {
margin: 0;
height: 100vh;
width: 100vw;
box-sizing: border-box;
overflow: hidden;
}
#leaflet-map {
display: inline-block;
box-sizing: border-box;
height: 100%;
width: 100%;
}

File diff suppressed because it is too large Load diff

View file

@ -1,21 +0,0 @@
// Placeholder code from Anime Detour testing
import { ICAL } from '/assets/modules/ical_moz.js';
async function getWebDAV() {
const calrequest = await fetch("https://next.abtmtr.link/remote.php/dav/public-calendars/83tEFQ3myCro3WBL?export");
const calendar = await calrequest.text();
const jcal = ICAL.parse(calendar);
const comp = new ICAL.Component(jcal);
const events = comp.getAllSubcomponents("vevent").map(x => new ICAL.Event(x));
const elt = events.map(x => ({
summary: x.summary,
startDate: x.startDate.toJSDate(),
endDate: x.endDate.toJSDate(),
description: x.description,
location: x.location
}));
console.log(events, elt);
}
getWebDAV();

View file

@ -1,3 +1,3 @@
{
"ignore": [".gitignore", ".git/**"]
"ignore": [".gitignore", ".git/**", "data/**"]
}

View file

@ -7,6 +7,7 @@
"dev": "nodemon ./scripts/server.js"
},
"author": "MeowcaTheoRange",
"type": "module",
"license": "MIT",
"dependencies": {
"express": "^4.19.2"

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<title>EventMapper</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
@ -12,15 +12,13 @@
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""
/>
<link
rel="stylesheet"
href="/assets/styles/styles.css"
/>
</head>
<body>
<div id="leaflet-map"></div>
<script
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""
></script>
<script src="" type="module"></script>
<script src="/assets/scripts/script.js" type="module"></script>
</body>
</html>

View file

@ -0,0 +1,104 @@
import express from 'express';
import config from "../eventmapper_config.json" with { type: "json" };
const app = express();
app.use("/assets", express.static('assets'));
app.use("/", express.static('pages'));
app.use("/dataServer", express.static('data')); // Example data file-server
app.get('/data/:lang/events', async (req, res) => {
// Get events
let eventsReq = await fetch(new URL("events/events.json", config.data_url));
let events;
if (eventsReq.ok)
events = await eventsReq.json();
else
return res.status(400).send("Bad Request");
// Get localization
let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url));
let l10n;
if (l10nReq.ok)
l10n = await l10nReq.json();
else
return res.status(404).send("Localization not found!");
// Merge events and localization
const merged = events.map(event => {
const localizationKey = l10n.__events[event.id];
return {
...event,
...localizationKey
};
});
return res.send(merged);
})
app.get('/data/:lang/map', async (req, res) => {
// Get layers
let layersReq = await fetch(new URL("map/layers.json", config.data_url));
let layers;
if (layersReq.ok)
layers = await layersReq.json();
else
return res.status(400).send("Bad Request");
// Get localization
let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url));
let l10n;
if (l10nReq.ok)
l10n = await l10nReq.json();
else
return res.status(404).send("Localization not found!");
// Merge layers and localization
const merged = layers.map(layer => {
const localizationKey = l10n.__layers[layer.id];
return {
...layer,
...localizationKey
};
});
return res.send(merged);
})
app.get('/data/:lang/map/:layer', async (req, res) => {
// Get rooms
let roomsReq = await fetch(new URL(`map/${req.params.layer}.json`, config.data_url));
let rooms;
if (roomsReq.ok)
rooms = await roomsReq.json();
else
return res.status(400).send("Bad Request");
// Get localization
let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url));
let l10n;
if (l10nReq.ok)
l10n = await l10nReq.json();
else
return res.status(404).send("Localization not found!");
// Merge rooms and localization
const merged = rooms.map(room => {
const localizationKey = l10n.__rooms[room.id];
return {
...room,
...localizationKey
};
});
return res.send(merged);
})
app.listen(config.port, () => {
const listeningURL = new URL("http://localhost/");
listeningURL.port = config.port;
console.log(`Example app listening on ${listeningURL.toString()}`)
})