2018-10-23 23:17:55 +02:00
|
|
|
import Instance, { IInstance } from '../models/instance';
|
2019-02-07 20:31:33 +01:00
|
|
|
import federationChart from '../services/chart/federation';
|
2018-10-23 23:17:55 +02:00
|
|
|
|
2019-02-07 07:00:44 +01:00
|
|
|
export async function registerOrFetchInstanceDoc(host: string): Promise<IInstance> {
|
2018-10-23 23:17:55 +02:00
|
|
|
if (host == null) return null;
|
|
|
|
|
|
|
|
const index = await Instance.findOne({ host });
|
|
|
|
|
|
|
|
if (index == null) {
|
|
|
|
const i = await Instance.insert({
|
|
|
|
host,
|
|
|
|
caughtAt: new Date(),
|
|
|
|
system: null // TODO
|
|
|
|
});
|
|
|
|
|
|
|
|
federationChart.update(true);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
} else {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|