the browser-facing portion of osu!
at master 1.6 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers; 7 8use App\Libraries\Search\ArtistTrackSearch; 9use App\Libraries\Search\ArtistTrackSearchParamsFromRequest; 10use App\Models\ArtistTrack; 11use App\Transformers\ArtistTrackTransformer; 12 13class ArtistTracksController extends Controller 14{ 15 public function index() 16 { 17 $params = ArtistTrackSearchParamsFromRequest::fromArray(request()->all()); 18 $search = new ArtistTrackSearch($params); 19 20 $tracks = $search->records(); 21 $index = [ 22 'artist_tracks' => json_collection($tracks, new ArtistTrackTransformer(), ['artist', 'album']), 23 'search' => ArtistTrackSearchParamsFromRequest::toArray($params), 24 ...cursor_for_response($search->getSortCursor()), 25 ]; 26 27 if (is_json_request()) { 28 return $index; 29 } 30 31 $availableGenres = cache_remember_mutexed( 32 'artist_track_genres', 33 600, 34 [], 35 fn () => ArtistTrack::distinct()->pluck('genre')->sort()->values(), 36 ); 37 38 return ext_view('artist_tracks.index', compact('availableGenres', 'index')); 39 } 40 41 public function show($id) 42 { 43 $track = ArtistTrack::findOrFail($id); 44 $artist = $track->artist; 45 46 if ($artist === null) { 47 abort(404); 48 } 49 50 return ujs_redirect(route('artists.show', $artist)); 51 } 52}