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

70 lines
3 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2022-07-29 06:47:10 +00:00
use App\Http\Controllers\Controller;
2023-06-05 21:46:41 +00:00
use App\Http\Resources\PlaylistFolderResource;
use App\Http\Resources\PlaylistResource;
use App\Http\Resources\QueueStateResource;
2023-06-05 21:46:41 +00:00
use App\Http\Resources\UserResource;
2020-09-13 22:04:07 +00:00
use App\Models\User;
2024-01-18 11:13:05 +00:00
use App\Repositories\PlaylistRepository;
2018-08-29 06:15:11 +00:00
use App\Repositories\SettingRepository;
2023-06-05 21:46:41 +00:00
use App\Repositories\SongRepository;
use App\Services\ApplicationInformationService;
2020-12-22 20:11:22 +00:00
use App\Services\ITunesService;
2018-08-19 14:40:25 +00:00
use App\Services\LastfmService;
use App\Services\License\Contracts\LicenseServiceInterface;
use App\Services\QueueService;
use App\Services\SpotifyService;
2018-08-19 14:40:25 +00:00
use App\Services\YouTubeService;
2020-09-13 22:04:07 +00:00
use Illuminate\Contracts\Auth\Authenticatable;
2015-12-13 04:42:28 +00:00
class FetchInitialDataController extends Controller
2015-12-13 04:42:28 +00:00
{
2023-06-05 21:46:41 +00:00
/** @param User $user */
public function __invoke(
ITunesService $iTunesService,
SettingRepository $settingRepository,
SongRepository $songRepository,
2024-01-18 11:13:05 +00:00
PlaylistRepository $playlistRepository,
ApplicationInformationService $applicationInformationService,
QueueService $queueService,
2024-01-09 18:34:40 +00:00
LicenseServiceInterface $licenseService,
?Authenticatable $user
2018-08-19 15:26:52 +00:00
) {
2024-01-08 16:59:05 +00:00
$licenseStatus = $licenseService->getStatus();
2023-06-05 21:46:41 +00:00
return response()->json([
'settings' => $user->is_admin ? $settingRepository->getAllAsKeyValueArray() : [],
2024-01-18 11:13:05 +00:00
'playlists' => PlaylistResource::collection($playlistRepository->getAllAccessibleByUser($user)),
'playlist_folders' => PlaylistFolderResource::collection($user->playlist_folders),
'current_user' => UserResource::make($user, true),
2024-01-04 11:35:36 +00:00
'uses_last_fm' => LastfmService::used(),
'uses_spotify' => SpotifyService::enabled(),
'uses_you_tube' => YouTubeService::enabled(),
'uses_i_tunes' => $iTunesService->used(),
'allows_download' => config('koel.download.allow'),
'media_path_set' => (bool) $settingRepository->getByKey('media_path'),
2023-06-05 21:46:41 +00:00
'supports_transcoding' => config('koel.streaming.ffmpeg_path')
&& is_executable(config('koel.streaming.ffmpeg_path')),
2023-06-05 21:46:41 +00:00
'cdn_url' => static_url(),
'current_version' => koel_version(),
'latest_version' => $user->is_admin
? $applicationInformationService->getLatestVersionNumber()
: koel_version(),
2024-05-19 05:49:42 +00:00
'song_count' => $songRepository->countSongs(),
'song_length' => $songRepository->getTotalSongLength(),
'queue_state' => QueueStateResource::make($queueService->getQueueState($user)),
2024-01-08 16:59:05 +00:00
'koel_plus' => [
'active' => $licenseStatus->isValid(),
'short_key' => $licenseStatus->license?->short_key,
'customer_name' => $licenseStatus->license?->meta->customerName,
'customer_email' => $licenseStatus->license?->meta->customerEmail,
'product_id' => config('lemonsqueezy.product_id'),
2024-01-08 16:59:05 +00:00
],
2024-04-24 20:44:47 +00:00
'storage_driver' => config('koel.storage_driver'),
2015-12-13 04:42:28 +00:00
]);
}
}