mirror of
https://codeberg.org/yeentown/barkey
synced 2024-12-03 09:17:28 +00:00
d071d18dd7
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
36 lines
818 B
TypeScript
36 lines
818 B
TypeScript
import { Antennas } from '@/models/index.js';
|
|
import { Antenna } from '@/models/entities/antenna.js';
|
|
import { subsdcriber } from '../db/redis.js';
|
|
|
|
let antennasFetched = false;
|
|
let antennas: Antenna[] = [];
|
|
|
|
export async function getAntennas() {
|
|
if (!antennasFetched) {
|
|
antennas = await Antennas.find();
|
|
antennasFetched = true;
|
|
}
|
|
|
|
return antennas;
|
|
}
|
|
|
|
subsdcriber.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;
|
|
}
|
|
}
|
|
});
|