mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-17 08:08:17 +09:00
0e4a111f81
Resolve #7779
37 lines
809 B
TypeScript
37 lines
809 B
TypeScript
import { Antennas } from '@/models/index';
|
|
import { Antenna } from '@/models/entities/antenna';
|
|
import { subsdcriber } from '../db/redis';
|
|
|
|
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;
|
|
}
|
|
}
|
|
});
|