repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/iTunes/ITunesConnector.php
app/Http/Integrations/iTunes/ITunesConnector.php
<?php namespace App\Http\Integrations\iTunes; use Saloon\Http\Connector; use Saloon\Traits\Plugins\AcceptsJson; use Saloon\Traits\Plugins\AlwaysThrowOnErrors; class ITunesConnector extends Connector { use AcceptsJson; use AlwaysThrowOnErrors; public function resolveBaseUrl(): string { return config('koel.services.itunes.endpoint'); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/iTunes/Requests/GetTrackRequest.php
app/Http/Integrations/iTunes/Requests/GetTrackRequest.php
<?php namespace App\Http\Integrations\iTunes\Requests; use App\Models\Album; use App\Models\Artist; use Saloon\Enums\Method; use Saloon\Http\Request; class GetTrackRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $trackName, private readonly Album $album) { } /** @inheritdoc */ protected function defaultQuery(): array { $term = $this->trackName; if ($this->album->name !== Album::UNKNOWN_NAME) { $term .= ' ' . $this->album->name; } if ( $this->album->artist->name !== Artist::UNKNOWN_NAME && $this->album->artist->name !== Artist::VARIOUS_NAME ) { $term .= ' ' . $this->album->artist->name; } return [ 'term' => $term, 'media' => 'music', 'entity' => 'song', 'limit' => 1, ]; } public function resolveEndpoint(): string { return '/'; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Wikidata/WikidataConnector.php
app/Http/Integrations/Wikidata/WikidataConnector.php
<?php namespace App\Http\Integrations\Wikidata; use Saloon\Http\Connector; class WikidataConnector extends Connector { public function resolveBaseUrl(): string { return 'https://www.wikidata.org/wiki/'; } /** @inheritdoc */ protected function defaultHeaders(): array { return [ 'Accept' => 'application/json', 'User-Agent' => sprintf('%s/%s( %s )', config('app.name'), koel_version(), config('app.url')), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Wikidata/Requests/GetEntityDataRequest.php
app/Http/Integrations/Wikidata/Requests/GetEntityDataRequest.php
<?php namespace App\Http\Integrations\Wikidata\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class GetEntityDataRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $entityId) { } public function resolveEndpoint(): string { return "Special:EntityData/{$this->entityId}"; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Spotify/SpotifyClient.php
app/Http/Integrations/Spotify/SpotifyClient.php
<?php namespace App\Http\Integrations\Spotify; use App\Exceptions\SpotifyIntegrationDisabledException; use App\Services\SpotifyService; use Illuminate\Cache\Repository as Cache; use SpotifyWebAPI\Session; use SpotifyWebAPI\SpotifyWebAPI; /** * @method array search(string $keywords, string|array $type, array|object $options = []) */ class SpotifyClient { public const ACCESS_TOKEN_CACHE_KEY = 'spotify.access_token'; public function __construct( public SpotifyWebAPI $wrapped, private readonly ?Session $session, private readonly Cache $cache ) { if (SpotifyService::enabled()) { $this->wrapped->setOptions(['return_assoc' => true]); rescue(fn () => $this->setAccessToken()); } } private function setAccessToken(): void { $token = $this->cache->get(self::ACCESS_TOKEN_CACHE_KEY); if (!$token) { $this->session->requestCredentialsToken(); $token = $this->session->getAccessToken(); // Spotify's tokens expire after 1 hour, so we'll cache them with some buffer to an extra call. $this->cache->put(self::ACCESS_TOKEN_CACHE_KEY, $token, 59 * 60); } $this->wrapped->setAccessToken($token); } public function __call(string $name, array $arguments): mixed { throw_unless(SpotifyService::enabled(), SpotifyIntegrationDisabledException::create()); return $this->wrapped->$name(...$arguments); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/LastfmConnector.php
app/Http/Integrations/Lastfm/LastfmConnector.php
<?php namespace App\Http\Integrations\Lastfm; use App\Http\Integrations\Lastfm\Auth\LastfmAuthenticator; use Saloon\Http\Connector; use Saloon\Traits\Plugins\AcceptsJson; class LastfmConnector extends Connector { use AcceptsJson; public function resolveBaseUrl(): string { return config('koel.services.lastfm.endpoint'); } protected function defaultAuth(): LastfmAuthenticator { return new LastfmAuthenticator(config('koel.services.lastfm.key'), config('koel.services.lastfm.secret')); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php
app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Concerns\FormatsLastFmText; use App\Models\Album; use App\Values\Album\AlbumInformation; use Illuminate\Support\Arr; use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; final class GetAlbumInfoRequest extends Request { use FormatsLastFmText; protected Method $method = Method::GET; public function __construct(private readonly Album $album) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'method' => 'album.getInfo', 'artist' => $this->album->artist->name, 'album' => $this->album->name, 'autocorrect' => 1, 'format' => 'json', ]; } public function createDtoFromResponse(Response $response): ?AlbumInformation { $album = object_get($response->object(), 'album'); if (!$album) { return null; } return AlbumInformation::make( url: object_get($album, 'url'), cover: Arr::get(object_get($album, 'image', []), '0.#text'), wiki: [ 'summary' => self::formatLastFmText(object_get($album, 'wiki.summary')), 'full' => self::formatLastFmText(object_get($album, 'wiki.content')), ], tracks: array_map(static fn ($track): array => [ 'title' => $track->name, 'length' => (int) $track->duration, 'url' => $track->url, ], object_get($album, 'tracks.track', [])) ); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php
app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Contracts\RequiresSignature; use App\Models\Album; use App\Models\Song; use App\Models\User; use Saloon\Contracts\Body\HasBody; use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Traits\Body\HasFormBody; final class UpdateNowPlayingRequest extends Request implements HasBody, RequiresSignature { use HasFormBody; protected Method $method = Method::POST; public function __construct(private readonly Song $song, private readonly User $user) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultBody(): array { $parameters = [ 'method' => 'track.updateNowPlaying', 'artist' => $this->song->artist->name, 'track' => $this->song->title, 'duration' => $this->song->length, 'sk' => $this->user->preferences->lastFmSessionKey, ]; if ($this->song->album->name !== Album::UNKNOWN_NAME) { $parameters['album'] = $this->song->album->name; } return $parameters; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php
app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Contracts\RequiresSignature; use App\Models\Song; use App\Models\User; use Saloon\Contracts\Body\HasBody; use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Traits\Body\HasFormBody; final class ToggleLoveTrackRequest extends Request implements HasBody, RequiresSignature { use HasFormBody; protected Method $method = Method::POST; public function __construct(private readonly Song $song, private readonly User $user, private readonly bool $love) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultBody(): array { return [ 'method' => $this->love ? 'track.love' : 'track.unlove', 'sk' => $this->user->preferences->lastFmSessionKey, 'artist' => $this->song->artist_name, 'track' => $this->song->title, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php
app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Concerns\FormatsLastFmText; use App\Models\Artist; use App\Values\Artist\ArtistInformation; use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; final class GetArtistInfoRequest extends Request { use FormatsLastFmText; protected Method $method = Method::GET; public function __construct(private readonly Artist $artist) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'method' => 'artist.getInfo', 'artist' => $this->artist->name, 'autocorrect' => 1, 'format' => 'json', ]; } public function createDtoFromResponse(Response $response): ?ArtistInformation { $artist = object_get($response->object(), 'artist'); if (!$artist) { return null; } return ArtistInformation::make( url: object_get($artist, 'url'), bio: [ 'summary' => self::formatLastFmText(object_get($artist, 'bio.summary')), 'full' => self::formatLastFmText(object_get($artist, 'bio.content')), ], ); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php
app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Contracts\RequiresSignature; use Saloon\Enums\Method; use Saloon\Http\Request; final class GetSessionKeyRequest extends Request implements RequiresSignature { protected Method $method = Method::GET; public function __construct(private readonly string $token) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'method' => 'auth.getSession', 'token' => $this->token, 'format' => 'json', ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php
app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php
<?php namespace App\Http\Integrations\Lastfm\Requests; use App\Http\Integrations\Lastfm\Contracts\RequiresSignature; use App\Models\Album; use App\Models\Song; use App\Models\User; use Saloon\Contracts\Body\HasBody; use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Traits\Body\HasFormBody; final class ScrobbleRequest extends Request implements HasBody, RequiresSignature { use HasFormBody; protected Method $method = Method::POST; public function __construct( private readonly Song $song, private readonly User $user, private readonly int $timestamp ) { } public function resolveEndpoint(): string { return '/'; } /** @inheritdoc */ protected function defaultBody(): array { $body = [ 'method' => 'track.scrobble', 'artist' => $this->song->artist->name, 'track' => $this->song->title, 'timestamp' => $this->timestamp, 'sk' => $this->user->preferences->lastFmSessionKey, ]; if ($this->song->album->name !== Album::UNKNOWN_NAME) { $body['album'] = $this->song->album->name; } return $body; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php
app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php
<?php namespace App\Http\Integrations\Lastfm\Auth; use App\Http\Integrations\Lastfm\Contracts\RequiresSignature; use Saloon\Contracts\Authenticator; use Saloon\Http\PendingRequest; use Saloon\Repositories\Body\FormBodyRepository; final class LastfmAuthenticator implements Authenticator { public function __construct(private readonly string $key, private readonly string $secret) { } public function set(PendingRequest $pendingRequest): void { $this->addApiKey($pendingRequest); if ($pendingRequest->getRequest() instanceof RequiresSignature) { $this->sign($pendingRequest); } } private function addApiKey(PendingRequest $request): void { if ($request->body() instanceof FormBodyRepository) { $request->body()->add('api_key', $this->key); } else { $request->query()->add('api_key', $this->key); } } protected function sign(PendingRequest $request): void { if ($request->body() instanceof FormBodyRepository) { $request->body()->add('api_sig', $this->createSignature($request->body()->all())); } else { $request->query()->add('api_sig', $this->createSignature($request->query()->all())); } } private function createSignature(array $parameters): string { ksort($parameters); // Generate the API signature. // @link http://www.last.fm/api/webauth#6 $str = ''; foreach ($parameters as $name => $value) { if ($name === 'format') { // The format parameter is not part of the signature. continue; } $str .= $name . $value; } $str .= $this->secret; return md5($str); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Contracts/RequiresSignature.php
app/Http/Integrations/Lastfm/Contracts/RequiresSignature.php
<?php namespace App\Http\Integrations\Lastfm\Contracts; interface RequiresSignature { }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Lastfm/Concerns/FormatsLastFmText.php
app/Http/Integrations/Lastfm/Concerns/FormatsLastFmText.php
<?php namespace App\Http\Integrations\Lastfm\Concerns; trait FormatsLastFmText { /** * Correctly format a value returned by Last.fm. */ private static function formatLastFmText(?string $value): string { $artifacts = [ 'Read more on Last.fm.', 'Read more on Last.fm', 'User-contributed text is available under the Creative Commons By-SA License; additional terms may apply.', ]; return $value ? trim(str_replace($artifacts, '', nl2br(strip_tags(html_entity_decode($value))))) : ''; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/YouTube/YouTubeConnector.php
app/Http/Integrations/YouTube/YouTubeConnector.php
<?php namespace App\Http\Integrations\YouTube; use Saloon\Http\Auth\QueryAuthenticator; use Saloon\Http\Connector; use Saloon\Traits\Plugins\AcceptsJson; class YouTubeConnector extends Connector { use AcceptsJson; public function resolveBaseUrl(): string { return config('koel.services.youtube.endpoint'); } protected function defaultAuth(): QueryAuthenticator { return new QueryAuthenticator('key', config('koel.services.youtube.key')); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php
app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php
<?php namespace App\Http\Integrations\YouTube\Requests; use App\Models\Song; use Saloon\Enums\Method; use Saloon\Http\Request; class SearchVideosRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly Song $song, private readonly string $pageToken = '') { } public function resolveEndpoint(): string { return '/search'; } /** @inheritdoc */ protected function defaultQuery(): array { $q = $this->song->title; // If the artist is worth noticing, include them into the search. if (!$this->song->artist->is_unknown && !$this->song->artist->is_various) { $q .= " {$this->song->artist->name}"; } return [ 'part' => 'snippet', 'type' => 'video', 'maxResults' => 10, 'pageToken' => $this->pageToken, 'q' => $q, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Wikipedia/WikipediaConnector.php
app/Http/Integrations/Wikipedia/WikipediaConnector.php
<?php namespace App\Http\Integrations\Wikipedia; use Saloon\Http\Connector; class WikipediaConnector extends Connector { public function resolveBaseUrl(): string { return 'https://en.wikipedia.org/api/rest_v1/'; } /** @inheritdoc */ protected function defaultHeaders(): array { return [ 'Accept' => 'application/json', 'User-Agent' => sprintf('%s/%s( %s )', config('app.name'), koel_version(), config('app.url')), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/Wikipedia/Requests/GetPageSummaryRequest.php
app/Http/Integrations/Wikipedia/Requests/GetPageSummaryRequest.php
<?php namespace App\Http\Integrations\Wikipedia\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class GetPageSummaryRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $pageTitle) { } public function resolveEndpoint(): string { return "page/summary/{$this->pageTitle}"; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/MusicBrainzConnector.php
app/Http/Integrations/MusicBrainz/MusicBrainzConnector.php
<?php namespace App\Http\Integrations\MusicBrainz; use Saloon\Http\Connector; use Saloon\Traits\Plugins\AcceptsJson; class MusicBrainzConnector extends Connector { use AcceptsJson; public function resolveBaseUrl(): string { return config('koel.services.musicbrainz.endpoint'); } /** @inheritdoc */ public function defaultHeaders(): array { return [ 'Accept' => 'application/json', 'User-Agent' => config('koel.services.musicbrainz.user_agent') ?: sprintf('%s/%s( %s )', config('app.name'), koel_version(), config('app.url')), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/Requests/SearchForArtistRequest.php
app/Http/Integrations/MusicBrainz/Requests/SearchForArtistRequest.php
<?php namespace App\Http\Integrations\MusicBrainz\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class SearchForArtistRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $name) { } public function resolveEndpoint(): string { return '/artist'; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'query' => "artist:{$this->name}", 'limit' => 1, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/Requests/GetRecordingsRequest.php
app/Http/Integrations/MusicBrainz/Requests/GetRecordingsRequest.php
<?php namespace App\Http\Integrations\MusicBrainz\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class GetRecordingsRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $mbid) { } public function resolveEndpoint(): string { return "/release/{$this->mbid}"; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'inc' => 'recordings', ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/Requests/GetArtistUrlRelationshipsRequest.php
app/Http/Integrations/MusicBrainz/Requests/GetArtistUrlRelationshipsRequest.php
<?php namespace App\Http\Integrations\MusicBrainz\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class GetArtistUrlRelationshipsRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $mbid) { } public function resolveEndpoint(): string { return "/artist/{$this->mbid}"; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'inc' => 'url-rels', ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/Requests/GetReleaseGroupUrlRelationshipsRequest.php
app/Http/Integrations/MusicBrainz/Requests/GetReleaseGroupUrlRelationshipsRequest.php
<?php namespace App\Http\Integrations\MusicBrainz\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class GetReleaseGroupUrlRelationshipsRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $mbid) { } public function resolveEndpoint(): string { return "/release-group/{$this->mbid}"; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'inc' => 'url-rels', ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Integrations/MusicBrainz/Requests/SearchForReleaseRequest.php
app/Http/Integrations/MusicBrainz/Requests/SearchForReleaseRequest.php
<?php namespace App\Http\Integrations\MusicBrainz\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class SearchForReleaseRequest extends Request { protected Method $method = Method::GET; public function __construct(private readonly string $albumName, private readonly string $artistName) { } public function resolveEndpoint(): string { return '/release'; } /** @inheritdoc */ protected function defaultQuery(): array { return [ 'query' => "release:\"{$this->albumName}\" AND artist:\"{$this->artistName}\"", 'limit' => 1, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/CollaborativeSongResourceCollection.php
app/Http/Resources/CollaborativeSongResourceCollection.php
<?php namespace App\Http\Resources; class CollaborativeSongResourceCollection extends SongResourceCollection { /** @inheritdoc */ public function toArray($request): array { $user = $this->user ?? auth()->user(); return $this->collection->map( static fn (CollaborativeSongResource $resource) => $resource->for($user) )->toArray(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/SongFileResource.php
app/Http/Resources/SongFileResource.php
<?php namespace App\Http\Resources; use App\Enums\SongStorageType; use App\Models\Song; use Webmozart\Assert\Assert; class SongFileResource extends SongResource { public const JSON_STRUCTURE = [ 'type', 'id', 'title', 'lyrics', 'album_id', 'album_name', 'artist_id', 'artist_name', 'album_artist_id', 'album_artist_name', 'album_cover', 'length', 'liked', 'play_count', 'track', 'genre', 'year', 'disc', 'is_public', 'basename', 'created_at', ]; public function __construct(protected Song $song) { Assert::true($song->storage === SongStorageType::LOCAL); parent::__construct($song); } /** @return SongFileResourceCollection */ public static function collection($resource): SongResourceCollection { return SongFileResourceCollection::make($resource); } /** @inheritDoc */ public function toArray($request): array { $data = parent::toArray($request); $data['basename'] = $this->song->basename; return $data; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/CollaborativeSongResource.php
app/Http/Resources/CollaborativeSongResource.php
<?php namespace App\Http\Resources; use App\Values\Playlist\PlaylistCollaborator; use Carbon\Carbon; class CollaborativeSongResource extends SongResource { public const JSON_STRUCTURE = SongResource::JSON_STRUCTURE + [ 'collaboration' => [ 'user' => PlaylistCollaboratorResource::JSON_STRUCTURE, 'added_at', 'fmt_added_at', ], ]; /** @return CollaborativeSongResourceCollection */ public static function collection($resource): SongResourceCollection { return CollaborativeSongResourceCollection::make($resource); } /** @inheritdoc */ public function toArray($request): array { return array_merge(parent::toArray($request), [ 'collaboration' => [ 'user' => PlaylistCollaboratorResource::make( PlaylistCollaborator::make( $this->song->collaborator_public_id, $this->song->collaborator_name, avatar_or_gravatar($this->song->collaborator_avatar, $this->song->collaborator_email), ), ), 'added_at' => $this->song->added_at, 'fmt_added_at' => $this->song->added_at ? Carbon::make($this->song->added_at)?->diffForHumans() : null, ], ]); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PodcastResource.php
app/Http/Resources/PodcastResource.php
<?php namespace App\Http\Resources; use App\Models\Podcast; use App\Models\PodcastUserPivot; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class PodcastResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'url', 'title', 'image', 'link', 'description', 'author', ]; public function __construct(private readonly Podcast $podcast, private readonly bool $withSubscriptionData = true) { parent::__construct($this->podcast); } public static function collection($resource): PodcastResourceCollection { return PodcastResourceCollection::make($resource); } /** @inheritdoc */ public function toArray(Request $request): array { $data = [ 'type' => 'podcast', 'id' => $this->podcast->id, 'url' => $this->podcast->url, 'title' => $this->podcast->title, 'image' => $this->podcast->image, 'link' => $this->podcast->link, 'description' => $this->podcast->description, 'author' => $this->podcast->author, 'favorite' => $this->podcast->favorite, ]; if ($this->withSubscriptionData) { /** @var User $user */ $user = $request->user(); /** @var PodcastUserPivot $pivot */ $pivot = $this->podcast->subscribers->sole('id', $user->id)->pivot; $data['subscribed_at'] = $pivot->created_at; $data['last_played_at'] = $pivot->updated_at; $data['state'] = $pivot->state->toArray(); } return $data; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/QueueStateResource.php
app/Http/Resources/QueueStateResource.php
<?php namespace App\Http\Resources; use App\Values\QueueState; use Illuminate\Http\Resources\Json\JsonResource; class QueueStateResource extends JsonResource { public const JSON_STRUCTURE = [ 'songs' => [ SongResource::JSON_STRUCTURE, ], 'current_song', 'playback_position', ]; public function __construct(private readonly QueueState $state) { parent::__construct($state); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'queue-states', 'songs' => SongResource::collection($this->state->playables)->for(auth()->user()), 'current_song' => $this->state->currentPlayable ? new SongResource($this->state->currentPlayable) : null, 'playback_position' => $this->state->playbackPosition, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PlaylistResource.php
app/Http/Resources/PlaylistResource.php
<?php namespace App\Http\Resources; use App\Models\Playlist; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class PlaylistResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'description', 'folder_id', 'user_id', 'is_smart', 'rules', 'created_at', ]; public function __construct(private readonly Playlist $playlist) { parent::__construct($playlist); } /** @inheritdoc */ public function toArray(Request $request): array { $user = $request->user() ?? $this->playlist->owner; $embedding = $request->routeIs('embeds.payload'); return [ 'type' => 'playlists', 'id' => $this->playlist->id, 'name' => $this->playlist->name, 'description' => $this->playlist->description, 'folder_id' => $this->unless($embedding, $this->playlist->getFolderId($user)), 'user_id' => $this->unless($embedding, $this->playlist->owner->public_id), // backwards compatibility 'owner_id' => $this->unless($embedding, $this->playlist->owner->public_id), 'is_smart' => $this->unless($embedding, $this->playlist->is_smart), 'is_collaborative' => $this->unless($embedding, $this->playlist->is_collaborative), 'rules' => $this->unless($embedding, $this->playlist->rules), 'cover' => image_storage_url($this->playlist->cover), 'created_at' => $this->unless($embedding, $this->playlist->created_at), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/ThemeResource.php
app/Http/Resources/ThemeResource.php
<?php namespace App\Http\Resources; use App\Models\Theme; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ThemeResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'thumbnail_color', 'thumbnail_image', 'properties' => [ '--color-fg', '--color-bg', '--color-highlight', '--font-family', '--font-size', '--bg-image', ], 'is_custom', ]; public function __construct(private readonly Theme $theme) { parent::__construct($theme); } /** @inheritdoc */ public function toArray(Request $request): array { return [ 'type' => 'themes', 'id' => $this->theme->id, 'name' => $this->theme->name, 'thumbnail_color' => $this->theme->properties->bgColor, 'thumbnail_image' => $this->theme->thumbnail ? image_storage_url($this->theme->thumbnail) : '', 'properties' => $this->theme->properties->toArray(), 'is_custom' => true, // as opposed to built-in themes ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PlaylistCollaborationTokenResource.php
app/Http/Resources/PlaylistCollaborationTokenResource.php
<?php namespace App\Http\Resources; use App\Models\PlaylistCollaborationToken; use Illuminate\Http\Resources\Json\JsonResource; class PlaylistCollaborationTokenResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'token', ]; public function __construct(private readonly PlaylistCollaborationToken $token) { parent::__construct($token); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'playlist_collaboration_tokens', 'token' => $this->token->token, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/SongResource.php
app/Http/Resources/SongResource.php
<?php namespace App\Http\Resources; use App\Facades\License; use App\Models\Song; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; class SongResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'title', 'lyrics', 'album_id', 'album_name', 'artist_id', 'artist_name', 'album_artist_id', 'album_artist_name', 'album_cover', 'length', 'liked', 'play_count', 'track', 'genre', 'year', 'disc', 'is_public', 'created_at', ]; public const PAGINATION_JSON_STRUCTURE = [ 'data' => [ 0 => self::JSON_STRUCTURE, ], 'links' => [ 'first', 'last', 'prev', 'next', ], 'meta' => [ 'current_page', 'from', 'path', 'per_page', 'to', ], ]; private ?User $user = null; public function __construct(protected Song $song) { parent::__construct($song); } public static function collection($resource): SongResourceCollection { return SongResourceCollection::make($resource); } public function for(User $user): self { $this->user = $user; return $this; } /** @inheritDoc */ public function toArray(Request $request): array { $isPlus = once(static fn () => License::isPlus()); $user = $this->user ?? once(static fn () => auth()->user()); $embedding = $request->routeIs('embeds.payload'); $data = [ 'type' => Str::plural($this->song->type->value), 'id' => $this->song->id, 'title' => $this->song->title, 'lyrics' => $this->unless($embedding, $this->song->lyrics), 'album_id' => $this->unless($embedding, $this->song->album_id), 'album_name' => $this->song->album_name, 'artist_id' => $this->unless($embedding, $this->song->artist_id), 'artist_name' => $this->song->artist?->name, 'album_artist_id' => $this->unless($embedding, $this->song->album_artist?->id), 'album_artist_name' => $this->unless($embedding, $this->song->album_artist?->name), 'album_cover' => image_storage_url($this->song->album?->cover), 'length' => $this->song->length, 'liked' => $this->unless($embedding, $this->song->favorite), // backwards compatibility 'favorite' => $this->unless($embedding, $this->song->favorite), 'play_count' => $this->unless($embedding, (int) $this->song->play_count), 'track' => $this->song->track, 'disc' => $this->unless($embedding, $this->song->disc), 'genre' => $this->unless($embedding, $this->song->genre), 'year' => $this->unless($embedding, $this->song->year), 'is_public' => $this->unless($embedding, $this->song->is_public), 'created_at' => $this->unless($embedding, $this->song->created_at), 'embed_stream_url' => $this->when( $embedding, fn () => URL::temporarySignedRoute('embeds.stream', now()->addDay(), [ 'song' => $this->song->id, 'embed' => $request->route('embed')->id, // @phpstan-ignore-line 'options' => $request->route('options'), ]), ), ]; if ($this->song->isEpisode()) { $data += [ 'episode_description' => $this->unless($embedding, $this->song->episode_metadata->description), 'episode_link' => $this->song->episode_metadata->link, 'episode_image' => $this->song->episode_metadata->image ?? $this->song->podcast->image, 'podcast_id' => $this->unless($embedding, $this->song->podcast->id), 'podcast_title' => $this->song->podcast->title, 'podcast_author' => $this->song->podcast->metadata->author, ]; } else { $data += [ 'owner_id' => $this->unless($embedding, $this->song->owner->public_id), 'is_external' => $this->unless( $embedding, fn () => $isPlus && !$this->song->ownedBy($user), ), ]; } return $data; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/ResourcePermissionResource.php
app/Http/Resources/ResourcePermissionResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ResourcePermissionResource extends JsonResource { public function __construct( private readonly string $type, private readonly string|int $id, private readonly string $action, private readonly bool $allowed ) { parent::__construct($type); } /** @inheritDoc */ public function toArray(Request $request): array { return [ 'type' => 'resource-permissions', 'allowed' => $this->allowed, 'context' => [ 'type' => $this->type, 'id' => $this->id, 'action' => $this->action, ], ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/ArtistResource.php
app/Http/Resources/ArtistResource.php
<?php namespace App\Http\Resources; use App\Facades\License; use App\Models\Artist; use App\Models\User; use Illuminate\Http\Resources\Json\JsonResource; class ArtistResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'image', 'created_at', ]; public const PAGINATION_JSON_STRUCTURE = [ 'data' => [ '*' => self::JSON_STRUCTURE, ], 'links' => [ 'first', 'last', 'prev', 'next', ], 'meta' => [ 'current_page', 'from', 'path', 'per_page', 'to', ], ]; private ?User $user = null; public function __construct(private readonly Artist $artist) { parent::__construct($artist); } public function for(User $user): self { $this->user = $user; return $this; } /** @inheritdoc */ public function toArray($request): array { $isPlus = once(static fn () => License::isPlus()); $user = $this->user ?? once(static fn () => auth()->user()); $embedding = $request->routeIs('embeds.payload'); return [ 'type' => 'artists', 'id' => $this->artist->id, 'name' => $this->artist->name, 'image' => image_storage_url($this->artist->image), 'created_at' => $this->unless($embedding, $this->artist->created_at), 'is_external' => $this->unless( $embedding, fn () => $isPlus && $this->artist->user_id !== $user->id, ), 'favorite' => $this->unless($embedding, $this->artist->favorite), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/UserResource.php
app/Http/Resources/UserResource.php
<?php namespace App\Http\Resources; use App\Enums\Acl\Role; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class UserResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'email', 'avatar', 'preferences', 'is_prospect', 'sso_provider', 'sso_id', 'is_admin', 'role', 'permissions', ]; public function __construct(private readonly User $user) { parent::__construct($user); } /** @inheritdoc */ public function toArray(Request $request): array { $isCurrentUser = $this->user->is($request->user()); return [ 'type' => 'users', 'id' => $this->user->public_id, 'name' => $this->user->name, 'email' => $this->user->email, 'avatar' => $this->user->avatar, 'preferences' => $this->when($isCurrentUser, fn () => $this->user->preferences), 'is_prospect' => $this->user->is_prospect, 'sso_provider' => $this->user->sso_provider, 'sso_id' => $this->user->sso_id, 'is_admin' => $this->user->role === Role::ADMIN, // @todo remove this backward-compatibility field 'role' => $this->user->role, 'permissions' => $this->when( $isCurrentUser, fn () => $this->user->getPermissionsViaRoles()->pluck('name')->toArray(), ), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/SongFileResourceCollection.php
app/Http/Resources/SongFileResourceCollection.php
<?php namespace App\Http\Resources; class SongFileResourceCollection extends SongResourceCollection { /** @inheritdoc */ public function toArray($request): array { $user = $this->user ?? auth()->user(); return $this->collection->map(static fn (SongFileResource $resource) => $resource->for($user))->toArray(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/EmbedOptionsResource.php
app/Http/Resources/EmbedOptionsResource.php
<?php namespace App\Http\Resources; use App\Values\EmbedOptions; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class EmbedOptionsResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'theme', 'layout', 'preview', ]; public function __construct(private readonly EmbedOptions $options) { parent::__construct($options); } /** @inheritdoc */ public function toArray(Request $request): array { return [ 'type' => 'embed-options', 'theme' => $this->options->theme, 'layout' => $this->options->layout, 'preview' => $this->options->preview, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/ExcerptSearchResource.php
app/Http/Resources/ExcerptSearchResource.php
<?php namespace App\Http\Resources; use App\Values\ExcerptSearchResult; use Illuminate\Http\Resources\Json\JsonResource; class ExcerptSearchResource extends JsonResource { public const JSON_STRUCTURE = [ 'songs' => [ SongResource::JSON_STRUCTURE, ], 'artists' => [ ArtistResource::JSON_STRUCTURE, ], 'albums' => [ AlbumResource::JSON_STRUCTURE, ], 'podcasts' => [ PodcastResource::JSON_STRUCTURE, ], 'radio_stations' => [ RadioStationResource::JSON_STRUCTURE, ], ]; public function __construct(private readonly ExcerptSearchResult $result) { parent::__construct($result); } /** @inheritdoc */ public function toArray($request): array { return [ 'songs' => SongResource::collection($this->result->songs), 'artists' => ArtistResource::collection($this->result->artists), 'albums' => AlbumResource::collection($this->result->albums), 'podcasts' => PodcastResource::collection($this->result->podcasts), 'radio_stations' => RadioStationResource::collection($this->result->radioStations), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/GenreResource.php
app/Http/Resources/GenreResource.php
<?php namespace App\Http\Resources; use App\Values\GenreSummary; use Illuminate\Http\Resources\Json\JsonResource; class GenreResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', ]; public function __construct(private readonly GenreSummary $summary) { parent::__construct($summary); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'genres', 'id' => $this->summary->publicId, 'name' => $this->summary->name, 'song_count' => $this->summary->songCount, 'length' => $this->summary->length, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PodcastResourceCollection.php
app/Http/Resources/PodcastResourceCollection.php
<?php namespace App\Http\Resources; use App\Models\Podcast; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\ResourceCollection; use Illuminate\Support\Collection; class PodcastResourceCollection extends ResourceCollection { public function __construct( private readonly Collection $podcasts, private readonly bool $withSubscriptionData = true ) { parent::__construct($this->podcasts); } /** @inheritDoc */ public function toArray(Request $request): array { return $this->podcasts->map(function (Podcast $podcast): PodcastResource { return PodcastResource::make($podcast, $this->withSubscriptionData); })->toArray(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/FolderResource.php
app/Http/Resources/FolderResource.php
<?php namespace App\Http\Resources; use App\Models\Folder; use Illuminate\Http\Resources\Json\JsonResource; class FolderResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'path', 'name', ]; public function __construct(private readonly Folder $folder) { parent::__construct($this->folder); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'folders', 'id' => $this->folder->id, 'path' => $this->folder->path, 'name' => $this->folder->name, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/EmbedResource.php
app/Http/Resources/EmbedResource.php
<?php namespace App\Http\Resources; use App\Enums\EmbeddableType; use App\Models\Embed; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class EmbedResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'embeddable_type', 'embeddable_id', 'user_id', 'embeddable', ]; public const JSON_PUBLIC_STRUCTURE = [ 'type', 'id', 'embeddable_type', 'embeddable_id', 'embeddable', 'playables', ]; public function __construct( private readonly Embed $embed, private readonly ?Collection $playables = null, ) { parent::__construct($embed); } /** @inheritdoc */ public function toArray(Request $request): array { $embedding = $request->routeIs('embeds.payload'); return [ 'type' => 'embeds', 'id' => $this->embed->id, 'embeddable_type' => $this->embed->embeddable_type, 'embeddable_id' => $this->embed->embeddable_id, 'user_id' => $this->unless($embedding, $this->embed->user->public_id), 'embeddable' => $this->transformEmbeddableToResource(), 'playables' => SongResourceCollection::make($this->whenNotNull($this->playables))->for($this->embed->user), ]; } private function transformEmbeddableToResource(): JsonResource { return EmbeddableType::from($this->embed->embeddable_type) ->resourceClass() ::make($this->embed->embeddable); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/FavoriteResource.php
app/Http/Resources/FavoriteResource.php
<?php namespace App\Http\Resources; use App\Models\Favorite; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class FavoriteResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'favoriteable_type', 'favoriteable_id', 'user_id', 'created_at', ]; public function __construct(private readonly Favorite $favorite) { parent::__construct($favorite); } /** @inheritdoc */ public function toArray(Request $request): array { return [ 'type' => 'favorites', 'favoriteable_type' => $this->favorite->favoriteable_type, 'favoriteable_id' => $this->favorite->favoriteable_id, 'user_id' => $this->favorite->user_id, 'created_at' => $this->favorite->created_at, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/LiveEventResource.php
app/Http/Resources/LiveEventResource.php
<?php namespace App\Http\Resources; use App\Values\Ticketmaster\TicketmasterEvent; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class LiveEventResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'dates' => [ 'start', 'end', ], 'venue' => [ 'name', 'url', 'city', ], 'url', 'image', ]; // Right now we only have Ticketmaster events, so we keep it simple. public function __construct(private readonly TicketmasterEvent $event) { parent::__construct($event); } /** @inheritdoc */ public function toArray(Request $request): array { $data = $this->event->toArray(); $data['type'] = 'live-events'; return $data; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/UserProspectResource.php
app/Http/Resources/UserProspectResource.php
<?php namespace App\Http\Resources; use App\Models\User; use Illuminate\Http\Resources\Json\JsonResource; class UserProspectResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'email', 'avatar', 'role', 'is_prospect', ]; public function __construct(private readonly User $user) { parent::__construct($user); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'users', 'id' => $this->user->public_id, 'name' => $this->user->name, 'email' => $this->user->email, 'avatar' => $this->user->avatar, 'role' => $this->user->role->value, 'is_prospect' => $this->user->is_prospect, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/InteractionResource.php
app/Http/Resources/InteractionResource.php
<?php namespace App\Http\Resources; use App\Models\Interaction; use Illuminate\Http\Resources\Json\JsonResource; class InteractionResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'songId', 'song_id', 'playCount', 'play_count', ]; public function __construct(private readonly Interaction $interaction) { parent::__construct($interaction); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'interactions', 'id' => $this->interaction->id, 'songId' => $this->interaction->song_id, // @fixme backwards compatibility 'song_id' => $this->interaction->song_id, 'playCount' => $this->interaction->play_count, // @fixme backwards compatibility 'play_count' => $this->interaction->play_count, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PodcastCategoryResource.php
app/Http/Resources/PodcastCategoryResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use PhanAn\Poddle\Values\Category; class PodcastCategoryResource extends JsonResource { public function __construct(private readonly Category $category) { parent::__construct($this->category); } /** @inheritDoc */ public function toArray(Request $request): array { return ['type' => 'podcast-categories'] + $this->category->toArray(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PlaylistCollaboratorResource.php
app/Http/Resources/PlaylistCollaboratorResource.php
<?php namespace App\Http\Resources; use App\Values\Playlist\PlaylistCollaborator; use Illuminate\Http\Resources\Json\JsonResource; class PlaylistCollaboratorResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'avatar', ]; public function __construct(private readonly PlaylistCollaborator $collaborator) { parent::__construct($collaborator); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'playlist-collaborators', 'id' => $this->collaborator->publicId, 'name' => $this->collaborator->name, 'avatar' => $this->collaborator->avatar, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/AlbumResource.php
app/Http/Resources/AlbumResource.php
<?php namespace App\Http\Resources; use App\Facades\License; use App\Models\Album; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class AlbumResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'artist_id', 'artist_name', 'cover', 'created_at', 'year', ]; public const PAGINATION_JSON_STRUCTURE = [ 'data' => [ '*' => self::JSON_STRUCTURE, ], 'links' => [ 'first', 'last', 'prev', 'next', ], 'meta' => [ 'current_page', 'from', 'path', 'per_page', 'to', ], ]; private ?User $user = null; public function __construct(private readonly Album $album) { parent::__construct($album); } public function for(User $user): self { $this->user = $user; return $this; } /** @inheritdoc */ public function toArray(Request $request): array { $isPlus = once(static fn () => License::isPlus()); $user = $this->user ?? once(static fn () => auth()->user()); $embedding = $request->routeIs('embeds.payload'); return [ 'type' => 'albums', 'id' => $this->album->id, 'name' => $this->album->name, 'artist_id' => $this->album->artist->id, 'artist_name' => $this->album->artist->name, 'cover' => image_storage_url($this->album->cover), 'created_at' => $this->unless($embedding, $this->album->created_at), 'year' => $this->album->year, 'is_external' => $this->unless( $embedding, fn () => $isPlus && $this->album->user_id !== $user->id, ), 'favorite' => $this->unless($embedding, $this->album->favorite), ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/SongResourceCollection.php
app/Http/Resources/SongResourceCollection.php
<?php namespace App\Http\Resources; use App\Models\User; use Illuminate\Http\Resources\Json\ResourceCollection; class SongResourceCollection extends ResourceCollection { protected ?User $user; public function for(?User $user): static { $this->user = $user; return $this; } /** @inheritdoc */ public function toArray($request): array { $user = $this->user ?? auth()->user(); return $this->collection->map(static fn (SongResource $resource) => $resource->for($user))->toArray(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/PlaylistFolderResource.php
app/Http/Resources/PlaylistFolderResource.php
<?php namespace App\Http\Resources; use App\Models\PlaylistFolder; use Illuminate\Http\Resources\Json\JsonResource; class PlaylistFolderResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'id', 'name', 'user_id', 'created_at', ]; public function __construct(private readonly PlaylistFolder $folder) { parent::__construct($folder); } /** @inheritdoc */ public function toArray($request): array { return [ 'type' => 'playlist-folders', 'id' => $this->folder->id, 'name' => $this->folder->name, 'user_id' => $this->folder->user_id, 'created_at' => $this->folder->created_at, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Http/Resources/RadioStationResource.php
app/Http/Resources/RadioStationResource.php
<?php namespace App\Http\Resources; use App\Models\RadioStation; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class RadioStationResource extends JsonResource { public const JSON_STRUCTURE = [ 'type', 'name', 'id', 'url', 'logo', 'description', 'is_public', 'created_at', ]; public function __construct(private readonly RadioStation $station) { parent::__construct($station); } /** @inheritdoc */ public function toArray(Request $request): array { return [ 'type' => 'radio-stations', 'name' => $this->station->name, 'id' => $this->station->id, 'url' => $this->station->url, 'logo' => image_storage_url($this->station->logo), 'description' => $this->station->description, 'is_public' => $this->station->is_public, 'created_at' => $this->station->created_at, 'favorite' => $this->station->favorite, ]; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Mail/UserInvite.php
app/Mail/UserInvite.php
<?php namespace App\Mail; use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; class UserInvite extends Mailable { use Queueable; use SerializesModels; public function __construct(private readonly User $invitee) { } public function content(): Content { return new Content( markdown: 'emails.users.invite', with: [ 'invitee' => $this->invitee, 'url' => url("/#/invitation/accept/{$this->invitee->invitation_token}"), ], ); } public function envelope(): Envelope { return new Envelope(subject: 'Invitation to join Koel'); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Filesystems/DropboxFilesystem.php
app/Filesystems/DropboxFilesystem.php
<?php namespace App\Filesystems; use DateTimeInterface; use League\Flysystem\Filesystem; use Spatie\FlysystemDropbox\DropboxAdapter; class DropboxFilesystem extends Filesystem { public function __construct(private readonly DropboxAdapter $adapter) { parent::__construct($adapter, ['case_sensitive' => false]); } public function temporaryUrl(string $path, ?DateTimeInterface $expiresAt = null, array $config = []): string { return $this->adapter->getUrl($path); } public function getAdapter(): DropboxAdapter { return $this->adapter; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/SmartPlaylistRulesCast.php
app/Casts/SmartPlaylistRulesCast.php
<?php namespace App\Casts; use App\Values\SmartPlaylist\SmartPlaylistRuleGroupCollection; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class SmartPlaylistRulesCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): ?SmartPlaylistRuleGroupCollection { return $value ? rescue(static fn () => SmartPlaylistRuleGroupCollection::create(json_decode($value, true))) : null; } public function set($model, string $key, $value, array $attributes): ?string { if (is_array($value)) { $value = SmartPlaylistRuleGroupCollection::create($value); } return $value?->toJson() ?? null; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/EncryptedValueCast.php
app/Casts/EncryptedValueCast.php
<?php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Support\Facades\Crypt; class EncryptedValueCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): ?string { return $value ? Crypt::decrypt($value) : null; } public function set($model, string $key, $value, array $attributes): ?string { return $value ? Crypt::encrypt($value) : null; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/LicenseMetaCast.php
app/Casts/LicenseMetaCast.php
<?php namespace App\Casts; use App\Values\License\LicenseMeta; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Support\Facades\Log; use Throwable; class LicenseMetaCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): ?LicenseMeta { try { return $value ? LicenseMeta::fromJson(json_decode($value)) : null; } catch (Throwable) { Log::error('Failed to cast-get license meta', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return null; } } /** @param ?LicenseMeta $value */ public function set($model, string $key, $value, array $attributes): ?string { try { return $value?->toJson(); } catch (Throwable) { Log::error('Failed to cast-set license meta', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return null; } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/UserPreferencesCast.php
app/Casts/UserPreferencesCast.php
<?php namespace App\Casts; use App\Values\User\UserPreferences; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class UserPreferencesCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): UserPreferences { return UserPreferences::fromArray(json_decode($value, true) ?: []); } /** @param UserPreferences|null $value */ public function set($model, string $key, $value, array $attributes): ?string { return json_encode($value ?: []); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/SongTitleCast.php
app/Casts/SongTitleCast.php
<?php namespace App\Casts; use App\Models\Song; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; class SongTitleCast implements CastsAttributes { /** * @param Song $model * @param string|null $value */ public function get(Model $model, string $key, mixed $value, array $attributes): string { // If the title is empty, we "guess" the title by extracting the filename from the song's path. return $value ?: pathinfo($model->path, PATHINFO_FILENAME); } /** * @param string $value */ public function set(Model $model, string $key, mixed $value, array $attributes): string { return html_entity_decode($value); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/SongLyricsCast.php
app/Casts/SongLyricsCast.php
<?php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; class SongLyricsCast implements CastsAttributes { /** @param string|null $value */ public function get(Model $model, string $key, mixed $value, array $attributes): string { if (!$value) { return ''; } // Since we're displaying the lyrics using <pre>, replace breaks with newlines and strip all tags. $value = strip_tags(preg_replace('#<br\s*/?>#i', PHP_EOL, $value)); // Keep the original LRC format with timestamps for synced lyrics support return $value; } public function set(Model $model, string $key, mixed $value, array $attributes): mixed { return $value; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/SongStorageCast.php
app/Casts/SongStorageCast.php
<?php namespace App\Casts; use App\Enums\SongStorageType; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; class SongStorageCast implements CastsAttributes { /** @param string|null $value */ public function get(Model $model, string $key, mixed $value, array $attributes): SongStorageType { if (!$value) { return SongStorageType::LOCAL; } return SongStorageType::tryFrom($value) ?? SongStorageType::LOCAL; } /** @param SongStorageType|string|null $value */ public function set(Model $model, string $key, mixed $value, array $attributes): ?string { $type = $value instanceof SongStorageType ? $value : SongStorageType::tryFrom($value); return $type?->value; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/LicenseInstanceCast.php
app/Casts/LicenseInstanceCast.php
<?php namespace App\Casts; use App\Values\License\LicenseInstance; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Support\Facades\Log; use Throwable; class LicenseInstanceCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): ?LicenseInstance { try { return $value ? LicenseInstance::fromJsonObject(json_decode($value)) : null; } catch (Throwable) { Log::error('Failed to cast-get license instance', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return null; } } /** @param ?LicenseInstance $value */ public function set($model, string $key, $value, array $attributes): ?string { try { return $value?->toJson(); } catch (Throwable) { Log::error('Failed to cast-set license instance', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return null; } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/ThemePropertiesCast.php
app/Casts/ThemePropertiesCast.php
<?php namespace App\Casts; use App\Values\Theme\ThemeProperties; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Support\Facades\Log; use Throwable; class ThemePropertiesCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes): ThemeProperties { try { return $value ? ThemeProperties::unserialize(json_decode($value)) : ThemeProperties::empty(); } catch (Throwable $e) { Log::error('Failed to cast-get theme properties', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return ThemeProperties::empty(); } } /** @param ?ThemeProperties $value */ public function set($model, string $key, $value, array $attributes): string { try { return $value?->serialize(); } catch (Throwable) { Log::error('Failed to cast-set theme properties', [ 'model' => $model, 'key' => $key, 'value' => $value, 'attributes' => $attributes, ]); return ''; } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/Podcast/EnclosureCast.php
app/Casts/Podcast/EnclosureCast.php
<?php namespace App\Casts\Podcast; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; use PhanAn\Poddle\Values\Enclosure; class EnclosureCast implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): Enclosure { return Enclosure::fromArray(json_decode($value, true)); } /** @param Enclosure|array $value */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (is_array($value)) { $value = Enclosure::fromArray($value); } return $value->toJson(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/Podcast/EpisodeMetadataCast.php
app/Casts/Podcast/EpisodeMetadataCast.php
<?php namespace App\Casts\Podcast; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; use PhanAn\Poddle\Values\EpisodeMetadata; use Throwable; class EpisodeMetadataCast implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): EpisodeMetadata { try { return EpisodeMetadata::fromArray(json_decode($value, true)); } catch (Throwable) { return EpisodeMetadata::fromArray([]); } } /** @param EpisodeMetadata|array<mixed>|null $value */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (is_array($value)) { $value = EpisodeMetadata::fromArray($value); } return $value?->toJson() ?? json_encode([]); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/Podcast/PodcastMetadataCast.php
app/Casts/Podcast/PodcastMetadataCast.php
<?php namespace App\Casts\Podcast; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; use PhanAn\Poddle\Values\ChannelMetadata; use Throwable; class PodcastMetadataCast implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): ChannelMetadata { try { return ChannelMetadata::fromArray(json_decode($value, true)); } catch (Throwable) { return ChannelMetadata::fromArray([]); } } /** @param ChannelMetadata|array<mixed>|null $value */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (is_array($value)) { $value = ChannelMetadata::fromArray($value); } return $value?->toJson() ?? json_encode([]); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/Podcast/CategoriesCast.php
app/Casts/Podcast/CategoriesCast.php
<?php namespace App\Casts\Podcast; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; use PhanAn\Poddle\Values\CategoryCollection; use Throwable; class CategoriesCast implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): CategoryCollection { try { return CategoryCollection::fromArray($value ? json_decode($value, true) : []); } catch (Throwable) { return CategoryCollection::make(); } } /** @param CategoryCollection|array<mixed> $value */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (is_array($value)) { $value = CategoryCollection::fromArray($value); } return $value->toJson(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Casts/Podcast/PodcastStateCast.php
app/Casts/Podcast/PodcastStateCast.php
<?php namespace App\Casts\Podcast; use App\Values\Podcast\PodcastState; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Model; class PodcastStateCast implements CastsAttributes { public function get(Model $model, string $key, mixed $value, array $attributes): PodcastState { if (is_string($value)) { $value = json_decode($value, true); } return PodcastState::fromArray($value ?? []); } /** * @param PodcastState|array|null $value */ public function set(Model $model, string $key, mixed $value, array $attributes): ?string { if (is_array($value)) { $value = PodcastState::fromArray($value); } return $value?->toJson(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/MakePlaylistSongsPublic.php
app/Listeners/MakePlaylistSongsPublic.php
<?php namespace App\Listeners; use App\Events\NewPlaylistCollaboratorJoined; use App\Services\PlaylistService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class MakePlaylistSongsPublic implements ShouldQueue { public function __construct(private PlaylistService $service) { } public function handle(NewPlaylistCollaboratorJoined $event): void { $this->service->makePlaylistContentPublic($event->token->playlist); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/WriteScanLog.php
app/Listeners/WriteScanLog.php
<?php namespace App\Listeners; use App\Events\MediaScanCompleted; use App\Values\Scanning\ScanResult; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; readonly class WriteScanLog implements ShouldQueue { public function handle(MediaScanCompleted $event): void { $transformer = static fn (ScanResult $entry) => (string) $entry; /** @var Collection $messages */ $messages = config('koel.sync_log_level') === 'all' ? $event->results->map($transformer) : $event->results->error()->map($transformer); rescue(static function () use ($messages): void { $file = storage_path('logs/sync-' . now()->format('Ymd-His') . '.log'); File::put($file, implode(PHP_EOL, $messages->toArray())); }); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/DeletePodcastIfNoSubscribers.php
app/Listeners/DeletePodcastIfNoSubscribers.php
<?php namespace App\Listeners; use App\Events\UserUnsubscribedFromPodcast; use App\Services\PodcastService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class DeletePodcastIfNoSubscribers implements ShouldQueue { public function __construct(private PodcastService $podcastService) { } public function handle(UserUnsubscribedFromPodcast $event): void { if ($event->podcast->subscribers()->count() === 0) { $this->podcastService->deletePodcast($event->podcast); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/PruneLibrary.php
app/Listeners/PruneLibrary.php
<?php namespace App\Listeners; use App\Services\LibraryManager; use Illuminate\Contracts\Queue\ShouldQueue; readonly class PruneLibrary implements ShouldQueue { public function __construct(private LibraryManager $libraryManager) { } public function handle(): void { $this->libraryManager->prune(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/DeleteNonExistingRecordsPostScan.php
app/Listeners/DeleteNonExistingRecordsPostScan.php
<?php namespace App\Listeners; use App\Events\MediaScanCompleted; use App\Models\Song; use App\Repositories\SongRepository; use App\Values\Scanning\ScanResult; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Builder; readonly class DeleteNonExistingRecordsPostScan implements ShouldQueue { public function __construct(private SongRepository $songRepository) { } public function handle(MediaScanCompleted $event): void { $paths = $event->results ->valid() ->map(static fn (ScanResult $result) => $result->path) ->merge($this->songRepository->getAllStoredOnCloud()->pluck('path')) ->toArray(); Song::deleteWhereValueNotIn($paths, 'path', static function (Builder $builder): Builder { return $builder->whereNull('podcast_id'); }); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/UnloveMultipleTracksOnLastfm.php
app/Listeners/UnloveMultipleTracksOnLastfm.php
<?php namespace App\Listeners; use App\Events\MultipleSongsUnliked; use App\Services\LastfmService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class UnloveMultipleTracksOnLastfm implements ShouldQueue { public function __construct(private LastfmService $lastfm) { } public function handle(MultipleSongsUnliked $event): void { $songs = $event->songs->filter(static fn ($song) => !$song->isEpisode() && !$song->artist->is_unknown); if ($songs->isEmpty() || !LastfmService::enabled() || !$event->user->preferences->lastFmSessionKey) { return; } $this->lastfm->batchToggleLoveTracks($event->songs, $event->user, false); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/UpdateLastfmNowPlaying.php
app/Listeners/UpdateLastfmNowPlaying.php
<?php namespace App\Listeners; use App\Events\PlaybackStarted; use App\Services\LastfmService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class UpdateLastfmNowPlaying implements ShouldQueue { public function __construct(private LastfmService $lastfm) { } public function handle(PlaybackStarted $event): void { if ( !LastfmService::enabled() || !$event->user->preferences->lastFmSessionKey || $event->song->isEpisode() || $event->song->artist?->is_unknown ) { return; } $this->lastfm->updateNowPlaying($event->song, $event->user); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/LoveTrackOnLastfm.php
app/Listeners/LoveTrackOnLastfm.php
<?php namespace App\Listeners; use App\Events\SongFavoriteToggled; use App\Services\LastfmService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class LoveTrackOnLastfm implements ShouldQueue { public function __construct(private LastfmService $lastfm) { } public function handle(SongFavoriteToggled $event): void { if ( $event->song->isEpisode() || !LastfmService::enabled() || !$event->user->preferences->lastFmSessionKey || $event->song->artist->is_unknown ) { return; } $this->lastfm->toggleLoveTrack($event->song, $event->user, $event->favorite); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Listeners/LoveMultipleTracksOnLastfm.php
app/Listeners/LoveMultipleTracksOnLastfm.php
<?php namespace App\Listeners; use App\Events\MultipleSongsLiked; use App\Models\Song; use App\Services\LastfmService; use Illuminate\Contracts\Queue\ShouldQueue; readonly class LoveMultipleTracksOnLastfm implements ShouldQueue { public function __construct(private LastfmService $lastfm) { } public function handle(MultipleSongsLiked $event): void { $songs = $event->songs->filter(static fn (Song $song) => !$song->isEpisode() && !$song->artist->is_unknown); if ($songs->isEmpty() || !LastfmService::enabled() || !$event->user->preferences->lastFmSessionKey) { return; } $this->lastfm->batchToggleLoveTracks($songs, $event->user, true); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/RadioStationObserver.php
app/Observers/RadioStationObserver.php
<?php namespace App\Observers; use App\Models\RadioStation; use Illuminate\Support\Facades\File; class RadioStationObserver { public function updating(RadioStation $radioStation): void { if (!$radioStation->isDirty('logo')) { return; } rescue_if( $radioStation->getRawOriginal('logo'), static function (string $oldLogo): void { File::delete(image_storage_path($oldLogo)); } ); } public function deleted(RadioStation $radioStation): void { rescue_if($radioStation->logo, static fn () => File::delete(image_storage_path($radioStation->logo))); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/GenreObserver.php
app/Observers/GenreObserver.php
<?php namespace App\Observers; use App\Helpers\Ulid; use App\Models\Genre; class GenreObserver { public function creating(Genre $genre): void { $genre->public_id ??= Ulid::generate(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/PlaylistObserver.php
app/Observers/PlaylistObserver.php
<?php namespace App\Observers; use App\Models\Playlist; use Illuminate\Support\Facades\File; class PlaylistObserver { public function updating(Playlist $playlist): void { if (!$playlist->isDirty('cover')) { return; } $oldCover = $playlist->getRawOriginal('cover'); // If the cover is being updated, delete the old cover rescue_if($oldCover, static fn () => File::delete(image_storage_path($oldCover))); } public function deleted(Playlist $playlist): void { rescue_if($playlist->cover, static fn () => File::delete(image_storage_path($playlist->cover))); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/FolderObserver.php
app/Observers/FolderObserver.php
<?php namespace App\Observers; use App\Models\Folder; class FolderObserver { public function creating(Folder $folder): void { $folder->hash ??= simple_hash($folder->path); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/AlbumObserver.php
app/Observers/AlbumObserver.php
<?php namespace App\Observers; use App\Facades\Dispatcher; use App\Jobs\GenerateAlbumThumbnailJob; use App\Models\Album; use Illuminate\Support\Facades\File; class AlbumObserver { public function saved(Album $album): void { if ($album->cover && !File::exists(image_storage_path($album->thumbnail))) { Dispatcher::dispatch(new GenerateAlbumThumbnailJob($album)); } } public function updating(Album $album): void { if (!$album->isDirty('cover')) { return; } $oldCover = $album->getRawOriginal('cover'); // If the cover is being updated, delete the old cover and thumbnail files rescue_if( $oldCover, static function () use ($oldCover): void { $oldCoverPath = image_storage_path($oldCover); $parts = pathinfo($oldCoverPath); $oldThumbnail = sprintf('%s_thumb.%s', $parts['filename'], $parts['extension']); File::delete([$oldCoverPath, image_storage_path($oldThumbnail)]); }, ); } public function updated(Album $album): void { $changes = $album->getChanges(); if (array_key_exists('name', $changes)) { // Keep the artist name in sync across songs and albums, but only if it actually changed. $album->songs()->update(['album_name' => $changes['name']]); } } public function deleted(Album $album): void { $coverPath = image_storage_path($album->cover); $thumbnailPath = image_storage_path($album->thumbnail); rescue_if($coverPath || $thumbnailPath, static fn () => File::delete([$coverPath, $thumbnailPath])); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/PlaylistCollaborationTokenObserver.php
app/Observers/PlaylistCollaborationTokenObserver.php
<?php namespace App\Observers; use App\Helpers\Uuid; use App\Models\PlaylistCollaborationToken; class PlaylistCollaborationTokenObserver { public function creating(PlaylistCollaborationToken $token): void { $token->token ??= Uuid::generate(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/ArtistObserver.php
app/Observers/ArtistObserver.php
<?php namespace App\Observers; use App\Models\Artist; use Illuminate\Support\Facades\File; class ArtistObserver { public function updating(Artist $artist): void { if (!$artist->isDirty('image')) { return; } $oldImage = $artist->getRawOriginal('image'); rescue_if($oldImage, static fn () => File::delete(image_storage_path($oldImage))); } public function updated(Artist $artist): void { $changes = $artist->getChanges(); if (array_key_exists('name', $changes)) { // Keep the artist name in sync across songs and albums, but only if it actually changed. $artist->songs()->update(['artist_name' => $changes['name']]); $artist->albums()->update(['artist_name' => $changes['name']]); } } public function deleted(Artist $artist): void { rescue_if($artist->image, static fn () => File::delete(image_storage_url($artist->image))); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/ThemeObserver.php
app/Observers/ThemeObserver.php
<?php namespace App\Observers; use App\Models\Theme; use Illuminate\Support\Facades\File; class ThemeObserver { public function deleted(Theme $theme): void { rescue_if( $theme->properties->bgImage, static function () use ($theme): void { File::delete([ image_storage_path($theme->properties->bgImage), image_storage_path($theme->thumbnail), ]); }, ); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Observers/UserObserver.php
app/Observers/UserObserver.php
<?php namespace App\Observers; use App\Helpers\Uuid; use App\Models\User; use Illuminate\Support\Facades\File; class UserObserver { public function creating(User $user): void { $user->public_id ??= Uuid::generate(); } public function updating(User $user): void { if (!$user->isDirty('avatar')) { return; } $oldAvatar = $user->getRawOriginal('avatar'); // If the avatar is being updated, delete the old avatar rescue_if($oldAvatar, static fn () => File::delete(image_storage_path($oldAvatar))); } public function deleted(User $user): void { rescue_if( $user->has_custom_avatar, static fn () => File::delete(image_storage_path($user->getRawOriginal('avatar'))) ); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/MediaPath.php
app/Rules/MediaPath.php
<?php namespace App\Rules; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Support\Facades\File; class MediaPath implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { $passes = false; if (config('koel.storage_driver') === 'local') { $passes = $value && File::isDirectory($value) && File::isReadable($value); } if (!$passes) { $fail( config('koel.storage_driver') === 'local' ? 'Media path is required for local storage.' : 'Media path is not required for non-local storage.' ); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/ValidRadioStationUrl.php
app/Rules/ValidRadioStationUrl.php
<?php namespace App\Rules; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; use Illuminate\Translation\PotentiallyTranslatedString; class ValidRadioStationUrl implements ValidationRule { // Aid in testing by allowing the rule to be bypassed. // No need for overengineered abstractions and factories. public bool $bypass = false; /** * Run the validation rule. * * @param string $value The url to validate * @param Closure(string, ?string=): PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { if ($this->bypass) { return; } $contentType = Http::head($value)->header('Content-Type'); if (!$contentType || !Str::startsWith($contentType, 'audio/')) { $fail("The $attribute doesn't look like a valid radio station URL."); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/CustomizableUserPreference.php
app/Rules/CustomizableUserPreference.php
<?php namespace App\Rules; use App\Values\User\UserPreferences; use Closure; use Illuminate\Contracts\Validation\ValidationRule; class CustomizableUserPreference implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { if (!UserPreferences::customizable($value)) { $fail('Invalid or uncustomizable user preference key.'); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/UserCanManageRole.php
app/Rules/UserCanManageRole.php
<?php namespace App\Rules; use App\Enums\Acl\Role; use App\Models\User; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Translation\PotentiallyTranslatedString; class UserCanManageRole implements ValidationRule { public function __construct(private readonly User $user) { } /** * Run the validation rule. * * @param Closure(string, ?string=): PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { if (!$this->user->role->canManage(Role::from($value))) { $fail("The role $value is not manageable by the current user's role {$this->user->role->value}."); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/AllPlaylistsAreAccessibleBy.php
app/Rules/AllPlaylistsAreAccessibleBy.php
<?php namespace App\Rules; use App\Facades\License; use App\Models\User; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Support\Arr; final class AllPlaylistsAreAccessibleBy implements ValidationRule { public function __construct(private readonly User $user) { } public function validate(string $attribute, mixed $value, Closure $fail): void { $accessiblePlaylists = $this->user->playlists; if (License::isPlus()) { $accessiblePlaylists = $accessiblePlaylists->merge($this->user->collaboratedPlaylists); } if (array_diff(Arr::wrap($value), $accessiblePlaylists->modelKeys())) { $fail( License::isPlus() ? 'Not all playlists are accessible by the user' : 'Not all playlists belong to the user' ); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/AllPlayablesAreAccessibleBy.php
app/Rules/AllPlayablesAreAccessibleBy.php
<?php namespace App\Rules; use App\Models\User; use App\Repositories\SongRepository; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Support\Arr; class AllPlayablesAreAccessibleBy implements ValidationRule { public function __construct(private readonly User $user) { } /** @param array<string> $value */ public function validate(string $attribute, mixed $value, Closure $fail): void { $ids = array_unique(Arr::wrap($value)); if ($ids && $this->countAccessiblePlayables($ids) !== count($ids)) { $fail('Not all songs or episodes exist in the database or are accessible by the user.'); } } private function countAccessiblePlayables(array $ids): int { return app(SongRepository::class)->countAccessibleByIds($ids, $this->user); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/ValidSmartPlaylistRulePayload.php
app/Rules/ValidSmartPlaylistRulePayload.php
<?php namespace App\Rules; use App\Values\SmartPlaylist\SmartPlaylistRuleGroupCollection; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Support\Arr; class ValidSmartPlaylistRulePayload implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { $passes = (bool) rescue(static fn () => SmartPlaylistRuleGroupCollection::create(Arr::wrap($value))); if (!$passes) { $fail('Invalid smart playlist rules'); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/ValidImageData.php
app/Rules/ValidImageData.php
<?php namespace App\Rules; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Intervention\Image\Decoders\Base64ImageDecoder; use Intervention\Image\Decoders\DataUriImageDecoder; use Intervention\Image\Laravel\Facades\Image; use Throwable; class ValidImageData implements ValidationRule { public function validate(string $attribute, mixed $value, Closure $fail): void { try { Image::read($value, [ Base64ImageDecoder::class, DataUriImageDecoder::class, ]); } catch (Throwable) { $fail("Invalid image for $attribute"); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/SupportedAudioFile.php
app/Rules/SupportedAudioFile.php
<?php namespace App\Rules; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; class SupportedAudioFile implements ValidationRule { /** @param UploadedFile $value */ public function validate(string $attribute, mixed $value, Closure $fail): void { $passes = array_key_exists( Str::lower(File::mimeType($value->getRealPath())), config('koel.streaming.supported_mime_types') ); if (!$passes) { $fail('Unsupported audio file'); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Rules/AvailableRole.php
app/Rules/AvailableRole.php
<?php namespace App\Rules; use App\Enums\Acl\Role; use App\Facades\License; use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Translation\PotentiallyTranslatedString; class AvailableRole implements ValidationRule { /** * Run the validation rule. * * @param Closure(string, ?string=): PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { if (License::isPlus()) { return; } if (!Role::from($value)->available()) { $fail("Invalid role $value."); } } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Services/Util.php
app/Services/Util.php
<?php namespace App\Services; class Util { public function __construct() { defined('UTF8_BOM') || define('UTF8_BOM', chr(0xEF) . chr(0xBB) . chr(0xBF)); defined('UTF16_LITTLE_ENDIAN_BOM') || define('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE)); defined('UTF16_BIG_ENDIAN_BOM') || define('UTF16_BIG_ENDIAN_BOM', chr(0xFE) . chr(0xFF)); defined('UTF32_LITTLE_ENDIAN_BOM') || define('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00)); // @phpcs-ignore-line defined('UTF32_BIG_ENDIAN_BOM') || define('UTF32_BIG_ENDIAN_BOM', chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF)); // @phpcs-ignore-line } public function detectUTFEncoding(?string $str): ?string { switch (substr($str, 0, 2)) { case UTF16_BIG_ENDIAN_BOM: return 'UTF-16BE'; case UTF16_LITTLE_ENDIAN_BOM: return 'UTF-16LE'; } if (substr($str, 0, 3) === UTF8_BOM) { return 'UTF-8'; } return match (substr($str, 0, 4)) { UTF32_BIG_ENDIAN_BOM => 'UTF-32BE', UTF32_LITTLE_ENDIAN_BOM => 'UTF-32LE', default => null, }; } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false
koel/koel
https://github.com/koel/koel/blob/add9401a4b9a904bb1b9f679bc674ad1570ff20e/app/Services/NullEncyclopedia.php
app/Services/NullEncyclopedia.php
<?php namespace App\Services; use App\Models\Album; use App\Models\Artist; use App\Services\Contracts\Encyclopedia; use App\Values\Album\AlbumInformation; use App\Values\Artist\ArtistInformation; class NullEncyclopedia implements Encyclopedia { public function getArtistInformation(Artist $artist): ?ArtistInformation { return ArtistInformation::make(); } public function getAlbumInformation(Album $album): ?AlbumInformation { return AlbumInformation::make(); } }
php
MIT
add9401a4b9a904bb1b9f679bc674ad1570ff20e
2026-01-04T15:02:34.446708Z
false