fix internal download in emoji import

Changelog: Fixed
This commit is contained in:
Johann150 2023-07-01 21:56:29 +02:00
parent 2f30af1812
commit f760426142
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 16 additions and 2 deletions

View file

@ -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<DbUserImportJobData>, 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);

View file

@ -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<void> {
if (file.storedInternal) {
const fromPath = InternalStorage.resolvePath(file.accessKey);
fs.copyFileSync(fromPath, toPath);
} else {
await downloadUrl(file.url, toPath);
}
}