Disallow having more than 65k audios in playlist

This commit is contained in:
Celestora 2022-03-23 16:09:50 +02:00
parent 4171a51e28
commit 7aef23b3cd
2 changed files with 12 additions and 3 deletions

View file

@ -462,7 +462,11 @@ final class Audio extends VKAPIRequestHandler
else if(!$audio->canBeViewedBy($this->getUser()))
$this->fail(201, "Access denied to audio(owner=$owner_id, vid=$audio_id)");
$audio->add($to);
try {
$audio->add($to);
} catch(\OverflowException $ex) {
$this->fail(300, "Album is full");
}
return $audio->getPrettyId();
}

View file

@ -266,8 +266,13 @@ class Audio extends Media
if($this->isInLibraryOf($entity))
return false;
DatabaseConnection::i()->getContext()->table("audio_relations")->insert([
"entity" => $entity->getId() * ($entity instanceof Club ? -1 : 1),
$entityId = $entity->getId() * ($entity instanceof Club ? -1 : 1);
$audioRels = DatabaseConnection::i()->getContext()->table("audio_relations");
if(sizeof($audioRels->where("entity", $entityId)) > 65536)
throw new \OverflowException("Can't have more than 65536 audios in a playlist");
$audioRels->insert([
"entity" => $entityId,
"audio" => $this->getId(),
]);