2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { InstancesRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { awaitAll } from '@/misc/prelude/await-all.js';
|
|
|
|
import type { Packed } from '@/misc/schema.js';
|
|
|
|
import type { } from '@/models/entities/Blocking.js';
|
|
|
|
import type { User } from '@/models/entities/User.js';
|
|
|
|
import type { Instance } from '@/models/entities/Instance.js';
|
|
|
|
import { MetaService } from '../MetaService.js';
|
|
|
|
import { UserEntityService } from './UserEntityService.js';
|
2022-02-18 20:43:50 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
|
|
|
export class InstanceEntityService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
|
|
|
|
|
|
|
private metaService: MetaService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public async pack(
|
2022-02-18 20:43:50 +09:00
|
|
|
instance: Instance,
|
|
|
|
): Promise<Packed<'FederationInstance'>> {
|
2022-09-18 03:27:08 +09:00
|
|
|
const meta = await this.metaService.fetch();
|
2022-02-18 20:43:50 +09: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 17:55:38 +09:00
|
|
|
isBlocked: meta.blockedHosts.includes(instance.host),
|
2022-02-18 20:43:50 +09: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 14:28:43 +09:00
|
|
|
faviconUrl: instance.faviconUrl,
|
2022-06-28 10:40:49 +09:00
|
|
|
themeColor: instance.themeColor,
|
2022-02-18 20:43:50 +09:00
|
|
|
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
|
|
|
|
};
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
2022-02-18 20:43:50 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
public packMany(
|
2022-02-18 20:43:50 +09:00
|
|
|
instances: Instance[],
|
|
|
|
) {
|
|
|
|
return Promise.all(instances.map(x => this.pack(x)));
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|