refactor: add InstanceRepository

This commit is contained in:
syuilo 2022-02-18 20:43:50 +09:00
parent debef43111
commit 0d3757f2d3
4 changed files with 41 additions and 11 deletions

View file

@ -61,6 +61,7 @@ import { RegistryItem } from './entities/registry-item';
import { Ad } from './entities/ad'; import { Ad } from './entities/ad';
import { PasswordResetRequest } from './entities/password-reset-request'; import { PasswordResetRequest } from './entities/password-reset-request';
import { UserPending } from './entities/user-pending'; import { UserPending } from './entities/user-pending';
import { InstanceRepository } from './repositories/instance';
export const Announcements = getRepository(Announcement); export const Announcements = getRepository(Announcement);
export const AnnouncementReads = getRepository(AnnouncementRead); export const AnnouncementReads = getRepository(AnnouncementRead);
@ -89,7 +90,7 @@ export const UserNotePinings = getRepository(UserNotePining);
export const UsedUsernames = getRepository(UsedUsername); export const UsedUsernames = getRepository(UsedUsername);
export const Followings = getCustomRepository(FollowingRepository); export const Followings = getCustomRepository(FollowingRepository);
export const FollowRequests = getCustomRepository(FollowRequestRepository); export const FollowRequests = getCustomRepository(FollowRequestRepository);
export const Instances = getRepository(Instance); export const Instances = getCustomRepository(InstanceRepository);
export const Emojis = getCustomRepository(EmojiRepository); export const Emojis = getCustomRepository(EmojiRepository);
export const DriveFiles = getCustomRepository(DriveFileRepository); export const DriveFiles = getCustomRepository(DriveFileRepository);
export const DriveFolders = getCustomRepository(DriveFolderRepository); export const DriveFolders = getCustomRepository(DriveFolderRepository);

View file

@ -1,2 +0,0 @@
import config from '@/config/index';

View file

@ -0,0 +1,39 @@
import { EntityRepository, Repository } from 'typeorm';
import { Instance } from '@/models/entities/instance';
import { Packed } from '@/misc/schema';
@EntityRepository(Instance)
export class InstanceRepository extends Repository<Instance> {
public async pack(
instance: Instance,
): Promise<Packed<'FederationInstance'>> {
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,
softwareName: instance.softwareName,
softwareVersion: instance.softwareVersion,
openRegistrations: instance.openRegistrations,
name: instance.name,
description: instance.description,
maintainerName: instance.maintainerName,
maintainerEmail: instance.maintainerEmail,
iconUrl: instance.iconUrl,
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
};
}
public packMany(
instances: Instance[],
) {
return Promise.all(instances.map(x => this.pack(x)));
}
}

View file

@ -34,14 +34,6 @@ export const packedFederationInstanceSchema = {
type: 'number', type: 'number',
optional: false, nullable: false, optional: false, nullable: false,
}, },
driveUsage: {
type: 'number',
optional: false, nullable: false,
},
driveFiles: {
type: 'number',
optional: false, nullable: false,
},
latestRequestSentAt: { latestRequestSentAt: {
type: 'string', type: 'string',
optional: false, nullable: true, optional: false, nullable: true,