2024-01-03 17:02:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Download;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests\Download\DownloadSongsRequest;
|
2024-01-10 23:11:45 +00:00
|
|
|
use App\Models\Song;
|
2024-01-03 17:02:18 +00:00
|
|
|
use App\Repositories\SongRepository;
|
|
|
|
use App\Services\DownloadService;
|
|
|
|
|
|
|
|
class DownloadSongsController extends Controller
|
|
|
|
{
|
2024-01-10 23:11:45 +00:00
|
|
|
public function __invoke(DownloadSongsRequest $request, DownloadService $service, SongRepository $repository)
|
2024-01-03 17:02:18 +00:00
|
|
|
{
|
2024-01-10 23:11:45 +00:00
|
|
|
// Don't use SongRepository::findMany() because it'd have been already catered to the current user.
|
|
|
|
$songs = Song::query()->findMany($request->songs);
|
2024-01-07 12:43:10 +00:00
|
|
|
$songs->each(fn ($song) => $this->authorize('download', $song));
|
|
|
|
|
2024-01-10 23:11:45 +00:00
|
|
|
return response()->download($service->getDownloadablePath($repository->getMany($request->songs)));
|
2024-01-03 17:02:18 +00:00
|
|
|
}
|
|
|
|
}
|