From f76042614236766e3b9d7d8ac582d5205cea15eb Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 1 Jul 2023 21:56:29 +0200 Subject: [PATCH] fix internal download in emoji import Changelog: Fixed --- .../queue/processors/db/import-custom-emojis.ts | 4 ++-- packages/backend/src/services/drive/read-file.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 packages/backend/src/services/drive/read-file.ts diff --git a/packages/backend/src/queue/processors/db/import-custom-emojis.ts b/packages/backend/src/queue/processors/db/import-custom-emojis.ts index 855017460..233a7045f 100644 --- a/packages/backend/src/queue/processors/db/import-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/import-custom-emojis.ts @@ -4,12 +4,12 @@ import unzipper from 'unzipper'; import { db } from '@/db/postgre.js'; import { createTempDir } from '@/misc/create-temp.js'; -import { downloadUrl } from '@/misc/download-url.js'; import { genId } from '@/misc/gen-id.js'; import { DriveFiles, Emojis } from '@/models/index.js'; import { DbUserImportJobData } from '@/queue/types.js'; import { queueLogger } from '@/queue/logger.js'; import { addFile } from '@/services/drive/add-file.js'; +import { copyFileTo } from '@/services/drive/read-file.js'; const logger = queueLogger.createSubLogger('import-custom-emojis'); @@ -33,7 +33,7 @@ export async function importCustomEmojis(job: Bull.Job, don try { fs.writeFileSync(destPath, '', 'binary'); - await downloadUrl(file.url, destPath); + await copyFileTo(file, destPath); } catch (e) { // TODO: 何度か再試行 if (e instanceof Error || typeof e === 'string') { logger.error(e); diff --git a/packages/backend/src/services/drive/read-file.ts b/packages/backend/src/services/drive/read-file.ts new file mode 100644 index 000000000..ef9f0b60c --- /dev/null +++ b/packages/backend/src/services/drive/read-file.ts @@ -0,0 +1,14 @@ +import * as fs from 'node:fs'; +import { DriveFiles } from '@/models/index.js'; +import { DriveFile } from '@/models/entities/drive-file.js'; +import { InternalStorage } from './internal-storage.js'; +import { downloadUrl } from '@/misc/download-url.js'; + +export async function copyFileTo(file: DriveFile, toPath: string): Promise { + if (file.storedInternal) { + const fromPath = InternalStorage.resolvePath(file.accessKey); + fs.copyFileSync(fromPath, toPath); + } else { + await downloadUrl(file.url, toPath); + } +}