@mtkruto/node 0.1.139 → 0.1.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/3_types.d.ts +10 -36
- package/esm/3_types.js +10 -36
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +1 -1
- package/esm/5_client.js +1 -1
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/client/0_filters.d.ts +60 -0
- package/esm/client/0_filters.js +27 -0
- package/esm/client/0_message.js +2 -2
- package/esm/client/{3_params.d.ts → 0_params.d.ts} +30 -33
- package/esm/client/0_types.d.ts +39 -0
- package/esm/client/0_types.js +2 -0
- package/esm/client/0_utilities.d.ts +1 -47
- package/esm/client/0_utilities.js +0 -27
- package/esm/client/1_composer.d.ts +1 -1
- package/esm/client/1_composer.js +1 -1
- package/esm/client/1_file_manager.d.ts +10 -0
- package/esm/client/1_file_manager.js +241 -0
- package/esm/client/1_update_manager.d.ts +18 -0
- package/esm/client/1_update_manager.js +553 -0
- package/esm/client/2_message_manager.d.ts +40 -0
- package/esm/client/2_message_manager.js +621 -0
- package/esm/client/3_chat_list_manager.d.ts +21 -0
- package/esm/client/3_chat_list_manager.js +353 -0
- package/esm/client/3_reaction_manager.d.ts +16 -0
- package/esm/client/3_reaction_manager.js +61 -0
- package/esm/client/4_client.d.ts +187 -60
- package/esm/client/4_client.js +492 -1698
- package/esm/connection/1_connection_web_socket.js +6 -6
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +1 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +524 -0
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/storage/0_storage.d.ts +5 -3
- package/esm/storage/0_storage.js +14 -4
- package/esm/tl/1_tl_object.d.ts +1 -0
- package/esm/tl/1_tl_object.js +24 -0
- package/esm/types/0_bot_command.d.ts +1 -0
- package/esm/types/0_chat_member_rights.d.ts +37 -0
- package/esm/types/0_chat_photo.d.ts +4 -4
- package/esm/types/0_file_source.d.ts +5 -0
- package/esm/types/0_giveaway_parameters.js +2 -1
- package/esm/types/0_id.d.ts +4 -0
- package/esm/types/0_message_entity.d.ts +20 -20
- package/esm/types/1__getters.d.ts +2 -2
- package/esm/types/1_animation.d.ts +1 -1
- package/esm/types/1_bot_command_scope.d.ts +5 -4
- package/esm/types/1_chat_p.d.ts +5 -6
- package/esm/types/1_document.d.ts +1 -0
- package/esm/types/1_input_message_content.d.ts +88 -0
- package/esm/types/1_photo.d.ts +1 -1
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_user.d.ts +1 -1
- package/esm/types/1_video.d.ts +1 -1
- package/esm/types/1_video_note.d.ts +1 -1
- package/esm/types/2_inline_keyboard_button.d.ts +10 -10
- package/esm/types/2_message_reaction_count.d.ts +3 -0
- package/esm/types/2_message_reaction_count.js +17 -1
- package/esm/types/2_message_reactions.d.ts +15 -0
- package/esm/types/2_message_reactions.js +37 -0
- package/esm/types/3_reply_markup.d.ts +42 -0
- package/esm/types/3_reply_markup.js +117 -0
- package/esm/types/4_inline_query_result.d.ts +193 -0
- package/esm/types/{5_inline_query_result.js → 4_inline_query_result.js} +2 -2
- package/esm/types/4_message.d.ts +36 -39
- package/esm/types/4_message.js +7 -24
- package/esm/types/5_callback_query.d.ts +2 -1
- package/esm/types/5_chat.d.ts +8 -5
- package/esm/types/6_update.d.ts +12 -2
- package/esm/utilities/0_buffer.js +9 -6
- package/esm/utilities/0_object.d.ts +1 -1
- package/esm/utilities/0_object.js +1 -6
- package/esm/utilities/1_misc.d.ts +2 -0
- package/esm/utilities/1_misc.js +6 -0
- package/package.json +1 -2
- package/script/3_types.d.ts +10 -36
- package/script/3_types.js +10 -36
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +1 -1
- package/script/5_client.js +1 -1
- package/script/_dnt.polyfills.d.ts +6 -0
- package/script/client/0_filters.d.ts +60 -0
- package/script/client/0_filters.js +31 -0
- package/script/client/0_message.js +1 -1
- package/script/client/{3_params.d.ts → 0_params.d.ts} +30 -33
- package/script/client/0_types.d.ts +39 -0
- package/script/client/0_types.js +6 -0
- package/script/client/0_utilities.d.ts +1 -47
- package/script/client/0_utilities.js +1 -29
- package/script/client/1_composer.d.ts +1 -1
- package/script/client/1_composer.js +2 -2
- package/script/client/1_file_manager.d.ts +10 -0
- package/script/client/1_file_manager.js +245 -0
- package/script/client/1_update_manager.d.ts +18 -0
- package/script/client/1_update_manager.js +557 -0
- package/script/client/2_message_manager.d.ts +40 -0
- package/script/client/2_message_manager.js +625 -0
- package/script/client/3_chat_list_manager.d.ts +21 -0
- package/script/client/3_chat_list_manager.js +357 -0
- package/script/client/3_reaction_manager.d.ts +16 -0
- package/script/client/3_reaction_manager.js +65 -0
- package/script/client/4_client.d.ts +187 -60
- package/script/client/4_client.js +491 -1698
- package/script/connection/1_connection_web_socket.js +5 -5
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.d.ts +1 -1
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/main/deps.js +2 -2
- package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/object-inspect/main/index.js +550 -0
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/storage/0_storage.d.ts +5 -3
- package/script/storage/0_storage.js +14 -4
- package/script/tl/1_tl_object.d.ts +1 -0
- package/script/tl/1_tl_object.js +24 -0
- package/script/types/0_bot_command.d.ts +1 -0
- package/script/types/0_chat_member_rights.d.ts +37 -0
- package/script/types/0_chat_photo.d.ts +4 -4
- package/script/types/0_file_source.d.ts +5 -0
- package/script/types/0_giveaway_parameters.js +2 -1
- package/script/types/0_id.d.ts +4 -0
- package/script/types/0_message_entity.d.ts +20 -20
- package/script/types/1__getters.d.ts +2 -2
- package/script/types/1_animation.d.ts +1 -1
- package/script/types/1_bot_command_scope.d.ts +5 -4
- package/script/types/1_chat_p.d.ts +5 -6
- package/script/types/1_document.d.ts +1 -0
- package/script/types/1_input_message_content.d.ts +88 -0
- package/script/types/1_photo.d.ts +1 -1
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_user.d.ts +1 -1
- package/script/types/1_video.d.ts +1 -1
- package/script/types/1_video_note.d.ts +1 -1
- package/script/types/2_inline_keyboard_button.d.ts +10 -10
- package/script/types/2_message_reaction_count.d.ts +3 -0
- package/script/types/2_message_reaction_count.js +19 -0
- package/script/types/2_message_reactions.d.ts +15 -0
- package/script/types/2_message_reactions.js +41 -0
- package/script/types/3_reply_markup.d.ts +42 -0
- package/script/types/3_reply_markup.js +122 -0
- package/script/types/4_inline_query_result.d.ts +193 -0
- package/script/types/{5_inline_query_result.js → 4_inline_query_result.js} +3 -3
- package/script/types/4_message.d.ts +36 -39
- package/script/types/4_message.js +6 -23
- package/script/types/5_callback_query.d.ts +2 -1
- package/script/types/5_chat.d.ts +8 -5
- package/script/types/6_update.d.ts +12 -2
- package/script/utilities/0_buffer.js +9 -6
- package/script/utilities/0_object.d.ts +1 -1
- package/script/utilities/0_object.js +1 -6
- package/script/utilities/1_misc.d.ts +2 -0
- package/script/utilities/1_misc.js +9 -1
- package/esm/types/0_chat_id.d.ts +0 -4
- package/esm/types/0_force_reply.d.ts +0 -12
- package/esm/types/0_force_reply.js +0 -17
- package/esm/types/0_input_contact_message_content.d.ts +0 -11
- package/esm/types/0_input_location_message_content.d.ts +0 -15
- package/esm/types/0_input_venue_message_content.d.ts +0 -19
- package/esm/types/0_reply_keyboard_remove.d.ts +0 -10
- package/esm/types/0_reply_keyboard_remove.js +0 -8
- package/esm/types/1_input_invoice_message_content.d.ts +0 -23
- package/esm/types/1_input_text_message_content.d.ts +0 -8
- package/esm/types/1_input_text_message_content.js +0 -1
- package/esm/types/2_input_message_content.d.ts +0 -6
- package/esm/types/2_input_message_content.js +0 -1
- package/esm/types/2_reply_keyboard_markup.d.ts +0 -12
- package/esm/types/2_reply_keyboard_markup.js +0 -37
- package/esm/types/3_inline_keyboard_markup.d.ts +0 -8
- package/esm/types/3_inline_keyboard_markup.js +0 -24
- package/esm/types/4_inline_query_result_article.d.ts +0 -15
- package/esm/types/4_inline_query_result_article.js +0 -1
- package/esm/types/4_inline_query_result_audio.d.ts +0 -17
- package/esm/types/4_inline_query_result_audio.js +0 -1
- package/esm/types/4_inline_query_result_cached_audio.d.ts +0 -14
- package/esm/types/4_inline_query_result_cached_audio.js +0 -1
- package/esm/types/4_inline_query_result_cached_document.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_document.js +0 -1
- package/esm/types/4_inline_query_result_cached_gif.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_gif.js +0 -1
- package/esm/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_mpeg4_gif.js +0 -1
- package/esm/types/4_inline_query_result_cached_photo.d.ts +0 -16
- package/esm/types/4_inline_query_result_cached_photo.js +0 -1
- package/esm/types/4_inline_query_result_cached_sticker.d.ts +0 -9
- package/esm/types/4_inline_query_result_cached_sticker.js +0 -1
- package/esm/types/4_inline_query_result_cached_video.d.ts +0 -16
- package/esm/types/4_inline_query_result_cached_video.js +0 -1
- package/esm/types/4_inline_query_result_cached_voice.d.ts +0 -15
- package/esm/types/4_inline_query_result_cached_voice.js +0 -1
- package/esm/types/4_inline_query_result_contact.d.ts +0 -15
- package/esm/types/4_inline_query_result_contact.js +0 -1
- package/esm/types/4_inline_query_result_document.d.ts +0 -18
- package/esm/types/4_inline_query_result_document.js +0 -1
- package/esm/types/4_inline_query_result_game.d.ts +0 -7
- package/esm/types/4_inline_query_result_game.js +0 -1
- package/esm/types/4_inline_query_result_gif.d.ts +0 -20
- package/esm/types/4_inline_query_result_gif.js +0 -1
- package/esm/types/4_inline_query_result_location.d.ts +0 -18
- package/esm/types/4_inline_query_result_location.js +0 -1
- package/esm/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
- package/esm/types/4_inline_query_result_mpeg4_gif.js +0 -1
- package/esm/types/4_inline_query_result_photo.d.ts +0 -19
- package/esm/types/4_inline_query_result_photo.js +0 -1
- package/esm/types/4_inline_query_result_venue.d.ts +0 -19
- package/esm/types/4_inline_query_result_venue.js +0 -1
- package/esm/types/4_inline_query_result_video.d.ts +0 -21
- package/esm/types/4_inline_query_result_video.js +0 -1
- package/esm/types/4_inline_query_result_voice.d.ts +0 -16
- package/esm/types/4_inline_query_result_voice.js +0 -1
- package/esm/types/4_reply_markup.d.ts +0 -7
- package/esm/types/4_reply_markup.js +0 -22
- package/esm/types/5_inline_query_result.d.ts +0 -28
- package/script/types/0_chat_id.d.ts +0 -4
- package/script/types/0_force_reply.d.ts +0 -12
- package/script/types/0_force_reply.js +0 -22
- package/script/types/0_input_contact_message_content.d.ts +0 -11
- package/script/types/0_input_location_message_content.d.ts +0 -15
- package/script/types/0_input_venue_message_content.d.ts +0 -19
- package/script/types/0_reply_keyboard_remove.d.ts +0 -10
- package/script/types/0_reply_keyboard_remove.js +0 -13
- package/script/types/1_input_invoice_message_content.d.ts +0 -23
- package/script/types/1_input_text_message_content.d.ts +0 -8
- package/script/types/1_input_text_message_content.js +0 -2
- package/script/types/2_input_message_content.d.ts +0 -6
- package/script/types/2_input_message_content.js +0 -2
- package/script/types/2_reply_keyboard_markup.d.ts +0 -12
- package/script/types/2_reply_keyboard_markup.js +0 -42
- package/script/types/3_inline_keyboard_markup.d.ts +0 -8
- package/script/types/3_inline_keyboard_markup.js +0 -29
- package/script/types/4_inline_query_result_article.d.ts +0 -15
- package/script/types/4_inline_query_result_article.js +0 -2
- package/script/types/4_inline_query_result_audio.d.ts +0 -17
- package/script/types/4_inline_query_result_audio.js +0 -2
- package/script/types/4_inline_query_result_cached_audio.d.ts +0 -14
- package/script/types/4_inline_query_result_cached_audio.js +0 -2
- package/script/types/4_inline_query_result_cached_document.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_document.js +0 -2
- package/script/types/4_inline_query_result_cached_gif.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_gif.js +0 -2
- package/script/types/4_inline_query_result_cached_mpeg4_gif.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_mpeg4_gif.js +0 -2
- package/script/types/4_inline_query_result_cached_photo.d.ts +0 -16
- package/script/types/4_inline_query_result_cached_photo.js +0 -2
- package/script/types/4_inline_query_result_cached_sticker.d.ts +0 -9
- package/script/types/4_inline_query_result_cached_sticker.js +0 -2
- package/script/types/4_inline_query_result_cached_video.d.ts +0 -16
- package/script/types/4_inline_query_result_cached_video.js +0 -2
- package/script/types/4_inline_query_result_cached_voice.d.ts +0 -15
- package/script/types/4_inline_query_result_cached_voice.js +0 -2
- package/script/types/4_inline_query_result_contact.d.ts +0 -15
- package/script/types/4_inline_query_result_contact.js +0 -2
- package/script/types/4_inline_query_result_document.d.ts +0 -18
- package/script/types/4_inline_query_result_document.js +0 -2
- package/script/types/4_inline_query_result_game.d.ts +0 -7
- package/script/types/4_inline_query_result_game.js +0 -2
- package/script/types/4_inline_query_result_gif.d.ts +0 -20
- package/script/types/4_inline_query_result_gif.js +0 -2
- package/script/types/4_inline_query_result_location.d.ts +0 -18
- package/script/types/4_inline_query_result_location.js +0 -2
- package/script/types/4_inline_query_result_mpeg4_gif.d.ts +0 -20
- package/script/types/4_inline_query_result_mpeg4_gif.js +0 -2
- package/script/types/4_inline_query_result_photo.d.ts +0 -19
- package/script/types/4_inline_query_result_photo.js +0 -2
- package/script/types/4_inline_query_result_venue.d.ts +0 -19
- package/script/types/4_inline_query_result_venue.js +0 -2
- package/script/types/4_inline_query_result_video.d.ts +0 -21
- package/script/types/4_inline_query_result_video.js +0 -2
- package/script/types/4_inline_query_result_voice.d.ts +0 -16
- package/script/types/4_inline_query_result_voice.js +0 -2
- package/script/types/4_reply_markup.d.ts +0 -7
- package/script/types/4_reply_markup.js +0 -26
- package/script/types/5_inline_query_result.d.ts +0 -28
- /package/esm/{client/3_params.js → _dnt.polyfills.js} +0 -0
- /package/esm/{types/0_chat_id.js → client/0_params.js} +0 -0
- /package/esm/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
- /package/esm/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
- /package/esm/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
- /package/esm/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
- /package/script/{client/3_params.js → _dnt.polyfills.js} +0 -0
- /package/script/{types/0_chat_id.js → client/0_params.js} +0 -0
- /package/script/types/{0_input_contact_message_content.js → 0_chat_member_rights.js} +0 -0
- /package/script/types/{0_input_location_message_content.js → 0_file_source.js} +0 -0
- /package/script/types/{0_input_venue_message_content.js → 0_id.js} +0 -0
- /package/script/types/{1_input_invoice_message_content.js → 1_input_message_content.js} +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _FileManager_instances, _FileManager_c, _FileManager_downloadInner;
|
|
13
|
+
import { debug, extension } from "../0_deps.js";
|
|
14
|
+
import { drop, getRandomId, mod, UNREACHABLE } from "../1_utilities.js";
|
|
15
|
+
import { as, types } from "../2_tl.js";
|
|
16
|
+
import { constructDocument, FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "../3_types.js";
|
|
17
|
+
import { FloodWait } from "../4_errors.js";
|
|
18
|
+
import { ConnectionError } from "./0_types.js";
|
|
19
|
+
const d = debug("FileManager");
|
|
20
|
+
export class FileManager {
|
|
21
|
+
constructor(c) {
|
|
22
|
+
_FileManager_instances.add(this);
|
|
23
|
+
_FileManager_c.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _FileManager_c, c, "f");
|
|
25
|
+
}
|
|
26
|
+
async upload(contents, params) {
|
|
27
|
+
const isBig = contents.length > 1048576; // 10 MB
|
|
28
|
+
const chunkSize = params?.chunkSize ?? 512 * 1024;
|
|
29
|
+
if (mod(chunkSize, 1024) != 0) {
|
|
30
|
+
throw new Error("chunkSize must be divisible by 1024");
|
|
31
|
+
}
|
|
32
|
+
const signal = params?.signal;
|
|
33
|
+
d("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
|
|
34
|
+
const fileId = getRandomId();
|
|
35
|
+
const name = params?.fileName ?? fileId.toString();
|
|
36
|
+
const { api, disconnect, connect } = __classPrivateFieldGet(this, _FileManager_c, "f").apiFactory();
|
|
37
|
+
signal?.addEventListener("abort", () => drop(disconnect()));
|
|
38
|
+
await connect();
|
|
39
|
+
let part = 0;
|
|
40
|
+
const partCount = Math.ceil(contents.length / chunkSize);
|
|
41
|
+
try {
|
|
42
|
+
main: for (; part < partCount; part++) {
|
|
43
|
+
chunk: while (true) {
|
|
44
|
+
try {
|
|
45
|
+
const start = part * chunkSize;
|
|
46
|
+
const end = start + chunkSize;
|
|
47
|
+
const bytes = contents.slice(start, end);
|
|
48
|
+
if (bytes.length == 0) {
|
|
49
|
+
continue main;
|
|
50
|
+
}
|
|
51
|
+
if (isBig) {
|
|
52
|
+
await api.upload.saveBigFilePart({ file_id: fileId, file_part: part, bytes, file_total_parts: partCount });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await api.upload.saveFilePart({ file_id: fileId, bytes, file_part: part });
|
|
56
|
+
}
|
|
57
|
+
d((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
|
|
58
|
+
break chunk;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (signal?.aborted) {
|
|
62
|
+
break main;
|
|
63
|
+
}
|
|
64
|
+
if (err instanceof FloodWait) {
|
|
65
|
+
d("got a flood wait of " + err.seconds + " seconds");
|
|
66
|
+
await new Promise((r) => setTimeout(r, err.seconds * 1000));
|
|
67
|
+
}
|
|
68
|
+
else if (err instanceof ConnectionError) {
|
|
69
|
+
while (true) {
|
|
70
|
+
try {
|
|
71
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
72
|
+
await connect();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
if (signal?.aborted) {
|
|
76
|
+
break main;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
drop(disconnect());
|
|
90
|
+
}
|
|
91
|
+
d("uploaded all " + partCount + " chunk(s)");
|
|
92
|
+
if (isBig) {
|
|
93
|
+
return new types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return new types.InputFile({ id: fileId, name, parts: part, md5_checksum: "" });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async *download(fileId, params) {
|
|
100
|
+
const fileId_ = FileID.decode(fileId);
|
|
101
|
+
switch (fileId_.fileType) {
|
|
102
|
+
case FileType.ChatPhoto: {
|
|
103
|
+
const big = fileId_.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
|
|
104
|
+
const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(fileId_.params.chatId);
|
|
105
|
+
const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
|
|
106
|
+
for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
107
|
+
yield chunk;
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case FileType.Photo: {
|
|
112
|
+
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
113
|
+
UNREACHABLE();
|
|
114
|
+
}
|
|
115
|
+
const location = new types.InputPhotoFileLocation({
|
|
116
|
+
id: fileId_.params.mediaId,
|
|
117
|
+
access_hash: fileId_.params.accessHash,
|
|
118
|
+
file_reference: fileId_.params.fileReference,
|
|
119
|
+
thumb_size: fileId_.params.thumbnailSize,
|
|
120
|
+
});
|
|
121
|
+
for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
122
|
+
yield chunk;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case FileType.Document:
|
|
127
|
+
case FileType.Sticker:
|
|
128
|
+
case FileType.VideoNote:
|
|
129
|
+
case FileType.Video:
|
|
130
|
+
case FileType.Audio:
|
|
131
|
+
case FileType.Voice:
|
|
132
|
+
case FileType.Animation: {
|
|
133
|
+
if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
|
|
134
|
+
UNREACHABLE();
|
|
135
|
+
}
|
|
136
|
+
const location = new types.InputDocumentFileLocation({
|
|
137
|
+
id: fileId_.params.mediaId,
|
|
138
|
+
access_hash: fileId_.params.accessHash,
|
|
139
|
+
file_reference: fileId_.params.fileReference,
|
|
140
|
+
thumb_size: fileId_.params.thumbnailSize,
|
|
141
|
+
});
|
|
142
|
+
for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
|
|
143
|
+
yield chunk;
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
UNREACHABLE();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async getCustomEmojiDocuments(id) {
|
|
152
|
+
id = Array.isArray(id) ? id : [id];
|
|
153
|
+
if (!id.length) {
|
|
154
|
+
throw new Error("No custom emoji ID provided");
|
|
155
|
+
}
|
|
156
|
+
const documents = new Array();
|
|
157
|
+
let shouldFetch = false;
|
|
158
|
+
for (const [i, id_] of id.entries()) {
|
|
159
|
+
const maybeDocument = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getCustomEmojiDocument(BigInt(id_));
|
|
160
|
+
if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
|
|
161
|
+
const document_ = maybeDocument[0];
|
|
162
|
+
const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
|
|
163
|
+
const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
|
|
164
|
+
mediaId: document_.id,
|
|
165
|
+
accessHash: document_.access_hash,
|
|
166
|
+
fileReference: document_.file_reference,
|
|
167
|
+
}).encode();
|
|
168
|
+
const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
|
|
169
|
+
documents.push(document);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
shouldFetch = true;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!shouldFetch) {
|
|
177
|
+
return documents;
|
|
178
|
+
}
|
|
179
|
+
const documents_ = await __classPrivateFieldGet(this, _FileManager_c, "f").api.messages.getCustomEmojiDocuments({ document_id: id.map(BigInt) }).then((v) => v.map((v) => v[as](types.Document)));
|
|
180
|
+
for (const [i, document_] of documents_.entries()) {
|
|
181
|
+
const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
|
|
182
|
+
const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
|
|
183
|
+
mediaId: document_.id,
|
|
184
|
+
accessHash: document_.access_hash,
|
|
185
|
+
fileReference: document_.file_reference,
|
|
186
|
+
}).encode();
|
|
187
|
+
const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
|
|
188
|
+
documents.push(document);
|
|
189
|
+
}
|
|
190
|
+
return documents;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
_FileManager_c = new WeakMap(), _FileManager_instances = new WeakSet(), _FileManager_downloadInner = async function* _FileManager_downloadInner(location, dcId, params) {
|
|
194
|
+
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
195
|
+
if (id != null) {
|
|
196
|
+
const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
|
|
197
|
+
const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
|
|
198
|
+
if (file != null && file[0] > 0) {
|
|
199
|
+
for await (const part of __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset)) {
|
|
200
|
+
yield part;
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
206
|
+
if (mod(chunkSize, 1024) != 0) {
|
|
207
|
+
throw new Error("chunkSize must be divisible by 1024");
|
|
208
|
+
}
|
|
209
|
+
const { api, connect, disconnect } = __classPrivateFieldGet(this, _FileManager_c, "f").apiFactory(dcId);
|
|
210
|
+
await connect();
|
|
211
|
+
const limit = chunkSize;
|
|
212
|
+
let offset = params?.offset ? BigInt(params.offset) : 0n;
|
|
213
|
+
let part = 0;
|
|
214
|
+
try {
|
|
215
|
+
while (true) {
|
|
216
|
+
const file = await api.upload.getFile({ location, offset, limit });
|
|
217
|
+
if (file instanceof types.upload.File) {
|
|
218
|
+
yield file.bytes;
|
|
219
|
+
if (id != null) {
|
|
220
|
+
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
|
|
221
|
+
}
|
|
222
|
+
++part;
|
|
223
|
+
if (file.bytes.length < limit) {
|
|
224
|
+
if (id != null) {
|
|
225
|
+
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
offset += BigInt(file.bytes.length);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
UNREACHABLE();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
drop(disconnect());
|
|
240
|
+
}
|
|
241
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Queue } from "../1_utilities.js";
|
|
2
|
+
import { enums, ReadObject, TLObject } from "../2_tl.js";
|
|
3
|
+
import { C } from "./0_types.js";
|
|
4
|
+
type UpdateHandler = (update: enums.Update) => Promise<(() => Promise<unknown>)>;
|
|
5
|
+
export declare class UpdateManager {
|
|
6
|
+
#private;
|
|
7
|
+
static readonly MAIN_BOX_ID = 0n;
|
|
8
|
+
constructor(c: C);
|
|
9
|
+
fetchState(source: string): Promise<void>;
|
|
10
|
+
processChats(chats: enums.Chat[]): Promise<void>;
|
|
11
|
+
processResult(result: ReadObject): Promise<void>;
|
|
12
|
+
processUsers(users: enums.User[]): Promise<void>;
|
|
13
|
+
getHandleUpdateQueue(boxId: bigint): Queue;
|
|
14
|
+
processUpdates(updates: enums.Update | enums.Updates, checkGap: boolean, call?: TLObject | null, callback?: () => void): void;
|
|
15
|
+
recoverUpdateGap(source: string): Promise<void>;
|
|
16
|
+
setUpdateHandler(handler: UpdateHandler): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|