From cb0b14ba2d404dd7b5e0f3e0b582adf02376e182 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 12 Oct 2022 01:16:09 +0200 Subject: [PATCH] backend: allow to export only specific emoji --- packages/backend/src/queue/index.ts | 3 ++- .../src/queue/processors/db/export-custom-emojis.ts | 3 ++- .../src/server/api/endpoints/export-custom-emojis.ts | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/queue/index.ts b/packages/backend/src/queue/index.ts index 05ad4c927..cfc991a66 100644 --- a/packages/backend/src/queue/index.ts +++ b/packages/backend/src/queue/index.ts @@ -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, diff --git a/packages/backend/src/queue/processors/db/export-custom-emojis.ts b/packages/backend/src/queue/processors/db/export-custom-emojis.ts index ed12e0e7b..c7e2e825d 100644 --- a/packages/backend/src/queue/processors/db/export-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/export-custom-emojis.ts @@ -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', diff --git a/packages/backend/src/server/api/endpoints/export-custom-emojis.ts b/packages/backend/src/server/api/endpoints/export-custom-emojis.ts index 5d923ef6d..104382c41 100644 --- a/packages/backend/src/server/api/endpoints/export-custom-emojis.ts +++ b/packages/backend/src/server/api/endpoints/export-custom-emojis.ts @@ -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); });