2024-01-03 17:02:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\API\ViewSongOnITunesRequest;
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Services\ITunesService;
|
|
|
|
use App\Services\TokenManager;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
|
|
class ViewSongOnITunesController extends Controller
|
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
ViewSongOnITunesRequest $request,
|
|
|
|
ITunesService $iTunesService,
|
|
|
|
TokenManager $tokenManager,
|
|
|
|
Album $album
|
|
|
|
) {
|
|
|
|
abort_unless(
|
|
|
|
(bool) $tokenManager->getUserFromPlainTextToken($request->api_token),
|
|
|
|
Response::HTTP_UNAUTHORIZED
|
|
|
|
);
|
|
|
|
|
2024-03-22 15:22:29 +00:00
|
|
|
$url = $iTunesService->getTrackUrl($request->q, $album);
|
2024-01-03 17:02:18 +00:00
|
|
|
abort_unless((bool) $url, Response::HTTP_NOT_FOUND, "Koel can't find such a song on iTunes Store.");
|
|
|
|
|
|
|
|
return redirect($url);
|
|
|
|
}
|
|
|
|
}
|