Refactoring

This commit is contained in:
syuilo 2020-03-31 09:15:04 +09:00
parent 28f8933c3c
commit 79354f4faf
5 changed files with 32 additions and 25 deletions

View File

@ -2,7 +2,6 @@ import { getRepository, getCustomRepository } from 'typeorm';
import { Announcement } from './entities/announcement';
import { AnnouncementRead } from './entities/announcement-read';
import { Instance } from './entities/instance';
import { Emoji } from './entities/emoji';
import { Poll } from './entities/poll';
import { PollVote } from './entities/poll-vote';
import { Meta } from './entities/meta';
@ -52,6 +51,7 @@ import { AntennaRepository } from './repositories/antenna';
import { AntennaNote } from './entities/antenna-note';
import { PromoNote } from './entities/promo-note';
import { PromoRead } from './entities/promo-read';
import { EmojiRepository } from './repositories/emoji';
export const Announcements = getRepository(Announcement);
export const AnnouncementReads = getRepository(AnnouncementRead);
@ -79,7 +79,7 @@ export const UsedUsernames = getRepository(UsedUsername);
export const Followings = getCustomRepository(FollowingRepository);
export const FollowRequests = getCustomRepository(FollowRequestRepository);
export const Instances = getRepository(Instance);
export const Emojis = getRepository(Emoji);
export const Emojis = getCustomRepository(EmojiRepository);
export const DriveFiles = getCustomRepository(DriveFileRepository);
export const DriveFolders = getCustomRepository(DriveFolderRepository);
export const Notifications = getCustomRepository(NotificationRepository);

View File

@ -0,0 +1,27 @@
import { EntityRepository, Repository } from 'typeorm';
import { Emoji } from '../entities/emoji';
import { ensure } from '../../prelude/ensure';
@EntityRepository(Emoji)
export class EmojiRepository extends Repository<Emoji> {
public async pack(
src: Emoji['id'] | Emoji,
) {
const emoji = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
return {
id: emoji.id,
aliases: emoji.aliases,
name: emoji.name,
category: emoji.category,
host: emoji.host,
url: emoji.url,
};
}
public packMany(
emojis: any[],
) {
return Promise.all(emojis.map(x => this.pack(x)));
}
}

View File

@ -51,12 +51,5 @@ export default define(meta, async (ps) => {
.take(ps.limit!)
.getMany();
return emojis.map(e => ({
id: e.id,
name: e.name,
category: e.category,
aliases: e.aliases,
host: e.host,
url: e.url
}));
return Emojis.packMany(emojis);
});

View File

@ -36,12 +36,5 @@ export default define(meta, async (ps) => {
.take(ps.limit!)
.getMany();
return emojis.map(e => ({
id: e.id,
name: e.name,
category: e.category,
aliases: e.aliases,
host: e.host,
url: e.url
}));
return Emojis.packMany(emojis);
});

View File

@ -130,13 +130,7 @@ export default define(meta, async (ps, me) => {
errorImageUrl: instance.errorImageUrl,
iconUrl: instance.iconUrl,
maxNoteTextLength: Math.min(instance.maxNoteTextLength, DB_MAX_NOTE_TEXT_LENGTH),
emojis: emojis.map(e => ({
id: e.id,
aliases: e.aliases,
name: e.name,
category: e.category,
url: e.url,
})),
emojis: await Emojis.packMany(emojis),
requireSetup: (await Users.count({
host: null,
})) === 0,