|
@@ -31,7 +31,7 @@ export interface DownloadFileParams {
|
|
dcId: number;
|
|
dcId: number;
|
|
/** How much to download. The library will download until it reaches this amount.<br/>
|
|
/** How much to download. The library will download until it reaches this amount.<br/>
|
|
* can be useful for downloading by chunks */
|
|
* can be useful for downloading by chunks */
|
|
- fileSize: number;
|
|
|
|
|
|
+ fileSize?: number;
|
|
/** Used to determine how many download tasks should be run in parallel. anything above 16 is unstable. */
|
|
/** Used to determine how many download tasks should be run in parallel. anything above 16 is unstable. */
|
|
workers?: number;
|
|
workers?: number;
|
|
/** How much to download in each chunk. The larger the less requests to be made. (max is 512kb). */
|
|
/** How much to download in each chunk. The larger the less requests to be made. (max is 512kb). */
|
|
@@ -76,8 +76,9 @@ export async function downloadFile(
|
|
let { partSizeKb, end } = fileParams;
|
|
let { partSizeKb, end } = fileParams;
|
|
const { fileSize, workers = 1 } = fileParams;
|
|
const { fileSize, workers = 1 } = fileParams;
|
|
const { dcId, progressCallback, start = 0 } = fileParams;
|
|
const { dcId, progressCallback, start = 0 } = fileParams;
|
|
-
|
|
|
|
- end = end && end < fileSize ? end : fileSize - 1;
|
|
|
|
|
|
+ if (end && fileSize) {
|
|
|
|
+ end = end < fileSize ? end : fileSize - 1;
|
|
|
|
+ }
|
|
|
|
|
|
if (!partSizeKb) {
|
|
if (!partSizeKb) {
|
|
partSizeKb = fileSize
|
|
partSizeKb = fileSize
|
|
@@ -441,15 +442,20 @@ export async function downloadProfilePhoto(
|
|
entity: EntityLike,
|
|
entity: EntityLike,
|
|
fileParams: DownloadProfilePhotoParams
|
|
fileParams: DownloadProfilePhotoParams
|
|
) {
|
|
) {
|
|
- entity = await client.getEntity(entity);
|
|
|
|
-
|
|
|
|
let photo;
|
|
let photo;
|
|
- if ("photo" in entity) {
|
|
|
|
|
|
+ if (typeof entity == "object" && "photo" in entity) {
|
|
photo = entity.photo;
|
|
photo = entity.photo;
|
|
} else {
|
|
} else {
|
|
- throw new Error(
|
|
|
|
- `Could not get photo from ${entity ? entity.className : undefined}`
|
|
|
|
- );
|
|
|
|
|
|
+ entity = await client.getEntity(entity);
|
|
|
|
+ if ("photo" in entity) {
|
|
|
|
+ photo = entity.photo;
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(
|
|
|
|
+ `Could not get photo from ${
|
|
|
|
+ entity ? entity.className : undefined
|
|
|
|
+ }`
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
let dcId;
|
|
let dcId;
|
|
let loc;
|
|
let loc;
|
|
@@ -468,7 +474,6 @@ export async function downloadProfilePhoto(
|
|
}
|
|
}
|
|
return client.downloadFile(loc, {
|
|
return client.downloadFile(loc, {
|
|
dcId,
|
|
dcId,
|
|
- fileSize: 2 * 1024 * 1024,
|
|
|
|
workers: 1,
|
|
workers: 1,
|
|
});
|
|
});
|
|
}
|
|
}
|