rudeshark.net/src/services/register-or-fetch-instance-doc.ts
syuilo 987168b863
strictNullChecks (#4666)
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
2019-04-13 01:43:22 +09:00

28 lines
633 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(),
system: null // TODO
});
federationChart.update(true);
return i;
} else {
return index;
}
}