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

60 lines
2.4 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;
2020-09-13 22:04:07 +00:00
use App\Models\User;
2018-08-29 06:15:11 +00:00
use App\Repositories\InteractionRepository;
use App\Repositories\PlaylistRepository;
use App\Repositories\SettingRepository;
use App\Repositories\UserRepository;
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;
2018-08-19 14:56:56 +00:00
use App\Services\MediaCacheService;
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 DataController extends Controller
{
private const RECENTLY_PLAYED_EXCERPT_COUNT = 7;
2022-07-29 06:47:10 +00:00
/** @param User $currentUser */
2018-08-19 14:40:25 +00:00
public function __construct(
2022-07-29 06:47:10 +00:00
private MediaCacheService $mediaCacheService,
private SettingRepository $settingRepository,
private PlaylistRepository $playlistRepository,
private InteractionRepository $interactionRepository,
private UserRepository $userRepository,
private ApplicationInformationService $applicationInformationService,
private ?Authenticatable $currentUser
2018-08-19 15:26:52 +00:00
) {
2018-08-19 14:40:25 +00:00
}
2020-09-13 22:04:07 +00:00
public function index()
2015-12-13 04:42:28 +00:00
{
2018-08-19 14:56:56 +00:00
return response()->json($this->mediaCacheService->get() + [
2020-09-13 22:04:07 +00:00
'settings' => $this->currentUser->is_admin ? $this->settingRepository->getAllAsKeyValueArray() : [],
2018-08-29 06:15:11 +00:00
'playlists' => $this->playlistRepository->getAllByCurrentUser(),
'interactions' => $this->interactionRepository->getAllByCurrentUser(),
'recentlyPlayed' => $this->interactionRepository->getRecentlyPlayed(
2020-09-13 22:04:07 +00:00
$this->currentUser,
self::RECENTLY_PLAYED_EXCERPT_COUNT
),
2020-09-13 22:04:07 +00:00
'users' => $this->currentUser->is_admin ? $this->userRepository->getAll() : [],
'currentUser' => $this->currentUser,
2022-08-08 16:00:59 +00:00
'useLastfm' => LastfmService::used(),
'useYouTube' => YouTubeService::enabled(),
'useiTunes' => ITunesService::used(),
2020-09-06 21:20:42 +00:00
'allowDownload' => config('koel.download.allow'),
'supportsTranscoding' => config('koel.streaming.ffmpeg_path')
&& is_executable(config('koel.streaming.ffmpeg_path')),
2020-12-22 23:01:49 +00:00
'cdnUrl' => static_url(),
'currentVersion' => koel_version(),
2020-09-13 22:04:07 +00:00
'latestVersion' => $this->currentUser->is_admin
? $this->applicationInformationService->getLatestVersionNumber()
: koel_version(),
2015-12-13 04:42:28 +00:00
]);
}
}