From 99300304f11bbd991570b3d0401f54bf80c66df3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 27 Dec 2019 21:24:50 +0100 Subject: [PATCH] Save --- README.md | 5 +++- docs | 2 +- src/danog/MadelineProto/InternalDoc.php | 23 +++++++++-------- .../MadelineProto/MTProtoTools/Files.php | 25 +++++++++++-------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 43633621..17a83feb 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Putting it all together](https://docs.madelineproto.xyz/docs/CALLS.html#putting-it-all-together) * [Accepting calls](https://docs.madelineproto.xyz/docs/CALLS.html#accepting-calls) * [Uploading and downloading files](https://docs.madelineproto.xyz/docs/FILES.html) + * [Bot API file IDs](https://docs.madelineproto.xyz/docs/FILES.html#bot-api-file-ids) * [Uploading & sending files](https://docs.madelineproto.xyz/docs/FILES.html#sending-files) * [Security notice](https://docs.madelineproto.xyz/docs/FILES.html#security-notice) * [Photos](https://docs.madelineproto.xyz/docs/FILES.html#inputmediauploadedphoto) @@ -133,13 +134,15 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [Videos](https://docs.madelineproto.xyz/docs/FILES.html#documentattributevideo-to-send-a-video) * [Audio & Voice](https://docs.madelineproto.xyz/docs/FILES.html#documentattributeaudio-to-send-an-audio-file) * [Uploading files](https://docs.madelineproto.xyz/docs/FILES.html#uploading-files) - * [Bot API file IDs](https://docs.madelineproto.xyz/docs/FILES.html#bot-api-file-ids) * [Reusing uploaded files](https://docs.madelineproto.xyz/docs/FILES.html#reusing-uploaded-files) + * [Renaming files](https://docs.madelineproto.xyz/docs/FILES.html#renaming-files) * [Downloading files](https://docs.madelineproto.xyz/docs/FILES.html#downloading-files) * [Extracting download info](https://docs.madelineproto.xyz/docs/FILES.html#extracting-download-info) * [Downloading profile pictures](https://docs.madelineproto.xyz/docs/FILES.html#downloading-profile-pictures) * [Download to directory](https://docs.madelineproto.xyz/docs/FILES.html#download-to-directory) * [Download to file](https://docs.madelineproto.xyz/docs/FILES.html#download-to-file) + * [Download to stream](https://docs.madelineproto.xyz/docs/FILES.html#download-to-stream) + * [Download to callback](https://docs.madelineproto.xyz/docs/FILES.html#download-to-callback) * [Download to browser (streaming)](https://docs.madelineproto.xyz/docs/FILES.html#download-to-browser-with-streams) * [Getting progress](https://docs.madelineproto.xyz/docs/FILES.html#getting-progress) * [Getting info about chats](https://docs.madelineproto.xyz/docs/CHAT_INFO.html) diff --git a/docs b/docs index 4bc0ee99..1e235370 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 4bc0ee99f5e5a2f52b419675b572165452fe824c +Subproject commit 1e235370a12eaeb14892da99833d42638420e722 diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 099b3e05..e003855d 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -4797,7 +4797,7 @@ class InternalDoc extends APIFactory /** * Upload file from stream. * - * @param mixed $stream Stream + * @param mixed $stream PHP resource or AMPHP async stream * @param integer $size File size * @param string $mime Mime type * @param string $file_name File name @@ -4813,19 +4813,22 @@ class InternalDoc extends APIFactory /** * Upload file from callable. * - * @param mixed $callable Callable - * @param integer $size File size - * @param string $mime Mime type - * @param string $file_name File name - * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) - * @param boolean $refetchable Whether each chunk can be refetched more than once - * @param boolean $encrypted Whether to encrypt file for secret chats + * The callable must accept two parameters: int $offset, int $size + * The callable must return a string with the contest of the file at the specified offset and size. + * + * @param mixed $callable Callable + * @param integer $size File size + * @param string $mime Mime type + * @param string $file_name File name + * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) + * @param boolean $seekable Whether chunks can be fetched out of order + * @param boolean $encrypted Whether to encrypt file for secret chats * * @return array */ - public function uploadFromCallable($callable, int $size, string $mime, string $file_name = '', $cb = null, bool $refetchable = true, bool $encrypted = false, array $extra = []) + public function uploadFromCallable($callable, int $size, string $mime, string $file_name = '', $cb = null, bool $seekable = true, bool $encrypted = false, array $extra = []) { - return $this->__call(__FUNCTION__, [$callable, $size, $mime, $file_name, $cb, $refetchable, $encrypted, $extra]); + return $this->__call(__FUNCTION__, [$callable, $size, $mime, $file_name, $cb, $seekable, $encrypted, $extra]); } /** * Upload file to secret chat. diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 6d09454a..8ed655f6 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -146,7 +146,7 @@ trait Files /** * Upload file from stream. * - * @param mixed $stream Stream + * @param mixed $stream PHP resource or AMPHP async stream * @param integer $size File size * @param string $mime Mime type * @param string $file_name File name @@ -218,17 +218,20 @@ trait Files /** * Upload file from callable. * - * @param mixed $callable Callable - * @param integer $size File size - * @param string $mime Mime type - * @param string $file_name File name - * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) - * @param boolean $refetchable Whether each chunk can be refetched more than once - * @param boolean $encrypted Whether to encrypt file for secret chats + * The callable must accept two parameters: int $offset, int $size + * The callable must return a string with the contest of the file at the specified offset and size. + * + * @param mixed $callable Callable + * @param integer $size File size + * @param string $mime Mime type + * @param string $file_name File name + * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) + * @param boolean $seekable Whether chunks can be fetched out of order + * @param boolean $encrypted Whether to encrypt file for secret chats * * @return array */ - public function uploadFromCallable($callable, int $size, string $mime, string $file_name = '', $cb = null, bool $refetchable = true, bool $encrypted = false) + public function uploadFromCallable($callable, int $size, string $mime, string $file_name = '', $cb = null, bool $seekable = true, bool $encrypted = false) { if (\is_object($callable) && $callable instanceof FileCallbackInterface) { $cb = $callable; @@ -267,7 +270,7 @@ trait Files $ige->setIV($iv); $ige->setKey($key); $ige->enableContinuousBuffer(); - $refetchable = false; + $seekable = false; } $ctx = \hash_init('md5'); $promises = []; @@ -299,7 +302,7 @@ trait Files return ['file_id' => $file_id, 'file_part' => $part_num, 'file_total_parts' => $part_total_num, 'bytes' => $bytes]; }, - $refetchable + $seekable ), ['heavy' => true, 'file' => true, 'datacenter' => &$datacenter] );