koel/app/Http/Controllers/API/ScrobbleController.php

30 lines
740 B
PHP
Raw Normal View History

2016-05-30 13:50:59 +08:00
<?php
namespace App\Http\Controllers\API;
2020-09-14 00:04:07 +02:00
use App\Http\Requests\API\ScrobbleStoreRequest;
use App\Jobs\ScrobbleJob;
2016-05-30 13:50:59 +08:00
use App\Models\Song;
2020-09-14 00:04:07 +02:00
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;
2016-05-30 13:50:59 +08:00
class ScrobbleController extends Controller
{
2020-09-14 00:04:07 +02:00
/** @var User */
2021-06-05 12:47:56 +02:00
private ?Authenticatable $currentUser;
2020-09-14 00:04:07 +02:00
2021-06-05 12:47:56 +02:00
public function __construct(?Authenticatable $currentUser)
2018-08-19 23:17:05 +02:00
{
2020-09-14 00:04:07 +02:00
$this->currentUser = $currentUser;
2018-08-19 23:17:05 +02:00
}
2020-09-14 00:04:07 +02:00
public function store(ScrobbleStoreRequest $request, Song $song)
2016-05-30 13:50:59 +08:00
{
2020-09-14 00:04:07 +02:00
if (!$song->artist->is_unknown && $this->currentUser->connectedToLastfm()) {
ScrobbleJob::dispatch($this->currentUser, $song, $request->timestamp);
2018-08-19 23:17:05 +02:00
}
return response()->noContent();
2016-05-30 13:50:59 +08:00
}
}