diff --git a/packages/backend/src/core/DownloadService.ts b/packages/backend/src/core/DownloadService.ts index a440ac3c85..44bfdb9ffe 100644 --- a/packages/backend/src/core/DownloadService.ts +++ b/packages/backend/src/core/DownloadService.ts @@ -19,7 +19,10 @@ import type { Response } from 'undici'; const pipeline = util.promisify(stream.pipeline); import { bindThis } from '@/decorators.js'; -type NonNullBodyResponse = Response & { body: ReadableStream }; +export type NonNullBodyResponse = Response & { + body: ReadableStream; + clone: () => NonNullBodyResponse; +}; @Injectable() export class DownloadService { diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts index 1b7b887a88..d6fac44509 100644 --- a/packages/backend/src/server/FileServerService.ts +++ b/packages/backend/src/server/FileServerService.ts @@ -11,7 +11,7 @@ import { createTemp } from '@/misc/create-temp.js'; import { FILE_TYPE_BROWSERSAFE } from '@/const.js'; import { StatusError } from '@/misc/status-error.js'; import type Logger from '@/logger.js'; -import { DownloadService } from '@/core/DownloadService.js'; +import { DownloadService, NonNullBodyResponse } from '@/core/DownloadService.js'; import { ImageProcessingService, webpDefault } from '@/core/ImageProcessingService.js'; import { VideoProcessingService } from '@/core/VideoProcessingService.js'; import { InternalStorageService } from '@/core/InternalStorageService.js'; @@ -109,9 +109,9 @@ export class FileServerService { if (!file.storedInternal) { if (file.isLink && file.uri) { // 期限切れリモートファイル const [path, cleanup] = await createTemp(); - const response = await this.downloadService.fetchUrl(file.uri);; - try { + const _response = await this.downloadService.fetchUrl(file.uri);; + const response = _response.clone() as NonNullBodyResponse; const fileSaving = this.downloadService.pipeRequestToFile(response, path); let { mime, ext } = await this.fileInfoService.detectRequestType(response); diff --git a/packages/backend/src/server/MediaProxyServerService.ts b/packages/backend/src/server/MediaProxyServerService.ts index 3926e863b6..75b5ec6936 100644 --- a/packages/backend/src/server/MediaProxyServerService.ts +++ b/packages/backend/src/server/MediaProxyServerService.ts @@ -8,7 +8,7 @@ import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { isMimeImage } from '@/misc/is-mime-image.js'; import { createTemp } from '@/misc/create-temp.js'; -import { DownloadService } from '@/core/DownloadService.js'; +import { DownloadService, NonNullBodyResponse } from '@/core/DownloadService.js'; import { IImageStreamable, ImageProcessingService, webpDefault } from '@/core/ImageProcessingService.js'; import type { IImage } from '@/core/ImageProcessingService.js'; import { FILE_TYPE_BROWSERSAFE } from '@/const.js'; @@ -75,9 +75,9 @@ export class MediaProxyServerService { // Create temp file const [path, cleanup] = await createTemp(); - const response = await this.downloadService.fetchUrl(url); - try { + const _response = await this.downloadService.fetchUrl(url); + const response = _response.clone() as NonNullBodyResponse; const fileSaving = this.downloadService.pipeRequestToFile(response, path); let { mime, ext } = await this.fileInfoService.detectRequestType(response);