@mtkruto/node 0.67.1 → 0.68.0
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/0_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_transport.d.ts +3 -3
- package/esm/3_transport.js +3 -3
- package/esm/3_types.d.ts +8 -7
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +8 -7
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1271 -1290
- package/esm/connection/1_connection_tcp.node.js +48 -65
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/assert/1.0.13/equals.js +4 -4
- package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/deps/jsr.io/@std/internal/1.0.10/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/format.d.ts +29 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/format.js +70 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/types.d.ts.map +1 -0
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- package/esm/tl/2_telegram.d.ts +9 -10
- package/esm/tl/2_telegram.d.ts.map +1 -1
- package/esm/tl/2_telegram.js +10 -10
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/{script/transport/2_transport_provider.d.ts → esm/transport/1_transport_provider.d.ts} +1 -1
- package/esm/transport/{2_transport_provider.d.ts.map → 1_transport_provider.d.ts.map} +1 -1
- package/{script/transport/3_transport_provider_tcp.d.ts → esm/transport/2_transport_provider_tcp.d.ts} +2 -2
- package/esm/transport/{3_transport_provider_tcp.d.ts.map → 2_transport_provider_tcp.d.ts.map} +1 -1
- package/esm/transport/{3_transport_provider_tcp.js → 2_transport_provider_tcp.js} +1 -1
- package/esm/transport/{3_transport_provider_web_socket.d.ts → 2_transport_provider_web_socket.d.ts} +2 -2
- package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -0
- package/esm/transport/{3_transport_provider_web_socket.js → 2_transport_provider_web_socket.js} +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/{2_inline_keyboard_button.d.ts → 1_inline_keyboard_button.d.ts} +1 -1
- package/esm/types/{2_inline_keyboard_button.d.ts.map → 1_inline_keyboard_button.d.ts.map} +1 -1
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_chat.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/2_pre_checkout_query.d.ts.map +1 -1
- package/esm/types/{3_reply_markup.d.ts → 2_reply_markup.d.ts} +2 -2
- package/esm/types/{3_reply_markup.d.ts.map → 2_reply_markup.d.ts.map} +1 -1
- package/esm/types/{3_reply_markup.js → 2_reply_markup.js} +1 -1
- package/esm/types/2_story_interactive_area.d.ts.map +1 -1
- package/esm/types/3_chat_member_updated.d.ts.map +1 -1
- package/esm/types/3_story.d.ts.map +1 -1
- package/esm/types/5_message.d.ts +1 -1
- package/esm/types/5_message.d.ts.map +1 -1
- package/esm/types/5_message.js +1 -1
- package/esm/types/6_inline_query_result.d.ts +1 -1
- package/esm/types/6_inline_query_result.js +1 -1
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_transport.d.ts +3 -3
- package/script/3_transport.js +3 -3
- package/script/3_types.d.ts +8 -7
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +8 -7
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1271 -1290
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/assert/1.0.13/equals.js +4 -4
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/build_message.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/diff.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/diff_str.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/format.d.ts +29 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/format.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +106 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.d.ts +9 -10
- package/script/tl/2_telegram.d.ts.map +1 -1
- package/script/tl/2_telegram.js +32 -10
- package/script/transport/0_obfuscation.js +17 -7
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/{esm/transport/2_transport_provider.d.ts → script/transport/1_transport_provider.d.ts} +1 -1
- package/script/transport/{2_transport_provider.d.ts.map → 1_transport_provider.d.ts.map} +1 -1
- package/{esm/transport/3_transport_provider_tcp.d.ts → script/transport/2_transport_provider_tcp.d.ts} +2 -2
- package/script/transport/{3_transport_provider_tcp.d.ts.map → 2_transport_provider_tcp.d.ts.map} +1 -1
- package/script/transport/{3_transport_provider_tcp.js → 2_transport_provider_tcp.js} +3 -3
- package/script/transport/{3_transport_provider_web_socket.d.ts → 2_transport_provider_web_socket.d.ts} +2 -2
- package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -0
- package/script/transport/{3_transport_provider_web_socket.js → 2_transport_provider_web_socket.js} +2 -2
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/{2_inline_keyboard_button.d.ts → 1_inline_keyboard_button.d.ts} +1 -1
- package/script/types/{2_inline_keyboard_button.d.ts.map → 1_inline_keyboard_button.d.ts.map} +1 -1
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_chat.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/2_pre_checkout_query.d.ts.map +1 -1
- package/script/types/{3_reply_markup.d.ts → 2_reply_markup.d.ts} +2 -2
- package/script/types/{3_reply_markup.d.ts.map → 2_reply_markup.d.ts.map} +1 -1
- package/script/types/{3_reply_markup.js → 2_reply_markup.js} +3 -3
- package/script/types/2_story_interactive_area.d.ts.map +1 -1
- package/script/types/3_chat_member_updated.d.ts.map +1 -1
- package/script/types/3_story.d.ts.map +1 -1
- package/script/types/5_message.d.ts +1 -1
- package/script/types/5_message.d.ts.map +1 -1
- package/script/types/5_message.js +2 -2
- package/script/types/6_inline_query_result.d.ts +1 -1
- package/script/types/6_inline_query_result.js +4 -4
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
- package/esm/deps/jsr.io/@std/internal/1.0.9/build_message.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.9/diff.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.9/diff_str.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.9/format.d.ts +0 -2
- package/esm/deps/jsr.io/@std/internal/1.0.9/format.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.9/format.js +0 -37
- package/esm/deps/jsr.io/@std/internal/1.0.9/styles.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/internal/1.0.9/types.d.ts.map +0 -1
- package/esm/transport/3_transport_provider_web_socket.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/build_message.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/diff.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/diff_str.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/format.d.ts +0 -2
- package/script/deps/jsr.io/@std/internal/1.0.9/format.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/format.js +0 -63
- package/script/deps/jsr.io/@std/internal/1.0.9/styles.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/internal/1.0.9/types.d.ts.map +0 -1
- package/script/transport/3_transport_provider_web_socket.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.js +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.js +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.js +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.js +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.js +0 -0
- /package/esm/transport/{2_transport_provider.js → 1_transport_provider.js} +0 -0
- /package/esm/types/{2_inline_keyboard_button.js → 1_inline_keyboard_button.js} +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/build_message.js +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff.js +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/diff_str.js +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/styles.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.9 → 1.0.10}/types.js +0 -0
- /package/script/transport/{2_transport_provider.js → 1_transport_provider.js} +0 -0
- /package/script/types/{2_inline_keyboard_button.js → 1_inline_keyboard_button.js} +0 -0
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
var
|
|
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, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_uploadPart, _FileManager_handleError, _FileManager_getFileContents, _FileManager_CUSTOM_EMOJI_TTL;
|
|
1
|
+
var _a;
|
|
13
2
|
/**
|
|
14
3
|
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
15
4
|
* Copyright (C) 2023-2025 Roj <https://roj.im/>
|
|
@@ -37,39 +26,58 @@ import { Api } from "../2_tl.js";
|
|
|
37
26
|
import { getDc } from "../3_transport.js";
|
|
38
27
|
import { constructSticker, deserializeFileId, FileType, PhotoSourceType, serializeFileId, toUniqueFileId } from "../3_types.js";
|
|
39
28
|
import { STICKER_SET_NAME_TTL } from "../4_constants.js";
|
|
29
|
+
import { StickersetInvalid } from "../4_errors.js";
|
|
40
30
|
import { UPLOAD_REQUEST_PER_CONNECTION } from "./0_utilities.js";
|
|
41
31
|
export class FileManager {
|
|
32
|
+
#c;
|
|
33
|
+
#Lupload;
|
|
34
|
+
static #UPLOAD_MAX_CHUNK_SIZE = 512 * kilobyte;
|
|
35
|
+
static #DOWNLOAD_MAX_CHUNK_SIZE = 1 * megabyte;
|
|
36
|
+
static #BIG_FILE_THRESHOLD = 10 * megabyte;
|
|
42
37
|
constructor(c) {
|
|
43
|
-
|
|
44
|
-
_FileManager_c.set(this, void 0);
|
|
45
|
-
_FileManager_Lupload.set(this, void 0);
|
|
46
|
-
__classPrivateFieldSet(this, _FileManager_c, c, "f");
|
|
38
|
+
this.#c = c;
|
|
47
39
|
const L = getLogger("FileManager").client(c.id);
|
|
48
|
-
|
|
40
|
+
this.#Lupload = L.branch("upload");
|
|
41
|
+
}
|
|
42
|
+
#progressIds = new Set();
|
|
43
|
+
getProgressId() {
|
|
44
|
+
let id;
|
|
45
|
+
do {
|
|
46
|
+
id = getRandomId();
|
|
47
|
+
} while (id === 0n || this.#progressIds.has(id));
|
|
48
|
+
this.#progressIds.add(id);
|
|
49
|
+
return Promise.resolve(String(id));
|
|
49
50
|
}
|
|
50
51
|
async upload(file, params, checkName, allowStream = true) {
|
|
51
|
-
|
|
52
|
+
if (params?.progressId !== undefined && !this.#progressIds.has(BigInt(params.progressId))) {
|
|
53
|
+
throw new InputError("Invalid progressId.");
|
|
54
|
+
}
|
|
55
|
+
if (params?.progressId !== undefined) {
|
|
56
|
+
this.#progressIds.delete(BigInt(params.progressId));
|
|
57
|
+
}
|
|
58
|
+
let { size, name, contents } = await _a.#getFileContents(file, params, allowStream);
|
|
52
59
|
if (checkName) {
|
|
53
60
|
name = checkName(name);
|
|
54
61
|
}
|
|
55
62
|
if (size == 0 || size < -1) {
|
|
56
63
|
throw new InputError("Invalid file size.");
|
|
57
64
|
}
|
|
58
|
-
const poolSize = await
|
|
59
|
-
const chunkSize = params?.chunkSize ??
|
|
60
|
-
_a.validateChunkSize(chunkSize,
|
|
61
|
-
const
|
|
62
|
-
const
|
|
65
|
+
const poolSize = await this.#c.getUploadPoolSize();
|
|
66
|
+
const chunkSize = params?.chunkSize ?? _a.#UPLOAD_MAX_CHUNK_SIZE;
|
|
67
|
+
_a.validateChunkSize(chunkSize, _a.#UPLOAD_MAX_CHUNK_SIZE);
|
|
68
|
+
const mustTrackProgress = params?.progressId !== undefined;
|
|
69
|
+
const fileId = params?.progressId !== undefined ? BigInt(params.progressId) : getRandomId();
|
|
70
|
+
const isBig = contents instanceof Uint8Array ? contents.length > _a.#BIG_FILE_THRESHOLD : true;
|
|
63
71
|
const whatIsUploaded = contents instanceof Uint8Array ? (isBig ? "big file" : "file") + " of size " + size : "stream";
|
|
64
|
-
|
|
72
|
+
this.#Lupload.debug("uploading " + whatIsUploaded + " with chunk size of " + chunkSize + " and pool size of " + poolSize + " and file ID of " + fileId);
|
|
65
73
|
let result;
|
|
66
74
|
if (contents instanceof Uint8Array) {
|
|
67
|
-
result = await
|
|
75
|
+
result = await this.#uploadBuffer(contents, fileId, mustTrackProgress, chunkSize, poolSize, params?.signal);
|
|
68
76
|
}
|
|
69
77
|
else {
|
|
70
|
-
result = await
|
|
78
|
+
result = await this.#uploadStream(contents, fileId, mustTrackProgress, chunkSize, poolSize, params?.signal);
|
|
71
79
|
}
|
|
72
|
-
|
|
80
|
+
this.#Lupload.debug(`[${fileId}] uploaded ` + result.parts + " part(s)");
|
|
73
81
|
if (result.small) {
|
|
74
82
|
return { _: "inputFile", id: fileId, name, parts: result.parts, md5_checksum: "" };
|
|
75
83
|
}
|
|
@@ -77,20 +85,222 @@ export class FileManager {
|
|
|
77
85
|
return { _: "inputFileBig", id: fileId, name, parts: result.parts };
|
|
78
86
|
}
|
|
79
87
|
}
|
|
88
|
+
async #uploadStream(stream, fileId, mustTrackProgress, chunkSize, poolSize, signal) {
|
|
89
|
+
let part;
|
|
90
|
+
let promises = new Array();
|
|
91
|
+
let ms = 0.05;
|
|
92
|
+
let uploaded = 0;
|
|
93
|
+
for await (part of iterateReadableStream(stream.pipeThrough(new PartStream(chunkSize)))) {
|
|
94
|
+
if (!part.small && part.part > 0) {
|
|
95
|
+
await delay(ms);
|
|
96
|
+
ms = Math.max(ms * .8, 0.003);
|
|
97
|
+
}
|
|
98
|
+
promises.push(this.#uploadPart(fileId, part.totalParts, !part.small, part.part, part.bytes, signal).then(() => {
|
|
99
|
+
if (mustTrackProgress) {
|
|
100
|
+
uploaded += part.bytes.length;
|
|
101
|
+
this.#c.handleUpdate({
|
|
102
|
+
uploadProgress: {
|
|
103
|
+
id: String(fileId),
|
|
104
|
+
uploaded,
|
|
105
|
+
total: 0,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
|
|
111
|
+
await Promise.all(promises);
|
|
112
|
+
promises = [];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await Promise.all(promises);
|
|
116
|
+
return { small: part.small, parts: part.totalParts };
|
|
117
|
+
}
|
|
118
|
+
async #uploadBuffer(buffer, fileId, mustTrackProgress, chunkSize, poolSize, signal) {
|
|
119
|
+
const isBig = buffer.byteLength > _a.#BIG_FILE_THRESHOLD;
|
|
120
|
+
const partCount = Math.ceil(buffer.byteLength / chunkSize);
|
|
121
|
+
let promises = new Array();
|
|
122
|
+
let started = false;
|
|
123
|
+
let ms = 0.05;
|
|
124
|
+
let uploaded = 0;
|
|
125
|
+
main: for (let part = 0; part < partCount;) {
|
|
126
|
+
for (let i = 0; i < poolSize; ++i) {
|
|
127
|
+
for (let i = 0; i < UPLOAD_REQUEST_PER_CONNECTION; ++i) {
|
|
128
|
+
const start = part * chunkSize;
|
|
129
|
+
const end = start + chunkSize;
|
|
130
|
+
const bytes = buffer.subarray(start, end);
|
|
131
|
+
if (!bytes.length) {
|
|
132
|
+
break main;
|
|
133
|
+
}
|
|
134
|
+
if (!started) {
|
|
135
|
+
started = true;
|
|
136
|
+
}
|
|
137
|
+
else if (isBig && part > 0) {
|
|
138
|
+
await delay(ms);
|
|
139
|
+
ms = Math.max(ms * .8, 0.003);
|
|
140
|
+
}
|
|
141
|
+
promises.push(this.#uploadPart(fileId, partCount, isBig, part++, bytes, signal).then(() => {
|
|
142
|
+
if (mustTrackProgress) {
|
|
143
|
+
uploaded += bytes.length;
|
|
144
|
+
this.#c.handleUpdate({
|
|
145
|
+
uploadProgress: {
|
|
146
|
+
id: String(fileId),
|
|
147
|
+
uploaded,
|
|
148
|
+
total: buffer.length,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}));
|
|
153
|
+
if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
|
|
154
|
+
await Promise.all(promises);
|
|
155
|
+
promises = [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
await Promise.all(promises);
|
|
160
|
+
promises = [];
|
|
161
|
+
}
|
|
162
|
+
await Promise.all(promises);
|
|
163
|
+
return { small: !isBig, parts: partCount };
|
|
164
|
+
}
|
|
165
|
+
async #uploadPart(fileId, partCount, isBig, index, bytes, signal) {
|
|
166
|
+
let retryIn = 1;
|
|
167
|
+
let errorCount = 0;
|
|
168
|
+
while (true) {
|
|
169
|
+
try {
|
|
170
|
+
signal?.throwIfAborted();
|
|
171
|
+
this.#Lupload.debug(`[${fileId}] uploading part ` + (index + 1));
|
|
172
|
+
if (isBig) {
|
|
173
|
+
await this.#c.invoke({ _: "upload.saveBigFilePart", file_id: fileId, file_part: index, bytes: bytes, file_total_parts: partCount }, { type: "upload" });
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await this.#c.invoke({ _: "upload.saveFilePart", file_id: fileId, bytes: bytes, file_part: index }, { type: "upload" });
|
|
177
|
+
}
|
|
178
|
+
this.#Lupload.debug(`[${fileId}] uploaded part ` + (index + 1));
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
signal?.throwIfAborted();
|
|
183
|
+
this.#Lupload.debug(`[${fileId}] failed to upload part ` + (index + 1));
|
|
184
|
+
++errorCount;
|
|
185
|
+
if (errorCount > 20) {
|
|
186
|
+
retryIn = 0;
|
|
187
|
+
errorCount = 20;
|
|
188
|
+
}
|
|
189
|
+
await this.#handleError(err, retryIn, `[${fileId}-${index + 1}]`);
|
|
190
|
+
retryIn += 2;
|
|
191
|
+
if (retryIn > 11) {
|
|
192
|
+
retryIn = 11;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async #handleError(err, retryIn, logPrefix) {
|
|
198
|
+
if (retryIn > 0) {
|
|
199
|
+
this.#Lupload.warning(`${logPrefix} retrying in ${retryIn} seconds`);
|
|
200
|
+
await delay(retryIn * SECOND);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
static async #getFileContents(source, params, allowStream) {
|
|
207
|
+
let name = params?.fileName?.trim() || "file";
|
|
208
|
+
let contents;
|
|
209
|
+
let size = -1;
|
|
210
|
+
if (source instanceof Uint8Array) {
|
|
211
|
+
contents = source;
|
|
212
|
+
size = source.byteLength;
|
|
213
|
+
}
|
|
214
|
+
else if (source instanceof ReadableStream) {
|
|
215
|
+
if (!allowStream) {
|
|
216
|
+
throw new InputError("Streamed upload not allowed.");
|
|
217
|
+
}
|
|
218
|
+
contents = source;
|
|
219
|
+
}
|
|
220
|
+
else if (typeof source === "object" && source != null && (Symbol.iterator in source || Symbol.asyncIterator in source)) {
|
|
221
|
+
if (!allowStream) {
|
|
222
|
+
throw new InputError("Streamed upload not allowed.");
|
|
223
|
+
}
|
|
224
|
+
contents = new ReadableStream({
|
|
225
|
+
pull: Symbol.asyncIterator in source
|
|
226
|
+
? async (controller) => {
|
|
227
|
+
const { value, done } = await source.next();
|
|
228
|
+
done ? controller.close() : controller.enqueue(value);
|
|
229
|
+
}
|
|
230
|
+
: (controller) => {
|
|
231
|
+
const { value, done } = source.next();
|
|
232
|
+
done ? controller.close() : controller.enqueue(value);
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
let url;
|
|
238
|
+
try {
|
|
239
|
+
url = new URL(source).toString();
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
let path_;
|
|
243
|
+
if (typeof source === "string") {
|
|
244
|
+
if (isAbsolute(source)) {
|
|
245
|
+
path_ = source;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
// @ts-ignore: lib
|
|
249
|
+
path_ = join(dntShim.Deno.cwd(), source);
|
|
250
|
+
}
|
|
251
|
+
url = toFileUrl(path_).toString();
|
|
252
|
+
name = basename(path_);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
unreachable();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const response = await fetch(url);
|
|
259
|
+
if (response.body == null) {
|
|
260
|
+
throw new InputError("Invalid response");
|
|
261
|
+
}
|
|
262
|
+
if (name == "file") {
|
|
263
|
+
const contentType = response.headers.get("content-type")?.split(";")[0].trim();
|
|
264
|
+
if (contentType) {
|
|
265
|
+
name += extension(contentType);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const maybeFileName = new URL(response.url).pathname.split("/")
|
|
269
|
+
.filter((v) => v)
|
|
270
|
+
.slice(-1)[0]
|
|
271
|
+
.trim();
|
|
272
|
+
if (maybeFileName) {
|
|
273
|
+
name += extension(extname(maybeFileName));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const contentLength = Number(response.headers.get("content-length"));
|
|
278
|
+
if (!isNaN(contentLength)) {
|
|
279
|
+
size = contentLength;
|
|
280
|
+
}
|
|
281
|
+
if (allowStream) {
|
|
282
|
+
contents = response.body;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
contents = new Uint8Array(await response.arrayBuffer());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return { size: params?.fileSize ? params.fileSize : size, name, contents };
|
|
289
|
+
}
|
|
80
290
|
async *downloadInner(location, dcId, params) {
|
|
81
291
|
const signal = params?.signal;
|
|
82
292
|
signal?.throwIfAborted();
|
|
83
293
|
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
84
|
-
if (id != null &&
|
|
85
|
-
const file = await
|
|
294
|
+
if (id != null && this.#c.storage.supportsFiles) {
|
|
295
|
+
const file = await this.#c.storage.getFile(id);
|
|
86
296
|
const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
|
|
87
297
|
if (file != null && file[0] > 0) {
|
|
88
|
-
yield*
|
|
298
|
+
yield* this.#c.storage.iterFileParts(id, file[0], partOffset, signal);
|
|
89
299
|
return;
|
|
90
300
|
}
|
|
91
301
|
}
|
|
92
|
-
const chunkSize = params?.chunkSize ??
|
|
93
|
-
_a.validateChunkSize(chunkSize,
|
|
302
|
+
const chunkSize = params?.chunkSize ?? _a.#DOWNLOAD_MAX_CHUNK_SIZE;
|
|
303
|
+
_a.validateChunkSize(chunkSize, _a.#DOWNLOAD_MAX_CHUNK_SIZE);
|
|
94
304
|
if (params?.offset !== undefined) {
|
|
95
305
|
_a.validateOffset(params.offset);
|
|
96
306
|
}
|
|
@@ -105,18 +315,18 @@ export class FileManager {
|
|
|
105
315
|
let retryIn = 1;
|
|
106
316
|
let errorCount = 0;
|
|
107
317
|
try {
|
|
108
|
-
const file = await
|
|
318
|
+
const file = await this.#c.invoke({ _: "upload.getFile", location, offset, limit }, { dc, type: "download" });
|
|
109
319
|
signal?.throwIfAborted();
|
|
110
320
|
if (Api.is("upload.file", file)) {
|
|
111
321
|
yield file.bytes;
|
|
112
322
|
if (id != null) {
|
|
113
|
-
await
|
|
323
|
+
await this.#c.storage.saveFilePart(id, part, file.bytes);
|
|
114
324
|
signal?.throwIfAborted();
|
|
115
325
|
}
|
|
116
326
|
++part;
|
|
117
327
|
if (file.bytes.length < limit) {
|
|
118
328
|
if (id != null) {
|
|
119
|
-
await
|
|
329
|
+
await this.#c.storage.setFilePartCount(id, part + 1, chunkSize);
|
|
120
330
|
signal?.throwIfAborted();
|
|
121
331
|
}
|
|
122
332
|
break;
|
|
@@ -140,7 +350,7 @@ export class FileManager {
|
|
|
140
350
|
retryIn = 0;
|
|
141
351
|
errorCount = 0;
|
|
142
352
|
}
|
|
143
|
-
await
|
|
353
|
+
await this.#handleError(err, retryIn, `[${id}-${part + 1}]`);
|
|
144
354
|
signal?.throwIfAborted();
|
|
145
355
|
retryIn += 2;
|
|
146
356
|
if (retryIn > 11) {
|
|
@@ -183,7 +393,7 @@ export class FileManager {
|
|
|
183
393
|
unreachable();
|
|
184
394
|
}
|
|
185
395
|
const big = fileId_.location.source.type == PhotoSourceType.ChatPhotoBig;
|
|
186
|
-
const peer = await
|
|
396
|
+
const peer = await this.#c.getInputPeer(Number(fileId_.location.source.chatId));
|
|
187
397
|
const location = { _: "inputPeerPhotoFileLocation", big: big ? true : undefined, peer, photo_id: fileId_.location.id };
|
|
188
398
|
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
189
399
|
break;
|
|
@@ -227,17 +437,28 @@ export class FileManager {
|
|
|
227
437
|
}
|
|
228
438
|
}
|
|
229
439
|
async getStickerSetName(inputStickerSet, hash = 0) {
|
|
230
|
-
const maybeStickerSetName = await
|
|
440
|
+
const maybeStickerSetName = await this.#c.messageStorage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
|
|
231
441
|
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < STICKER_SET_NAME_TTL) {
|
|
232
442
|
return maybeStickerSetName[0];
|
|
233
443
|
}
|
|
234
444
|
else {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
445
|
+
try {
|
|
446
|
+
const stickerSet = await this.#c.invoke({ _: "messages.getStickerSet", stickerset: inputStickerSet, hash });
|
|
447
|
+
const name = Api.as("messages.stickerSet", stickerSet).set.short_name;
|
|
448
|
+
await this.#c.messageStorage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
|
|
449
|
+
return name;
|
|
450
|
+
}
|
|
451
|
+
catch (err) {
|
|
452
|
+
if (err instanceof StickersetInvalid) {
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
throw err;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
239
459
|
}
|
|
240
460
|
}
|
|
461
|
+
static #CUSTOM_EMOJI_TTL = 30 * MINUTE;
|
|
241
462
|
async getCustomEmojiStickers(id) {
|
|
242
463
|
id = Array.isArray(id) ? id : [id];
|
|
243
464
|
if (!id.length) {
|
|
@@ -246,8 +467,8 @@ export class FileManager {
|
|
|
246
467
|
const stickers = new Array();
|
|
247
468
|
let shouldFetch = false;
|
|
248
469
|
for (const id_ of id) {
|
|
249
|
-
const maybeDocument = await
|
|
250
|
-
if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <=
|
|
470
|
+
const maybeDocument = await this.#c.messageStorage.getCustomEmojiDocument(BigInt(id_));
|
|
471
|
+
if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= _a.#CUSTOM_EMOJI_TTL) {
|
|
251
472
|
const document_ = maybeDocument[0];
|
|
252
473
|
const fileId_ = {
|
|
253
474
|
type: FileType.Document,
|
|
@@ -268,9 +489,9 @@ export class FileManager {
|
|
|
268
489
|
if (!shouldFetch) {
|
|
269
490
|
return stickers;
|
|
270
491
|
}
|
|
271
|
-
const documents_ = (await
|
|
492
|
+
const documents_ = (await this.#c.invoke({ _: "messages.getCustomEmojiDocuments", document_id: id.map(BigInt) })).map((v) => Api.as("document", v));
|
|
272
493
|
for (const [i, document_] of documents_.entries()) {
|
|
273
|
-
await
|
|
494
|
+
await this.#c.messageStorage.setCustomEmojiDocument(document_.id, document_);
|
|
274
495
|
const fileId_ = {
|
|
275
496
|
type: FileType.Document,
|
|
276
497
|
dcId: document_.dc_id,
|
|
@@ -285,181 +506,4 @@ export class FileManager {
|
|
|
285
506
|
return stickers;
|
|
286
507
|
}
|
|
287
508
|
}
|
|
288
|
-
_a = FileManager
|
|
289
|
-
let part;
|
|
290
|
-
let promises = new Array();
|
|
291
|
-
let ms = 0.05;
|
|
292
|
-
for await (part of iterateReadableStream(stream.pipeThrough(new PartStream(chunkSize)))) {
|
|
293
|
-
if (!part.small && part.part > 0) {
|
|
294
|
-
await delay(ms);
|
|
295
|
-
ms = Math.max(ms * .8, 0.003);
|
|
296
|
-
}
|
|
297
|
-
promises.push(__classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadPart).call(this, fileId, part.totalParts, !part.small, part.part, part.bytes, signal));
|
|
298
|
-
if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
|
|
299
|
-
await Promise.all(promises);
|
|
300
|
-
promises = [];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
await Promise.all(promises);
|
|
304
|
-
return { small: part.small, parts: part.totalParts };
|
|
305
|
-
}, _FileManager_uploadBuffer = async function _FileManager_uploadBuffer(buffer, fileId, chunkSize, poolSize, signal) {
|
|
306
|
-
const isBig = buffer.byteLength > __classPrivateFieldGet(_a, _a, "f", _FileManager_BIG_FILE_THRESHOLD);
|
|
307
|
-
const partCount = Math.ceil(buffer.byteLength / chunkSize);
|
|
308
|
-
let promises = new Array();
|
|
309
|
-
let started = false;
|
|
310
|
-
let ms = 0.05;
|
|
311
|
-
main: for (let part = 0; part < partCount;) {
|
|
312
|
-
for (let i = 0; i < poolSize; ++i) {
|
|
313
|
-
for (let i = 0; i < UPLOAD_REQUEST_PER_CONNECTION; ++i) {
|
|
314
|
-
const start = part * chunkSize;
|
|
315
|
-
const end = start + chunkSize;
|
|
316
|
-
const bytes = buffer.subarray(start, end);
|
|
317
|
-
if (!bytes.length) {
|
|
318
|
-
break main;
|
|
319
|
-
}
|
|
320
|
-
if (!started) {
|
|
321
|
-
started = true;
|
|
322
|
-
}
|
|
323
|
-
else if (isBig && part > 0) {
|
|
324
|
-
await delay(ms);
|
|
325
|
-
ms = Math.max(ms * .8, 0.003);
|
|
326
|
-
}
|
|
327
|
-
promises.push(__classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_uploadPart).call(this, fileId, partCount, isBig, part++, bytes, signal));
|
|
328
|
-
if (promises.length == poolSize * UPLOAD_REQUEST_PER_CONNECTION) {
|
|
329
|
-
await Promise.all(promises);
|
|
330
|
-
promises = [];
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
await Promise.all(promises);
|
|
335
|
-
promises = [];
|
|
336
|
-
}
|
|
337
|
-
await Promise.all(promises);
|
|
338
|
-
return { small: !isBig, parts: partCount };
|
|
339
|
-
}, _FileManager_uploadPart = async function _FileManager_uploadPart(fileId, partCount, isBig, index, bytes, signal) {
|
|
340
|
-
let retryIn = 1;
|
|
341
|
-
let errorCount = 0;
|
|
342
|
-
while (true) {
|
|
343
|
-
try {
|
|
344
|
-
signal?.throwIfAborted();
|
|
345
|
-
__classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] uploading part ` + (index + 1));
|
|
346
|
-
if (isBig) {
|
|
347
|
-
await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "upload.saveBigFilePart", file_id: fileId, file_part: index, bytes: bytes, file_total_parts: partCount }, { type: "upload" });
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
await __classPrivateFieldGet(this, _FileManager_c, "f").invoke({ _: "upload.saveFilePart", file_id: fileId, bytes: bytes, file_part: index }, { type: "upload" });
|
|
351
|
-
}
|
|
352
|
-
__classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] uploaded part ` + (index + 1));
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
catch (err) {
|
|
356
|
-
signal?.throwIfAborted();
|
|
357
|
-
__classPrivateFieldGet(this, _FileManager_Lupload, "f").debug(`[${fileId}] failed to upload part ` + (index + 1));
|
|
358
|
-
++errorCount;
|
|
359
|
-
if (errorCount > 20) {
|
|
360
|
-
retryIn = 0;
|
|
361
|
-
errorCount = 20;
|
|
362
|
-
}
|
|
363
|
-
await __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_handleError).call(this, err, retryIn, `[${fileId}-${index + 1}]`);
|
|
364
|
-
retryIn += 2;
|
|
365
|
-
if (retryIn > 11) {
|
|
366
|
-
retryIn = 11;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}, _FileManager_handleError = async function _FileManager_handleError(err, retryIn, logPrefix) {
|
|
371
|
-
if (retryIn > 0) {
|
|
372
|
-
__classPrivateFieldGet(this, _FileManager_Lupload, "f").warning(`${logPrefix} retrying in ${retryIn} seconds`);
|
|
373
|
-
await delay(retryIn * SECOND);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
throw err;
|
|
377
|
-
}
|
|
378
|
-
}, _FileManager_getFileContents = async function _FileManager_getFileContents(source, params, allowStream) {
|
|
379
|
-
let name = params?.fileName?.trim() || "file";
|
|
380
|
-
let contents;
|
|
381
|
-
let size = -1;
|
|
382
|
-
if (source instanceof Uint8Array) {
|
|
383
|
-
contents = source;
|
|
384
|
-
size = source.byteLength;
|
|
385
|
-
}
|
|
386
|
-
else if (source instanceof ReadableStream) {
|
|
387
|
-
if (!allowStream) {
|
|
388
|
-
throw new InputError("Streamed upload not allowed.");
|
|
389
|
-
}
|
|
390
|
-
contents = source;
|
|
391
|
-
}
|
|
392
|
-
else if (typeof source === "object" && source != null && (Symbol.iterator in source || Symbol.asyncIterator in source)) {
|
|
393
|
-
if (!allowStream) {
|
|
394
|
-
throw new InputError("Streamed upload not allowed.");
|
|
395
|
-
}
|
|
396
|
-
contents = new ReadableStream({
|
|
397
|
-
pull: Symbol.asyncIterator in source
|
|
398
|
-
? async (controller) => {
|
|
399
|
-
const { value, done } = await source.next();
|
|
400
|
-
done ? controller.close() : controller.enqueue(value);
|
|
401
|
-
}
|
|
402
|
-
: (controller) => {
|
|
403
|
-
const { value, done } = source.next();
|
|
404
|
-
done ? controller.close() : controller.enqueue(value);
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
let url;
|
|
410
|
-
try {
|
|
411
|
-
url = new URL(source).toString();
|
|
412
|
-
}
|
|
413
|
-
catch {
|
|
414
|
-
let path_;
|
|
415
|
-
if (typeof source === "string") {
|
|
416
|
-
if (isAbsolute(source)) {
|
|
417
|
-
path_ = source;
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
// @ts-ignore: lib
|
|
421
|
-
path_ = join(dntShim.Deno.cwd(), source);
|
|
422
|
-
}
|
|
423
|
-
url = toFileUrl(path_).toString();
|
|
424
|
-
name = basename(path_);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
unreachable();
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const response = await fetch(url);
|
|
431
|
-
if (response.body == null) {
|
|
432
|
-
throw new InputError("Invalid response");
|
|
433
|
-
}
|
|
434
|
-
if (name == "file") {
|
|
435
|
-
const contentType = response.headers.get("content-type")?.split(";")[0].trim();
|
|
436
|
-
if (contentType) {
|
|
437
|
-
name += extension(contentType);
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
const maybeFileName = new URL(response.url).pathname.split("/")
|
|
441
|
-
.filter((v) => v)
|
|
442
|
-
.slice(-1)[0]
|
|
443
|
-
.trim();
|
|
444
|
-
if (maybeFileName) {
|
|
445
|
-
name += extension(extname(maybeFileName));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
const contentLength = Number(response.headers.get("content-length"));
|
|
450
|
-
if (!isNaN(contentLength)) {
|
|
451
|
-
size = contentLength;
|
|
452
|
-
}
|
|
453
|
-
if (allowStream) {
|
|
454
|
-
contents = response.body;
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
contents = new Uint8Array(await response.arrayBuffer());
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return { size: params?.fileSize ? params.fileSize : size, name, contents };
|
|
461
|
-
};
|
|
462
|
-
_FileManager_UPLOAD_MAX_CHUNK_SIZE = { value: 512 * kilobyte };
|
|
463
|
-
_FileManager_DOWNLOAD_MAX_CHUNK_SIZE = { value: 1 * megabyte };
|
|
464
|
-
_FileManager_BIG_FILE_THRESHOLD = { value: 10 * megabyte };
|
|
465
|
-
_FileManager_CUSTOM_EMOJI_TTL = { value: 30 * MINUTE };
|
|
509
|
+
_a = FileManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_file_manager_test.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager_test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"2_file_manager_test.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,2BAA2B,CAAC"}
|
|
@@ -17,29 +17,17 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _NetworkStatisticsManager_c;
|
|
32
20
|
export class NetworkStatisticsManager {
|
|
21
|
+
#c;
|
|
33
22
|
constructor(c) {
|
|
34
|
-
|
|
35
|
-
__classPrivateFieldSet(this, _NetworkStatisticsManager_c, c, "f");
|
|
23
|
+
this.#c = c;
|
|
36
24
|
}
|
|
37
25
|
async getNetworkStatistics() {
|
|
38
26
|
const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
this.#c.storage.get(["netstat_messages_read"]),
|
|
28
|
+
this.#c.storage.get(["netstat_messages_write"]),
|
|
29
|
+
this.#c.storage.get(["netstat_cdn_read"]),
|
|
30
|
+
this.#c.storage.get(["netstat_cdn_write"]),
|
|
43
31
|
]);
|
|
44
32
|
const messages = {
|
|
45
33
|
sent: Number(messagesWrite || 0),
|
|
@@ -55,13 +43,12 @@ export class NetworkStatisticsManager {
|
|
|
55
43
|
return {
|
|
56
44
|
read: async (count) => {
|
|
57
45
|
const key = cdn ? "netstat_cdn_read" : "netstat_messages_read";
|
|
58
|
-
await
|
|
46
|
+
await this.#c.storage.incr([key], count);
|
|
59
47
|
},
|
|
60
48
|
write: async (count) => {
|
|
61
49
|
const key = cdn ? "netstat_cdn_write" : "netstat_messages_write";
|
|
62
|
-
await
|
|
50
|
+
await this.#c.storage.incr([key], count);
|
|
63
51
|
},
|
|
64
52
|
};
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
|
-
_NetworkStatisticsManager_c = new WeakMap();
|