mirror of
https://github.com/koel/koel
synced 2024-11-24 21:23:06 +00:00
Move User dependency out of Song scrobble method
This commit is contained in:
parent
328dc88c99
commit
47c36f289e
2 changed files with 10 additions and 7 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Requests\API\Request;
|
||||
use App\Models\Song;
|
||||
|
||||
class ScrobbleController extends Controller
|
||||
|
@ -9,13 +10,14 @@ class ScrobbleController extends Controller
|
|||
/**
|
||||
* Create a Last.fm scrobble entry for a song.
|
||||
*
|
||||
* @param Song $song
|
||||
* @param string $timestamp The UNIX timestamp when the song started playing.
|
||||
* @param Request $request
|
||||
* @param Song $song
|
||||
* @param string $timestamp The UNIX timestamp when the song started playing.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(Song $song, $timestamp)
|
||||
public function store(Request $request, Song $song, $timestamp)
|
||||
{
|
||||
return response()->json($song->scrobble($timestamp));
|
||||
return response()->json($song->scrobble($request->user(), $timestamp));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,11 +74,12 @@ class Song extends Model
|
|||
/**
|
||||
* Scrobble the song using Last.fm service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $timestamp The UNIX timestamp in which the song started playing.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function scrobble($timestamp)
|
||||
public function scrobble(User $user, $timestamp)
|
||||
{
|
||||
// Don't scrobble the unknown guys. No one knows them.
|
||||
if ($this->artist->isUnknown()) {
|
||||
|
@ -86,7 +87,7 @@ class Song extends Model
|
|||
}
|
||||
|
||||
// If the current user hasn't connected to Last.fm, don't do shit.
|
||||
if (!$sessionKey = auth()->user()->lastfm_session_key) {
|
||||
if (!$user->lastfm_session_key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,7 +96,7 @@ class Song extends Model
|
|||
$this->title,
|
||||
$timestamp,
|
||||
$this->album->name === Album::UNKNOWN_NAME ? '' : $this->album->name,
|
||||
$sessionKey
|
||||
$user->lastfm_session_key
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue