2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-10-20 00:48:31 +02:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2023-03-10 06:22:37 +01:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2023-09-20 04:33:36 +02:00
|
|
|
import type { MiInstance } from '@/models/Instance.js';
|
2022-12-04 05:16:25 +01:00
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
2022-12-04 07:03:09 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2024-02-22 12:59:52 +01:00
|
|
|
import { UtilityService } from '@/core/UtilityService.js';
|
|
|
|
import { RoleService } from '@/core/RoleService.js';
|
|
|
|
import { MiUser } from '@/models/User.js';
|
2022-02-18 12:43:50 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
|
|
|
export class InstanceEntityService {
|
|
|
|
constructor(
|
|
|
|
private metaService: MetaService,
|
2024-02-22 12:59:52 +01:00
|
|
|
private roleService: RoleService,
|
2023-01-13 10:21:07 +01:00
|
|
|
|
|
|
|
private utilityService: UtilityService,
|
2022-09-17 20:27:08 +02:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
public async pack(
|
2023-08-16 10:51:28 +02:00
|
|
|
instance: MiInstance,
|
2024-02-22 12:59:52 +01:00
|
|
|
me?: { id: MiUser['id']; } | null | undefined,
|
2022-02-18 12:43:50 +01:00
|
|
|
): Promise<Packed<'FederationInstance'>> {
|
2022-09-17 20:27:08 +02:00
|
|
|
const meta = await this.metaService.fetch();
|
2024-02-22 12:59:52 +01:00
|
|
|
const iAmModerator = me ? await this.roleService.isModerator(me as MiUser) : false;
|
|
|
|
|
2022-02-18 12:43:50 +01:00
|
|
|
return {
|
|
|
|
id: instance.id,
|
2023-01-15 21:02:38 +01:00
|
|
|
firstRetrievedAt: instance.firstRetrievedAt.toISOString(),
|
2022-02-18 12:43:50 +01:00
|
|
|
host: instance.host,
|
|
|
|
usersCount: instance.usersCount,
|
|
|
|
notesCount: instance.notesCount,
|
|
|
|
followingCount: instance.followingCount,
|
|
|
|
followersCount: instance.followersCount,
|
|
|
|
isNotResponding: instance.isNotResponding,
|
2024-05-23 08:55:47 +02:00
|
|
|
isSuspended: instance.suspensionState !== 'none',
|
|
|
|
suspensionState: instance.suspensionState,
|
2023-01-13 10:21:07 +01:00
|
|
|
isBlocked: this.utilityService.isBlockedHost(meta.blockedHosts, instance.host),
|
2022-02-18 12:43:50 +01: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 13:11:27 +02:00
|
|
|
isSilenced: this.utilityService.isSilencedHost(meta.silencedHosts, instance.host),
|
2024-07-30 12:47:45 +02:00
|
|
|
isMediaSilenced: this.utilityService.isMediaSilencedHost(meta.mediaSilencedHosts, instance.host),
|
2022-02-18 12:43:50 +01:00
|
|
|
iconUrl: instance.iconUrl,
|
2022-06-21 07:28:43 +02:00
|
|
|
faviconUrl: instance.faviconUrl,
|
2022-06-28 03:40:49 +02:00
|
|
|
themeColor: instance.themeColor,
|
2022-02-18 12:43:50 +01:00
|
|
|
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
|
2023-11-07 18:30:04 +01:00
|
|
|
latestRequestReceivedAt: instance.latestRequestReceivedAt ? instance.latestRequestReceivedAt.toISOString() : null,
|
2023-12-05 22:19:53 +01:00
|
|
|
isNSFW: instance.isNSFW,
|
2024-02-22 12:59:52 +01:00
|
|
|
moderationNote: iAmModerator ? instance.moderationNote : null,
|
2022-02-18 12:43:50 +01:00
|
|
|
};
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
2022-02-18 12:43:50 +01:00
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
public packMany(
|
2023-08-16 10:51:28 +02:00
|
|
|
instances: MiInstance[],
|
2024-08-01 14:24:50 +02:00
|
|
|
me?: { id: MiUser['id']; } | null | undefined,
|
2022-02-18 12:43:50 +01:00
|
|
|
) {
|
2024-08-01 14:24:50 +02:00
|
|
|
return Promise.all(instances.map(x => this.pack(x, me)));
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|