This commit is contained in:
tamaina 2023-01-07 04:24:04 +00:00
parent 12afc294f7
commit f69e57385b
3 changed files with 10 additions and 7 deletions

View File

@ -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 {

View File

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

View File

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