forked from FoundKeyGang/FoundKey
fix internal download in emoji import
Changelog: Fixed
This commit is contained in:
parent
2f30af1812
commit
f760426142
2 changed files with 16 additions and 2 deletions
|
@ -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);
|
||||
|
|
14
packages/backend/src/services/drive/read-file.ts
Normal file
14
packages/backend/src/services/drive/read-file.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue