feat(client): support downloading from file ids
This commit is contained in:
parent
9303d0841a
commit
2034ae8b28
2 changed files with 7 additions and 2 deletions
|
@ -8,6 +8,7 @@ import {
|
||||||
FileDownloadParameters,
|
FileDownloadParameters,
|
||||||
FileLocation,
|
FileLocation,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
|
import { fileIdToInputFileLocation } from '@mtcute/file-id'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file and return it as an iterable, which yields file contents
|
* 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
|
if (!fileSize) fileSize = location.fileSize
|
||||||
location = location.location as any
|
location = location.location as any
|
||||||
}
|
}
|
||||||
|
if (typeof location === 'string') {
|
||||||
|
location = fileIdToInputFileLocation(location)
|
||||||
|
}
|
||||||
|
|
||||||
// we will receive a FileMigrateError in case this is invalid
|
// we will receive a FileMigrateError in case this is invalid
|
||||||
if (!dcId) dcId = this._primaryDc.id
|
if (!dcId) dcId = this._primaryDc.id
|
||||||
|
|
|
@ -49,9 +49,10 @@ export type InputFileLike =
|
||||||
|
|
||||||
export interface FileDownloadParameters {
|
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.
|
* Total file size, if known.
|
||||||
|
|
Loading…
Reference in a new issue