1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers\API; |
||
4 | |||
5 | use App\Application; |
||
6 | use App\Repositories\InteractionRepository; |
||
7 | use App\Repositories\PlaylistRepository; |
||
8 | use App\Repositories\SettingRepository; |
||
9 | use App\Repositories\UserRepository; |
||
10 | use App\Services\ApplicationInformationService; |
||
11 | use App\Services\iTunesService; |
||
12 | use App\Services\LastfmService; |
||
13 | use App\Services\MediaCacheService; |
||
14 | use App\Services\YouTubeService; |
||
15 | use Illuminate\Http\JsonResponse; |
||
16 | use Illuminate\Http\Request; |
||
17 | |||
18 | /** |
||
19 | * @group 2. Application data |
||
20 | */ |
||
21 | class DataController extends Controller |
||
22 | { |
||
23 | private const RECENTLY_PLAYED_EXCERPT_COUNT = 7; |
||
24 | |||
25 | private $lastfmService; |
||
26 | private $youTubeService; |
||
27 | private $iTunesService; |
||
28 | private $mediaCacheService; |
||
29 | private $settingRepository; |
||
30 | private $playlistRepository; |
||
31 | private $interactionRepository; |
||
32 | private $userRepository; |
||
33 | private $applicationInformationService; |
||
34 | |||
35 | public function __construct( |
||
36 | LastfmService $lastfmService, |
||
37 | YouTubeService $youTubeService, |
||
38 | iTunesService $iTunesService, |
||
39 | MediaCacheService $mediaCacheService, |
||
40 | SettingRepository $settingRepository, |
||
41 | PlaylistRepository $playlistRepository, |
||
42 | InteractionRepository $interactionRepository, |
||
43 | UserRepository $userRepository, |
||
44 | ApplicationInformationService $applicationInformationService |
||
45 | ) { |
||
46 | $this->lastfmService = $lastfmService; |
||
47 | $this->youTubeService = $youTubeService; |
||
48 | $this->iTunesService = $iTunesService; |
||
49 | $this->mediaCacheService = $mediaCacheService; |
||
50 | $this->settingRepository = $settingRepository; |
||
51 | $this->playlistRepository = $playlistRepository; |
||
52 | $this->interactionRepository = $interactionRepository; |
||
53 | $this->userRepository = $userRepository; |
||
54 | $this->applicationInformationService = $applicationInformationService; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get application data. |
||
59 | * |
||
60 | * The big fat call to retrieve a set of application data catered for the current user |
||
61 | * (songs, albums, artists, playlists, interactions, and if the user is an admin, settings as well). |
||
62 | * Naturally, this call should be made right after the user has been logged in, when you need to populate |
||
63 | * the application's interface with useful information. |
||
64 | * |
||
65 | * @responseFile responses/data.index.json |
||
66 | * |
||
67 | * @return JsonResponse |
||
68 | */ |
||
69 | public function index(Request $request) |
||
70 | { |
||
71 | return response()->json($this->mediaCacheService->get() + [ |
||
72 | 'settings' => $request->user()->is_admin ? $this->settingRepository->getAllAsKeyValueArray() : [], |
||
73 | 'playlists' => $this->playlistRepository->getAllByCurrentUser(), |
||
74 | 'interactions' => $this->interactionRepository->getAllByCurrentUser(), |
||
75 | 'recentlyPlayed' => $this->interactionRepository->getRecentlyPlayed( |
||
76 | $request->user(), |
||
77 | self::RECENTLY_PLAYED_EXCERPT_COUNT |
||
78 | ), |
||
79 | 'users' => $request->user()->is_admin ? $this->userRepository->getAll() : [], |
||
80 | 'currentUser' => $request->user(), |
||
81 | 'useLastfm' => $this->lastfmService->used(), |
||
82 | 'useYouTube' => $this->youTubeService->enabled(), |
||
83 | 'useiTunes' => $this->iTunesService->used(), |
||
84 | 'allowDownload' => config('koel.download.allow'), |
||
85 | 'supportsTranscoding' => config('koel.streaming.ffmpeg_path') |
||
86 | && is_executable(config('koel.streaming.ffmpeg_path')), |
||
87 | 'cdnUrl' => app()->staticUrl(), |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
88 | 'currentVersion' => Application::KOEL_VERSION, |
||
89 | 'latestVersion' => $request->user()->is_admin |
||
90 | ? $this->applicationInformationService->getLatestVersionNumber() |
||
91 | : Application::KOEL_VERSION, |
||
92 | ]); |
||
93 | } |
||
94 | } |
||
95 |