From 2034ae8b28cca5ffd7e5a865c1c23f46912648b1 Mon Sep 17 00:00:00 2001 From: teidesu Date: Sat, 1 May 2021 21:10:49 +0300 Subject: [PATCH] feat(client): support downloading from file ids --- packages/client/src/methods/files/download-iterable.ts | 4 ++++ packages/client/src/types/files/utils.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/client/src/methods/files/download-iterable.ts b/packages/client/src/methods/files/download-iterable.ts index 3a15bc4c..f1e2e8bb 100644 --- a/packages/client/src/methods/files/download-iterable.ts +++ b/packages/client/src/methods/files/download-iterable.ts @@ -8,6 +8,7 @@ import { FileDownloadParameters, FileLocation, } from '../../types' +import { fileIdToInputFileLocation } from '@mtcute/file-id' /** * Download a file and return it as an iterable, which yields file contents @@ -52,6 +53,9 @@ export async function* downloadAsIterable( if (!fileSize) fileSize = location.fileSize location = location.location as any } + if (typeof location === 'string') { + location = fileIdToInputFileLocation(location) + } // we will receive a FileMigrateError in case this is invalid if (!dcId) dcId = this._primaryDc.id diff --git a/packages/client/src/types/files/utils.ts b/packages/client/src/types/files/utils.ts index dd4bca38..7574b62a 100644 --- a/packages/client/src/types/files/utils.ts +++ b/packages/client/src/types/files/utils.ts @@ -49,9 +49,10 @@ export type InputFileLike = export interface FileDownloadParameters { /** - * File location which should be downloaded + * File location which should be downloaded. + * You can also provide TDLib and Bot API compatible File ID */ - location: tl.TypeInputFileLocation | FileLocation + location: tl.TypeInputFileLocation | FileLocation | string /** * Total file size, if known.