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 { Announcement } from './entities/announcement';
import { AnnouncementRead } from './entities/announcement-read'; import { AnnouncementRead } from './entities/announcement-read';
import { Instance } from './entities/instance'; import { Instance } from './entities/instance';
import { Emoji } from './entities/emoji';
import { Poll } from './entities/poll'; import { Poll } from './entities/poll';
import { PollVote } from './entities/poll-vote'; import { PollVote } from './entities/poll-vote';
import { Meta } from './entities/meta'; import { Meta } from './entities/meta';
@ -52,6 +51,7 @@ import { AntennaRepository } from './repositories/antenna';
import { AntennaNote } from './entities/antenna-note'; import { AntennaNote } from './entities/antenna-note';
import { PromoNote } from './entities/promo-note'; import { PromoNote } from './entities/promo-note';
import { PromoRead } from './entities/promo-read'; import { PromoRead } from './entities/promo-read';
import { EmojiRepository } from './repositories/emoji';
export const Announcements = getRepository(Announcement); export const Announcements = getRepository(Announcement);
export const AnnouncementReads = getRepository(AnnouncementRead); export const AnnouncementReads = getRepository(AnnouncementRead);
@ -79,7 +79,7 @@ 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 = getRepository(Instance);
export const Emojis = getRepository(Emoji); 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);
export const Notifications = getCustomRepository(NotificationRepository); 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!) .take(ps.limit!)
.getMany(); .getMany();
return emojis.map(e => ({ return Emojis.packMany(emojis);
id: e.id,
name: e.name,
category: e.category,
aliases: e.aliases,
host: e.host,
url: e.url
}));
}); });

View file

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

View file

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