1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 06:18:58 +01:00

optimize url

This commit is contained in:
َAhJ 2023-11-23 18:47:13 +03:30
parent ec4351e09a
commit 2669333ea7

View File

@ -16,7 +16,7 @@
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation * @link https://docs.madelineproto.xyz MadelineProto documentation
*/ */
use League\Uri\Uri;
use League\Uri\Contracts\UriException; use League\Uri\Contracts\UriException;
use danog\MadelineProto\API; use danog\MadelineProto\API;
use danog\MadelineProto\Logger; use danog\MadelineProto\Logger;
@ -106,7 +106,7 @@ class MyEventHandler extends SimpleEventHandler
public function cmdSaveState(PrivateMessage&Incoming&HasMedia&IsNotEdited $message) public function cmdSaveState(PrivateMessage&Incoming&HasMedia&IsNotEdited $message)
{ {
$message->reply('Give me a new name for this file: ', ParseMode::MARKDOWN); $message->reply('Give me a new name for this file: ', ParseMode::MARKDOWN);
$this->states[$message->chatId] = serialize($message->media); $this->states[$message->chatId] = $message->media;
} }
/** /**
@ -117,10 +117,13 @@ class MyEventHandler extends SimpleEventHandler
{ {
$url = $message->commandArgs[0]; $url = $message->commandArgs[0];
$name = $message->commandArgs[1] ?? basename($url); $name = $message->commandArgs[1] ?? basename($url);
if (stripos($url, 'http') !== 0) { try {
$url = "http://$url"; $url = Uri::new($message->commandArgs[0]);
$url->getScheme() || $url = "http://$url";
$this->cmdUpload(new RemoteUrl("$url"), $name, $message);
} catch (UriException $e) {
$message->reply('Error: ' . $e->getMessage());
} }
$this->cmdUpload(new RemoteUrl($url), $name, $message);
} }
/** /**
@ -131,7 +134,7 @@ class MyEventHandler extends SimpleEventHandler
{ {
if (isset($this->states[$message->chatId])) { if (isset($this->states[$message->chatId])) {
$name = $message->message; $name = $message->message;
$url = unserialize($this->states[$message->chatId]); $url = $this->states[$message->chatId];
unset($this->states[$message->chatId]); unset($this->states[$message->chatId]);
$this->cmdUpload($url, $name, $message); $this->cmdUpload($url, $name, $message);
} }