2022-03-26 01:34:00 -05:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-26 20:07:39 -06:00
|
|
|
import { Instance } from '@/models/entities/instance.js';
|
|
|
|
import { Packed } from '@/misc/schema.js';
|
2022-06-21 03:55:38 -05:00
|
|
|
import { fetchMeta } from '@/misc/fetch-meta.js';
|
2022-02-18 05:43:50 -06:00
|
|
|
|
2022-03-26 01:34:00 -05:00
|
|
|
export const InstanceRepository = db.getRepository(Instance).extend({
|
|
|
|
async pack(
|
2022-02-18 05:43:50 -06:00
|
|
|
instance: Instance,
|
|
|
|
): Promise<Packed<'FederationInstance'>> {
|
2022-06-21 03:55:38 -05:00
|
|
|
const meta = await fetchMeta();
|
2022-02-18 05:43:50 -06:00
|
|
|
return {
|
|
|
|
id: instance.id,
|
|
|
|
caughtAt: instance.caughtAt.toISOString(),
|
|
|
|
host: instance.host,
|
|
|
|
usersCount: instance.usersCount,
|
|
|
|
notesCount: instance.notesCount,
|
|
|
|
followingCount: instance.followingCount,
|
|
|
|
followersCount: instance.followersCount,
|
|
|
|
latestRequestSentAt: instance.latestRequestSentAt ? instance.latestRequestSentAt.toISOString() : null,
|
|
|
|
lastCommunicatedAt: instance.lastCommunicatedAt.toISOString(),
|
|
|
|
isNotResponding: instance.isNotResponding,
|
|
|
|
isSuspended: instance.isSuspended,
|
2022-06-21 03:55:38 -05:00
|
|
|
isBlocked: meta.blockedHosts.includes(instance.host),
|
2022-02-18 05:43:50 -06:00
|
|
|
softwareName: instance.softwareName,
|
|
|
|
softwareVersion: instance.softwareVersion,
|
|
|
|
openRegistrations: instance.openRegistrations,
|
|
|
|
name: instance.name,
|
|
|
|
description: instance.description,
|
|
|
|
maintainerName: instance.maintainerName,
|
|
|
|
maintainerEmail: instance.maintainerEmail,
|
|
|
|
iconUrl: instance.iconUrl,
|
2022-06-21 00:28:43 -05:00
|
|
|
faviconUrl: instance.faviconUrl,
|
2022-06-27 20:40:49 -05:00
|
|
|
themeColor: instance.themeColor,
|
2022-02-18 05:43:50 -06:00
|
|
|
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
|
|
|
|
};
|
2022-03-26 01:34:00 -05:00
|
|
|
},
|
2022-02-18 05:43:50 -06:00
|
|
|
|
2022-03-26 01:34:00 -05:00
|
|
|
packMany(
|
2022-02-18 05:43:50 -06:00
|
|
|
instances: Instance[],
|
|
|
|
) {
|
|
|
|
return Promise.all(instances.map(x => this.pack(x)));
|
2022-03-26 01:34:00 -05:00
|
|
|
},
|
|
|
|
});
|