mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 20:07:33 -07:00
36 lines
824 B
TypeScript
36 lines
824 B
TypeScript
import { Antennas } from "@/models/index.js";
|
|
import type { Antenna } from "@/models/entities/antenna.js";
|
|
import { subscriber } from "@/db/redis.js";
|
|
|
|
let antennasFetched = false;
|
|
let antennas: Antenna[] = [];
|
|
|
|
export async function getAntennas() {
|
|
if (!antennasFetched) {
|
|
antennas = await Antennas.find();
|
|
antennasFetched = true;
|
|
}
|
|
|
|
return antennas;
|
|
}
|
|
|
|
subscriber.on("message", async (_, data) => {
|
|
const obj = JSON.parse(data);
|
|
|
|
if (obj.channel === "internal") {
|
|
const { type, body } = obj.message;
|
|
switch (type) {
|
|
case "antennaCreated":
|
|
antennas.push(body);
|
|
break;
|
|
case "antennaUpdated":
|
|
antennas[antennas.findIndex((a) => a.id === body.id)] = body;
|
|
break;
|
|
case "antennaDeleted":
|
|
antennas = antennas.filter((a) => a.id !== body.id);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
});
|