mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
Refactor and clean up
This commit is contained in:
parent
570197d94b
commit
40deeb9f8b
10 changed files with 26 additions and 24 deletions
|
@ -18,7 +18,8 @@ class InteractionController extends Controller
|
|||
*/
|
||||
public function play(Request $request)
|
||||
{
|
||||
if ($interaction = Interaction::increasePlayCount($request->input('song'), $request->user())) {
|
||||
$interaction = Interaction::increasePlayCount($request->song, $request->user());
|
||||
if ($interaction) {
|
||||
event(new SongStartedPlaying($interaction->song, $interaction->user));
|
||||
}
|
||||
|
||||
|
@ -34,7 +35,7 @@ class InteractionController extends Controller
|
|||
*/
|
||||
public function like(Request $request)
|
||||
{
|
||||
return response()->json(Interaction::toggleLike($request->input('song'), $request->user()));
|
||||
return response()->json(Interaction::toggleLike($request->song, $request->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +47,7 @@ class InteractionController extends Controller
|
|||
*/
|
||||
public function batchLike(BatchInteractionRequest $request)
|
||||
{
|
||||
return response()->json(Interaction::batchLike((array) $request->input('songs'), $request->user()));
|
||||
return response()->json(Interaction::batchLike((array) $request->songs, $request->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,6 +59,6 @@ class InteractionController extends Controller
|
|||
*/
|
||||
public function batchUnlike(BatchInteractionRequest $request)
|
||||
{
|
||||
return response()->json(Interaction::batchUnlike((array) $request->input('songs'), $request->user()));
|
||||
return response()->json(Interaction::batchUnlike((array) $request->songs, $request->user()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class LastfmController extends Controller
|
|||
*/
|
||||
public function callback(Request $request, Lastfm $lastfm)
|
||||
{
|
||||
abort_unless($token = $request->input('token'), 500, 'Something wrong happened.');
|
||||
abort_unless($token = $request->token, 500, 'Something wrong happened.');
|
||||
|
||||
// Get the session key using the obtained token.
|
||||
abort_unless($sessionKey = $lastfm->getSessionKey($token), 500, 'Invalid token key.');
|
||||
|
@ -83,7 +83,7 @@ class LastfmController extends Controller
|
|||
*/
|
||||
public function setSessionKey(Request $request)
|
||||
{
|
||||
$this->auth->user()->savePreference('lastfm_session_key', trim($request->input('key')));
|
||||
$this->auth->user()->savePreference('lastfm_session_key', trim($request->key));
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class PlaylistController extends Controller
|
|||
public function store(PlaylistStoreRequest $request)
|
||||
{
|
||||
$playlist = auth()->user()->playlists()->create($request->only('name'));
|
||||
$playlist->songs()->sync($request->input('songs', []));
|
||||
$playlist->songs()->sync((array) $request->songs);
|
||||
|
||||
$playlist->songs = $playlist->songs->pluck('id');
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ class ProfileController extends Controller
|
|||
{
|
||||
$data = $request->only('name', 'email');
|
||||
|
||||
if ($password = $request->input('password')) {
|
||||
$data['password'] = Hash::make($password);
|
||||
if ($request->password) {
|
||||
$data['password'] = Hash::make($request->password);
|
||||
}
|
||||
|
||||
return response()->json(auth()->user()->update($data));
|
||||
|
|
|
@ -18,7 +18,7 @@ class SettingController extends Controller
|
|||
public function store(SettingRequest $request)
|
||||
{
|
||||
// For right now there's only one setting to be saved
|
||||
Setting::set('media_path', rtrim(trim($request->input('media_path')), '/'));
|
||||
Setting::set('media_path', rtrim(trim($request->media_path), '/'));
|
||||
|
||||
// In a next version we should opt for a "MediaPathChanged" event,
|
||||
// but let's just do this async now.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Requests\API\Request;
|
||||
use App\Http\Requests\API\SongUpdateRequest;
|
||||
use App\Models\Song;
|
||||
use App\Services\Streamers\PHPStreamer;
|
||||
|
@ -18,6 +19,7 @@ class SongController extends Controller
|
|||
*
|
||||
* @link https://github.com/phanan/koel/wiki#streaming-music
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Song $song The song to stream.
|
||||
* @param null|bool $transcode Whether to force transcoding the song.
|
||||
* If this is omitted, by default Koel will transcode FLAC.
|
||||
|
@ -26,7 +28,7 @@ class SongController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function play(Song $song, $transcode = null, $bitRate = null)
|
||||
public function play(Request $request, Song $song, $transcode = null, $bitRate = null)
|
||||
{
|
||||
if ($song->s3_params) {
|
||||
return (new S3Streamer($song))->stream();
|
||||
|
@ -43,7 +45,7 @@ class SongController extends Controller
|
|||
$streamer = new TranscodingStreamer(
|
||||
$song,
|
||||
$bitRate ?: config('koel.streaming.bitrate'),
|
||||
request()->input('time', 0)
|
||||
floatval($request->time)
|
||||
);
|
||||
} else {
|
||||
switch (config('koel.streaming.method')) {
|
||||
|
|
|
@ -19,10 +19,8 @@ class iTunesController extends Controller
|
|||
public function viewSong(ViewSongRequest $request, Album $album)
|
||||
{
|
||||
$url = iTunes::getTrackUrl($request->q, $album->name, $album->artist->name);
|
||||
if ($url) {
|
||||
return redirect($url);
|
||||
} else {
|
||||
abort(404, "Koel can't find such a song on iTunes Store.");
|
||||
}
|
||||
abort_unless($url, 404, "Koel can't find such a song on iTunes Store.");
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class Song extends Model
|
|||
}
|
||||
|
||||
// If the current user hasn't connected to Last.fm, don't do shit.
|
||||
if (!$user->lastfm_session_key) {
|
||||
if (!$user->connectedToLastfm()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,15 +24,15 @@ class Download
|
|||
*/
|
||||
public function from($mixed)
|
||||
{
|
||||
if (is_a($mixed, Song::class)) {
|
||||
if ($mixed instanceof Song) {
|
||||
return $this->fromSong($mixed);
|
||||
} elseif (is_a($mixed, Collection::class)) {
|
||||
} elseif (mixed instanceof Collection) {
|
||||
return $this->fromMultipleSongs($mixed);
|
||||
} elseif (is_a($mixed, Album::class)) {
|
||||
} elseif ($mixed instanceof Album) {
|
||||
return $this->fromAlbum($mixed);
|
||||
} elseif (is_a($mixed, Artist::class)) {
|
||||
} elseif ($mixed instanceof Artist) {
|
||||
return $this->fromArtist($mixed);
|
||||
} elseif (is_a($mixed, Playlist::class)) {
|
||||
} elseif ($mixed instanceof Playlist) {
|
||||
return $this->fromPlaylist($mixed);
|
||||
} else {
|
||||
throw new Exception('Unsupport download type.');
|
||||
|
|
|
@ -156,7 +156,8 @@ class LastfmTest extends BrowserKitTestCase
|
|||
|
||||
public function testControllerCallback()
|
||||
{
|
||||
$request = m::mock(Request::class, ['input' => 'token']);
|
||||
$request = m::mock(Request::class);
|
||||
$request->token = 'foo';
|
||||
$lastfm = m::mock(Lastfm::class, ['getSessionKey' => 'bar']);
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
|
|
Loading…
Reference in a new issue