backend: allow to export only specific emoji

This commit is contained in:
Johann150 2022-10-12 01:16:09 +02:00
parent 7ea6deb19b
commit cb0b14ba2d
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 14 additions and 4 deletions

View file

@ -131,9 +131,10 @@ export function createDeleteDriveFilesJob(user: ThinUser) {
});
}
export function createExportCustomEmojisJob(user: ThinUser) {
export function createExportCustomEmojisJob(user: ThinUser, ids: string[] | undefined) {
return dbQueue.add('exportCustomEmojis', {
user,
ids,
}, {
removeOnComplete: true,
removeOnFail: true,

View file

@ -3,7 +3,7 @@ import archiver from 'archiver';
import Bull from 'bull';
import { format as dateFormat } from 'date-fns';
import mime from 'mime-types';
import { IsNull } from 'typeorm';
import { In, IsNull } from 'typeorm';
import config from '@/config/index.js';
import { createTemp, createTempDir } from '@/misc/create-temp.js';
import { downloadUrl } from '@/misc/download-url.js';
@ -50,6 +50,7 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi
const customEmojis = await Emojis.find({
where: {
host: IsNull(),
...(job.data.ids ? { id: In(job.data.ids) } : {}),
},
order: {
id: 'ASC',

View file

@ -13,11 +13,19 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {},
properties: {
ids: {
description: 'Specific emoji IDs to be exported. Non-local emoji will be ignored. If not provided, all local emoji will be exported.',
type: 'array',
items: { type: 'string' },
minItems: 1,
uniqueItems: true,
},
},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
createExportCustomEmojisJob(user);
createExportCustomEmojisJob(user, ps.ids);
});