tgsnake
Version:
Telegram MTProto framework for nodejs.
59 lines (58 loc) • 2.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.download = download;
const platform_node_js_1 = require("../../platform.node.js");
async function download(client, { fileId, limit, offset, thumbSize }) {
const media = platform_node_js_1.FileId.decodeFileId(fileId);
if (platform_node_js_1.DOCUMENT_TYPES.includes(media.fileType)) {
return client.core.downloadStream({
file: new platform_node_js_1.Raw.InputDocumentFileLocation({
id: media.id,
accessHash: media.accessHash,
fileReference: media.fileReference,
thumbSize: 'y',
}),
dcId: media.dcId,
limit,
offset,
});
}
if (media.fileType === platform_node_js_1.FileType.CHAT_PHOTO) {
return client.core.downloadStream({
file: new platform_node_js_1.Raw.InputPeerPhotoFileLocation({
photoId: media.id,
big: media.thumbnailSource === platform_node_js_1.ThumbnailSource.CHAT_PHOTO_BIG,
peer: await client.core.resolvePeer(media.chatId),
}),
dcId: media.dcId,
limit,
offset,
});
}
if (media.thumbnailSource === platform_node_js_1.ThumbnailSource.LEGACY) {
return client.core.downloadStream({
file: new platform_node_js_1.Raw.InputPhotoLegacyFileLocation({
id: media.id,
accessHash: media.accessHash,
fileReference: media.fileReference,
volumeId: media.volumeId,
localId: media.localId,
secret: media.secret,
}),
dcId: media.dcId,
limit,
offset,
});
}
return client.core.downloadStream({
file: new platform_node_js_1.Raw.InputPhotoFileLocation({
id: media.id,
accessHash: media.accessHash,
fileReference: media.fileReference,
thumbSize: thumbSize ?? media.thumbnailSize ?? 'y',
}),
dcId: media.dcId,
limit,
offset,
});
}