From edde6347825af19e5a9d19fa3f0e0f1bab6fdc56 Mon Sep 17 00:00:00 2001 From: lalka2018 <99399973+lalka2016@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:12:04 +0300 Subject: [PATCH] =?UTF-8?q?(=D1=81=D0=BC=D0=B5=D1=88=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B8=D1=82=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Теперь на странице пользователя/группы показываются три случайные песни, а не первые три как раньше - Теперь пробел на странице аудио не перемещает вас в низ страницы - Оптимизирован мини-плеер, теперь он инициализируется при любом нажатии на него, а не при наведении - Теперь при завершении проигрывания трека в мини-плеере он ищет другой трек рядом, и если находит то воспроизводит. Будет удобно для постов с подборками треков - Поиск теперь показывает 14 результатов - Теперь при возникновении ошибки загрузки аудио она нормально отображается - Вместе с плеером на странице с аудиозаписями теперь двигаются и вкладки - Добавление аудио в группу по идее должно нормально работать --- Web/Models/Entities/Audio.php | 4 +- Web/Models/Entities/Playlist.php | 5 ++ Web/Models/Repositories/Audios.php | 27 ++++++ Web/Presenters/AudioPresenter.php | 31 ++++++- Web/Presenters/GroupPresenter.php | 2 +- Web/Presenters/SearchPresenter.php | 3 +- Web/Presenters/UserPresenter.php | 2 +- Web/Presenters/templates/Audio/Playlist.xml | 17 ++++ Web/Presenters/templates/Audio/player.xml | 2 +- Web/Presenters/templates/User/View.xml | 2 +- Web/static/css/audios.css | 7 ++ Web/static/js/al_music.js | 91 ++++++++++++++++----- install/sqls/gamma-00000-disco.sql | 2 + locales/en.strings | 19 ++++- locales/ru.strings | 19 ++++- 15 files changed, 200 insertions(+), 33 deletions(-) diff --git a/Web/Models/Entities/Audio.php b/Web/Models/Entities/Audio.php index 43c9dba6..84e263aa 100644 --- a/Web/Models/Entities/Audio.php +++ b/Web/Models/Entities/Audio.php @@ -120,14 +120,14 @@ class Audio extends Media Shell::powershell("-executionpolicy bypass", "-File", __DIR__ . "/../shell/processAudio.ps1", ...$args) ->start(); } else { - exit("Linux uploads are not implemented"); + throw new \BadMethodCallException("Linux uploads are not implemented"); } # Wait until processAudio will consume the file $start = time(); while(file_exists($filename)) if(time() - $start > 5) - exit("Timed out waiting for ffmpeg"); // TODO replace with exception + throw new \RuntimeException("Timed out waiting FFMPEG"); } catch(UnknownCommandException $ucex) { exit(OPENVK_ROOT_CONF["openvk"]["debug"] ? "bash/pwsh is not installed" : VIDEOS_FRIENDLY_ERROR); diff --git a/Web/Models/Entities/Playlist.php b/Web/Models/Entities/Playlist.php index 813edbe0..685f4cc5 100644 --- a/Web/Models/Entities/Playlist.php +++ b/Web/Models/Entities/Playlist.php @@ -222,4 +222,9 @@ class Playlist extends MediaCollection return $cover; } + + function getURL(): string + { + return "/playlist" . $this->getOwner()->getRealId() . "_" . $this->getId(); + } } \ No newline at end of file diff --git a/Web/Models/Repositories/Audios.php b/Web/Models/Repositories/Audios.php index deae943e..ad5e822e 100644 --- a/Web/Models/Repositories/Audios.php +++ b/Web/Models/Repositories/Audios.php @@ -109,6 +109,33 @@ class Audios return $this->getByEntityID($user->getId(), ($perPage * ($page - 1)), $perPage, $deleted); } + function getRandomThreeAudiosByEntityId(int $id): Array + { + $iter = $this->rels->where("entity", $id); + $ids = []; + + foreach($iter as $it) + $ids[] = $it->audio; + + $shuffleSeed = openssl_random_pseudo_bytes(6); + $shuffleSeed = hexdec(bin2hex($shuffleSeed)); + + $ids = knuth_shuffle($ids, $shuffleSeed); + $ids = array_slice($ids, 0, 3); + $audios = []; + + foreach($ids as $id) { + $audio = $this->get((int)$id); + + if(!$audio || $audio->isDeleted()) + continue; + + $audios[] = $audio; + } + + return $audios; + } + function getByClub(Club $club, int $page = 1, ?int $perPage = NULL, ?int& $deleted = nullptr): \Traversable { return $this->getByEntityID($club->getId() * -1, ($perPage * ($page - 1)), $perPage, $deleted); diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php index a8f49dfb..9cdbc095 100644 --- a/Web/Presenters/AudioPresenter.php +++ b/Web/Presenters/AudioPresenter.php @@ -162,7 +162,30 @@ final class AudioPresenter extends OpenVKPresenter } else { $err = !isset($upload) ? 65536 : $upload["error"]; $err = str_pad(dechex($err), 9, "0", STR_PAD_LEFT); - $this->flashFail("err", tr("error"), tr("error_generic") . "Upload error: 0x$err", null, $isAjax); + $readableError = tr("error_generic"); + + switch($upload["error"]) { + default: + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $readableError = tr("file_too_big"); + break; + case UPLOAD_ERR_PARTIAL: + $readableError = tr("file_loaded_partially"); + break; + case UPLOAD_ERR_NO_FILE: + $readableError = tr("file_not_uploaded"); + break; + case UPLOAD_ERR_NO_TMP_DIR: + $readableError = "Missing a temporary folder."; + break; + case UPLOAD_ERR_CANT_WRITE: + case UPLOAD_ERR_EXTENSION: + $readableError = "Failed to write file to disk. "; + break; + } + + $this->flashFail("err", tr("error"), $readableError . " " . tr("error_code", $err), null, $isAjax); } $performer = $this->postParam("performer"); @@ -186,6 +209,12 @@ final class AudioPresenter extends OpenVKPresenter } catch(\DomainException $ex) { $e = $ex->getMessage(); $this->flashFail("err", tr("error"), tr("media_file_corrupted_or_too_large") . " $e.", null, $isAjax); + } catch(\RuntimeException $ex) { + $this->flashFail("err", tr("error"), tr("ffmpeg_timeout"), null, $isAjax); + } catch(\BadMethodCallException $ex) { + $this->flashFail("err", tr("error"), "Загрузка аудио под Linux на данный момент не реализована. Следите за обновлениями: https://github.com/openvk/openvk/pull/512/commits", null, $isAjax); + } catch(\Exception $ex) { + $this->flashFail("err", tr("error"), tr("ffmpeg_not_installed"), null, $isAjax); } $audio->save(); diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index adf536de..eb8f446c 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -31,7 +31,7 @@ final class GroupPresenter extends OpenVKPresenter $this->template->albumsCount = (new Albums)->getClubAlbumsCount($club); $this->template->topics = (new Topics)->getLastTopics($club, 3); $this->template->topicsCount = (new Topics)->getClubTopicsCount($club); - $this->template->audios = (new Audios)->getByClub($club, 1, 3); + $this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($club->getRealId()); $this->template->audiosCount = (new Audios)->getClubCollectionSize($club); } diff --git a/Web/Presenters/SearchPresenter.php b/Web/Presenters/SearchPresenter.php index e9dbf3d1..d80c06c3 100644 --- a/Web/Presenters/SearchPresenter.php +++ b/Web/Presenters/SearchPresenter.php @@ -104,12 +104,13 @@ final class SearchPresenter extends OpenVKPresenter $repo = $repos[$type] or $this->throwError(400, "Bad Request", "Invalid search entity $type."); $results = $this->{$repo}->find($query, $parameters, $sort); - $iterator = $results->page($page); + $iterator = $results->page($page, 14); $count = $results->size(); $this->template->iterator = iterator_to_array($iterator); $this->template->count = $count; $this->template->type = $type; $this->template->page = $page; + $this->template->perPage = 14; } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index ee12559f..2aa12893 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -45,7 +45,7 @@ final class UserPresenter extends OpenVKPresenter $this->template->videosCount = (new Videos)->getUserVideosCount($user); $this->template->notes = (new Notes)->getUserNotes($user, 1, 4); $this->template->notesCount = (new Notes)->getUserNotesCount($user); - $this->template->audios = (new Audios)->getByUser($user, 1, 3); + $this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($user->getId()); $this->template->audiosCount = (new Audios)->getUserCollectionSize($user); $this->template->user = $user; diff --git a/Web/Presenters/templates/Audio/Playlist.xml b/Web/Presenters/templates/Audio/Playlist.xml index 5d01f7e2..82d145a8 100644 --- a/Web/Presenters/templates/Audio/Playlist.xml +++ b/Web/Presenters/templates/Audio/Playlist.xml @@ -2,6 +2,23 @@ {block title}{_playlist}{/block} +{block headIncludes} + + + + + + + +{/block} + {block header} {$owner->getCanonicalName()} » diff --git a/Web/Presenters/templates/Audio/player.xml b/Web/Presenters/templates/Audio/player.xml index e560db6f..0e959f8e 100644 --- a/Web/Presenters/templates/Audio/player.xml +++ b/Web/Presenters/templates/Audio/player.xml @@ -1,7 +1,7 @@ {php $id = $audio->getId() . rand(0, 1000)} {php $isWithdrawn = $audio->isWithdrawn()} {php $editable = isset($thisUser) && $audio->canBeModifiedBy($thisUser)} -
+