diff --git a/VKAPI/Handlers/Audio.php b/VKAPI/Handlers/Audio.php index 004daef4..90d060fb 100644 --- a/VKAPI/Handlers/Audio.php +++ b/VKAPI/Handlers/Audio.php @@ -581,13 +581,31 @@ final class Audio extends VKAPIRequestHandler ]; } - function searchAlbums(string $query, int $offset = 0, int $limit = 25, int $drop_private = 0): object + function searchAlbums(string $query = '', int $offset = 0, int $limit = 25, int $drop_private = 0, int $order = 0, int $from_me = 0): object { $this->requireUser(); $playlists = []; - $search = (new Audios)->searchPlaylists($query)->offsetLimit($offset, $limit); - foreach($search as $playlist) { + $params = []; + $order_str = 'id'; + switch($order) { + default: + case 0: + $order_str = 'id'; + break; + case 1: + $order_str = 'length'; + break; + case 2: + $order_str = 'listens'; + break; + } + + if($from_me === 1) + $params['from_me'] = $this->getUser()->getId(); + + $search = (new Audios)->findPlaylists($query, $params, ['type' => $order_str, 'invert' => false]); + foreach($search->offsetLimit($offset, $limit) as $playlist) { if(!$playlist->canBeViewedBy($this->getUser())) { if($drop_private == 0) $playlists[] = NULL; @@ -599,7 +617,7 @@ final class Audio extends VKAPIRequestHandler } return (object) [ - "count" => sizeof($playlists), + "count" => $search->size(), "items" => $playlists, ]; } diff --git a/Web/Models/Repositories/Audios.php b/Web/Models/Repositories/Audios.php index 22e7ac1e..1ec45dd2 100644 --- a/Web/Models/Repositories/Audios.php +++ b/Web/Models/Repositories/Audios.php @@ -300,11 +300,13 @@ class Audios function findPlaylists(string $query, array $params = [], array $order = ['type' => 'id', 'invert' => false]): \Traversable { $result = $this->playlists->where([ - "unlisted" => 0, "deleted" => 0, ])->where("CONCAT_WS(' ', name, description) LIKE ?", "%$query%"); $order_str = 'id'; + if(is_null($params['from_me']) || empty($params['from_me'])) + $result->where(["unlisted" => 0]); + switch($order['type']) { case 'id': $order_str = 'id ' . ($order['invert'] ? 'ASC' : 'DESC'); @@ -317,6 +319,17 @@ class Audios break; } + foreach($params as $paramName => $paramValue) { + if(is_null($paramValue) || $paramValue == '') continue; + + switch($paramName) { + # БУДЬ МАКСИМАЛЬНО АККУРАТЕН С ДАННЫМ ПАРАМЕТРОМ + case "from_me": + $result->where("owner", $paramValue); + break; + } + } + if($order_str) $result->order($order_str); diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php index 31406771..0c9a78f9 100644 --- a/Web/Models/Repositories/Posts.php +++ b/Web/Models/Repositories/Posts.php @@ -181,6 +181,7 @@ class Posts case 'ads': $result->where("ad", 1); break;*/ + # БУДЬ МАКСИМАЛЬНО АККУРАТЕН С ДАННЫМ ПАРАМЕТРОМ case 'from_me': $result->where("owner", $paramValue); break; diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php index e1584366..b47ba0f0 100644 --- a/Web/Presenters/AudioPresenter.php +++ b/Web/Presenters/AudioPresenter.php @@ -567,16 +567,65 @@ final class AudioPresenter extends OpenVKPresenter break; case "add_to_club": - $club = (new Clubs)->get((int)$this->postParam("club")); - - if(!$club || !$club->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", "error", tr("access_denied"), null, true); - - if(!$audio->isInLibraryOf($club)) - $audio->add($club); - else - $this->flashFail("err", "error", tr("group_has_audio"), null, true); - + $detailed = []; + if($audio->isWithdrawn()) + $this->flashFail("err", "error", tr("invalid_audio"), null, true); + + if(empty($this->postParam("clubs"))) + $this->flashFail("err", "error", 'clubs not passed', null, true); + + $clubs_arr = explode(',', $this->postParam("clubs")); + $count = sizeof($clubs_arr); + if($count < 1 || $count > 10) { + $this->flashFail("err", "error", tr('too_many_or_to_lack'), null, true); + } + + foreach($clubs_arr as $club_id) { + $club = (new Clubs)->get((int)$club_id); + if(!$club || !$club->canBeModifiedBy($this->user->identity)) + continue; + + if(!$audio->isInLibraryOf($club)) { + $detailed[$club_id] = true; + $audio->add($club); + } else { + $detailed[$club_id] = false; + continue; + } + } + + $this->returnJson(["success" => true, 'detailed' => $detailed]); + break; + case "add_to_playlist": + $detailed = []; + if($audio->isWithdrawn()) + $this->flashFail("err", "error", tr("invalid_audio"), null, true); + + if(empty($this->postParam("playlists"))) + $this->flashFail("err", "error", 'playlists not passed', null, true); + + $playlists_arr = explode(',', $this->postParam("playlists")); + $count = sizeof($playlists_arr); + if($count < 1 || $count > 10) { + $this->flashFail("err", "error", tr('too_many_or_to_lack'), null, true); + } + + foreach($playlists_arr as $playlist_id) { + $pid = explode('_', $playlist_id); + $playlist = (new Audios)->getPlaylistByOwnerAndVID((int)$pid[0], (int)$pid[1]); + if(!$playlist || !$playlist->canBeModifiedBy($this->user->identity)) + continue; + + if(!$playlist->hasAudio($audio)) { + $playlist->add($audio); + $detailed[$playlist_id] = true; + } else { + $detailed[$playlist_id] = false; + continue; + } + } + + $this->returnJson(["success" => true, 'detailed' => $detailed]); break; case "delete": if($audio->canBeModifiedBy($this->user->identity)) diff --git a/Web/Presenters/SearchPresenter.php b/Web/Presenters/SearchPresenter.php index bc4b8d8d..47f3ee16 100644 --- a/Web/Presenters/SearchPresenter.php +++ b/Web/Presenters/SearchPresenter.php @@ -83,6 +83,7 @@ final class SearchPresenter extends OpenVKPresenter $parameters['with_lyrics'] = true; break; + # дай бог работал этот case case 'from_me': if((int) $param_value != 1) continue; $parameters['from_me'] = $this->user->id; diff --git a/Web/Presenters/templates/Audio/Upload.xml b/Web/Presenters/templates/Audio/Upload.xml index da2cc0fc..96f402f7 100644 --- a/Web/Presenters/templates/Audio/Upload.xml +++ b/Web/Presenters/templates/Audio/Upload.xml @@ -110,8 +110,24 @@ document.querySelector("#firstStep").style.display = "none" document.querySelector("#lastStep").style.display = "block" + + function fallback() { + console.info('Tags not found, setting default values.') + + document.querySelector("#lastStep input[name=name]").value = files[0].name + document.querySelector("#lastStep select[name=genre]").value = "Other" + document.querySelector("#lastStep input[name=performer]").value = tr("track_unknown"); + } - const tags = await id3.fromFile(files[0]); + let tags = null + + try { + tags = await id3.fromFile(files[0]); + } catch(e) { + console.error(e) + } + + console.log(tags) if(tags != null) { console.log("ID" + tags.kind + " detected, setting values..."); @@ -126,11 +142,22 @@ document.querySelector("#lastStep input[name=performer]").value = tr("track_unknown"); if(tags.genre != null) { - if(document.querySelector("#lastStep select[name=genre] > option[value='" + tags.genre + "']") != null) { - document.querySelector("#lastStep select[name=genre]").value = tags.genre; + // if there are more than one genre + if(tags.genre.split(', ').length > 1) { + const genres = tags.genre.split(', ') + + genres.forEach(genre => { + if(document.querySelector("#lastStep select[name=genre] > option[value='" + genre + "']") != null) { + document.querySelector("#lastStep select[name=genre]").value = genre; + } + }) } else { - console.warn("Unknown genre: " + tags.genre); - document.querySelector("#lastStep select[name=genre]").value = "Other" + if(document.querySelector("#lastStep select[name=genre] > option[value='" + tags.genre + "']") != null) { + document.querySelector("#lastStep select[name=genre]").value = tags.genre; + } else { + console.warn("Unknown genre: " + tags.genre); + document.querySelector("#lastStep select[name=genre]").value = "Other" + } } } else { document.querySelector("#lastStep select[name=genre]").value = "Other" @@ -139,9 +166,7 @@ if(tags.comments != null) document.querySelector("#lastStep textarea[name=lyrics]").value = tags.comments } else { - document.querySelector("#lastStep input[name=name]").value = files[0].name - document.querySelector("#lastStep select[name=genre]").value = "Other" - document.querySelector("#lastStep input[name=performer]").value = tr("track_unknown"); + fallback() } }); diff --git a/Web/Presenters/templates/Audio/player.xml b/Web/Presenters/templates/Audio/player.xml index f235dc93..de8f03d7 100644 --- a/Web/Presenters/templates/Audio/player.xml +++ b/Web/Presenters/templates/Audio/player.xml @@ -1,7 +1,8 @@ {php $id = $audio->getId() . rand(0, 1000)} {php $isWithdrawn = $audio->isWithdrawn()} +{php $isAvailable = $audio->isAvailable()} {php $editable = isset($thisUser) && $audio->canBeModifiedBy($thisUser)} -
+