2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:50:11 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-10-19 17:48:31 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2023-03-09 23:22:37 -06:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2023-09-19 21:33:36 -05:00
|
|
|
import type { MiInstance } from '@/models/Instance.js';
|
2022-12-03 22:16:25 -06:00
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
2022-12-04 00:03:09 -06:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-03-09 23:22:37 -06:00
|
|
|
import { UtilityService } from '../UtilityService.js';
|
2022-02-18 05:43:50 -06:00
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
@Injectable()
|
|
|
|
export class InstanceEntityService {
|
|
|
|
constructor(
|
|
|
|
private metaService: MetaService,
|
2023-01-13 03:21:07 -06:00
|
|
|
|
|
|
|
private utilityService: UtilityService,
|
2022-09-17 13:27:08 -05:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 00:03:09 -06:00
|
|
|
@bindThis
|
2022-09-17 13:27:08 -05:00
|
|
|
public async pack(
|
2023-08-16 03:51:28 -05:00
|
|
|
instance: MiInstance,
|
2022-02-18 05:43:50 -06:00
|
|
|
): Promise<Packed<'FederationInstance'>> {
|
2022-09-17 13:27:08 -05:00
|
|
|
const meta = await this.metaService.fetch();
|
2022-02-18 05:43:50 -06:00
|
|
|
return {
|
|
|
|
id: instance.id,
|
2023-01-15 14:02:38 -06:00
|
|
|
firstRetrievedAt: instance.firstRetrievedAt.toISOString(),
|
2022-02-18 05:43:50 -06: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 03:21:07 -06:00
|
|
|
isBlocked: this.utilityService.isBlockedHost(meta.blockedHosts, 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,
|
2023-10-16 06:11:27 -05:00
|
|
|
isSilenced: this.utilityService.isSilencedHost(meta.silencedHosts, instance.host),
|
2022-02-18 05:43:50 -06:00
|
|
|
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,
|
2023-11-10 23:51:29 -06:00
|
|
|
latestRequestReceivedAt: instance.latestRequestReceivedAt ? instance.latestRequestReceivedAt.toISOString() : null,
|
2022-02-18 05:43:50 -06:00
|
|
|
};
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|
2022-02-18 05:43:50 -06:00
|
|
|
|
2022-12-04 00:03:09 -06:00
|
|
|
@bindThis
|
2022-09-17 13:27:08 -05:00
|
|
|
public packMany(
|
2023-08-16 03:51:28 -05:00
|
|
|
instances: MiInstance[],
|
2022-02-18 05:43:50 -06:00
|
|
|
) {
|
|
|
|
return Promise.all(instances.map(x => this.pack(x)));
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|