mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 05:38:57 +01:00
Improve validation
This commit is contained in:
parent
9ae0c3b4fd
commit
f59edfaa53
@ -188,7 +188,7 @@ final class DjLoop extends VoIPLoop
|
||||
private function startPlaying(LocalFile|RemoteUrl|ReadableStream $f, SplQueue $queue, Cancellation $cancellation): void
|
||||
{
|
||||
$it = null;
|
||||
if ($f instanceof LocalFile) {
|
||||
if ($f instanceof LocalFile || $f instanceof RemoteUrl) {
|
||||
try {
|
||||
$it = new Ogg($f, $cancellation);
|
||||
if (!\in_array('MADELINE_ENCODER_V=1', $it->comments, true)) {
|
||||
|
@ -21,6 +21,7 @@ namespace danog\MadelineProto;
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
use Amp\ByteStream\WritableStream;
|
||||
use Amp\Cancellation;
|
||||
use Amp\DeferredCancellation;
|
||||
use Amp\Process\Process;
|
||||
use AssertionError;
|
||||
use Closure;
|
||||
@ -543,9 +544,11 @@ final class Ogg
|
||||
{
|
||||
$ok = false;
|
||||
try {
|
||||
$ogg = new self($f);
|
||||
$cancel = new DeferredCancellation;
|
||||
$ogg = new self($f, $cancel->getCancellation());
|
||||
$ok = \in_array('MADELINE_ENCODER_V=1', $ogg->comments, true);
|
||||
} catch (\Throwable) {}
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
if (!$ok) {
|
||||
throw new AssertionError("The passed file was not generated by MadelineProto or @libtgvoipbot, please pre-convert it using @libtgvoip bot or install FFI and ffmpeg to perform realtime conversion!");
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace danog\MadelineProto\VoIP;
|
||||
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
use Amp\DeferredFuture;
|
||||
use AssertionError;
|
||||
use danog\MadelineProto\LocalFile;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Magic;
|
||||
@ -163,8 +164,10 @@ trait AuthKeyHandler
|
||||
public function callPlay(int $id, LocalFile|RemoteUrl|ReadableStream $file): void
|
||||
{
|
||||
if (!Magic::canConvertOgg()) {
|
||||
if ($file instanceof LocalFile) {
|
||||
if ($file instanceof LocalFile || $file instanceof RemoteUrl) {
|
||||
Ogg::validateOgg($file);
|
||||
} else {
|
||||
throw new AssertionError("The passed file was not generated by MadelineProto or @libtgvoipbot, please pre-convert it using @libtgvoip bot or install FFI and ffmpeg to perform realtime conversion!");
|
||||
}
|
||||
}
|
||||
($this->calls[$id] ?? null)?->play($file);
|
||||
@ -235,8 +238,10 @@ trait AuthKeyHandler
|
||||
{
|
||||
if (!Magic::canConvertOgg()) {
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof LocalFile) {
|
||||
if ($file instanceof LocalFile || $file instanceof RemoteUrl) {
|
||||
Ogg::validateOgg($file);
|
||||
} else {
|
||||
throw new AssertionError("The passed file was not generated by MadelineProto or @libtgvoipbot, please pre-convert it using @libtgvoip bot or install FFI and ffmpeg to perform realtime conversion!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user