mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 05:57:32 -07:00
Refactoring
This commit is contained in:
parent
8af638401b
commit
12d3e3f786
5 changed files with 32 additions and 25 deletions
|
@ -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);
|
||||
|
|
27
src/models/repositories/emoji.ts
Normal file
27
src/models/repositories/emoji.ts
Normal 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)));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue