mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 08:23:08 +02:00
77c9b90e6d
* Store nodeinfo per federated instances * Update fetch-nodeinfo.ts * Update fetch-nodeinfo.ts * update
26 lines
609 B
TypeScript
26 lines
609 B
TypeScript
import { Instance } from '../models/entities/instance';
|
|
import { Instances } from '../models';
|
|
import { federationChart } from './chart';
|
|
import { genId } from '../misc/gen-id';
|
|
import { toPuny } from '../misc/convert-host';
|
|
|
|
export async function registerOrFetchInstanceDoc(host: string): Promise<Instance> {
|
|
host = toPuny(host);
|
|
|
|
const index = await Instances.findOne({ host });
|
|
|
|
if (index == null) {
|
|
const i = await Instances.save({
|
|
id: genId(),
|
|
host,
|
|
caughtAt: new Date(),
|
|
lastCommunicatedAt: new Date(),
|
|
});
|
|
|
|
federationChart.update(true);
|
|
|
|
return i;
|
|
} else {
|
|
return index;
|
|
}
|
|
}
|