koel/app/Http/Controllers/Download/DownloadPlaylistController.php

34 lines
924 B
PHP
Raw Normal View History

2024-01-03 17:02:18 +00:00
<?php
namespace App\Http\Controllers\Download;
use App\Http\Controllers\Controller;
use App\Models\Playlist;
2024-01-07 12:43:10 +00:00
use App\Models\User;
use App\Repositories\SongRepository;
2024-01-03 17:02:18 +00:00
use App\Services\DownloadService;
2024-01-07 12:43:10 +00:00
use App\Services\SmartPlaylistService;
use Illuminate\Contracts\Auth\Authenticatable;
2024-01-03 17:02:18 +00:00
class DownloadPlaylistController extends Controller
{
2024-01-07 12:43:10 +00:00
/** @param User $user */
public function __invoke(
Playlist $playlist,
SongRepository $repository,
SmartPlaylistService $smartPlaylistService,
DownloadService $download,
Authenticatable $user
) {
$this->authorize('download', $playlist);
2024-01-03 17:02:18 +00:00
2024-01-07 12:43:10 +00:00
return response()->download(
$download->from(
$playlist->is_smart
? $smartPlaylistService->getSongs($playlist, $user)
: $repository->getByStandardPlaylist($playlist, $user)
)
);
2024-01-03 17:02:18 +00:00
}
}