2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-20 20:33:11 +00:00
|
|
|
import type { InstancesRepository } from '@/models/index.js';
|
2023-05-10 19:18:48 +00:00
|
|
|
import type { Packed } from 'misskey-js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import type { } from '@/models/entities/Blocking.js';
|
|
|
|
import type { Instance } from '@/models/entities/Instance.js';
|
2022-12-04 04:16:25 +00:00
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
2022-12-04 06:03:09 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-03-10 05:22:37 +00:00
|
|
|
import { UtilityService } from '../UtilityService.js';
|
2022-02-18 11:43:50 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
@Injectable()
|
|
|
|
export class InstanceEntityService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
|
|
|
|
|
|
|
private metaService: MetaService,
|
2023-01-13 09:21:07 +00:00
|
|
|
|
|
|
|
private utilityService: UtilityService,
|
2022-09-17 18:27:08 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public async pack(
|
2022-02-18 11:43:50 +00:00
|
|
|
instance: Instance,
|
|
|
|
): Promise<Packed<'FederationInstance'>> {
|
2022-09-17 18:27:08 +00:00
|
|
|
const meta = await this.metaService.fetch();
|
2022-02-18 11:43:50 +00:00
|
|
|
return {
|
|
|
|
id: instance.id,
|
2023-01-15 20:02:38 +00:00
|
|
|
firstRetrievedAt: instance.firstRetrievedAt.toISOString(),
|
2022-02-18 11:43:50 +00:00
|
|
|
host: instance.host,
|
|
|
|
usersCount: instance.usersCount,
|
|
|
|
notesCount: instance.notesCount,
|
|
|
|
followingCount: instance.followingCount,
|
|
|
|
followersCount: instance.followersCount,
|
|
|
|
isNotResponding: instance.isNotResponding,
|
|
|
|
isSuspended: instance.isSuspended,
|
2023-01-13 09:21:07 +00:00
|
|
|
isBlocked: this.utilityService.isBlockedHost(meta.blockedHosts, instance.host),
|
2022-02-18 11:43:50 +00: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 05:28:43 +00:00
|
|
|
faviconUrl: instance.faviconUrl,
|
2022-06-28 01:40:49 +00:00
|
|
|
themeColor: instance.themeColor,
|
2022-02-18 11:43:50 +00:00
|
|
|
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
|
|
|
|
};
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
2022-02-18 11:43:50 +00:00
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public packMany(
|
2022-02-18 11:43:50 +00:00
|
|
|
instances: Instance[],
|
|
|
|
) {
|
|
|
|
return Promise.all(instances.map(x => this.pack(x)));
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|