chore(*): remove duplicate cache rule + cleanup cache headers; cleanup + formatting
This commit is contained in:
parent
425fed6ff6
commit
0e565970a5
42 changed files with 223 additions and 217 deletions
|
@ -16,8 +16,8 @@ class ArtistImportHandler extends ApiHandler
|
|||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->ensureCliAccess();
|
||||
|
||||
$this->ensureCliAccess();
|
||||
$this->artistImportToken = getenv("ARTIST_IMPORT_TOKEN");
|
||||
$this->navidromeApiUrl = getenv("NAVIDROME_API_URL");
|
||||
$this->navidromeAuthToken = getenv("NAVIDROME_API_TOKEN");
|
||||
|
@ -32,13 +32,8 @@ class ArtistImportHandler extends ApiHandler
|
|||
$providedToken = $input["token"] ?? null;
|
||||
$artistId = $input["artistId"] ?? null;
|
||||
|
||||
if ($providedToken !== $this->artistImportToken) {
|
||||
$this->sendJsonResponse("error", "Unauthorized access", 401);
|
||||
}
|
||||
|
||||
if (!$artistId) {
|
||||
$this->sendJsonResponse("error", "Artist ID is required", 400);
|
||||
}
|
||||
if ($providedToken !== $this->artistImportToken) $this->sendJsonResponse("error", "Unauthorized access", 401);
|
||||
if (!$artistId) $this->sendJsonResponse("error", "Artist ID is required", 400);
|
||||
|
||||
try {
|
||||
$artistData = $this->fetchNavidromeArtist($artistId);
|
||||
|
@ -56,7 +51,9 @@ class ArtistImportHandler extends ApiHandler
|
|||
{
|
||||
http_response_code($statusCode);
|
||||
header("Content-Type: application/json");
|
||||
|
||||
echo json_encode([$key => $message]);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -96,9 +93,11 @@ class ArtistImportHandler extends ApiHandler
|
|||
private function processArtist(object $artistData): bool
|
||||
{
|
||||
$artistName = $artistData->name ?? "";
|
||||
|
||||
if (!$artistName) throw new \Exception("Artist name is missing.");
|
||||
|
||||
$existingArtist = $this->getArtistByName($artistName);
|
||||
|
||||
if ($existingArtist) return true;
|
||||
|
||||
$artistKey = sanitizeMediaString($artistName);
|
||||
|
@ -106,7 +105,6 @@ class ArtistImportHandler extends ApiHandler
|
|||
$description = strip_tags($artistData->biography ?? "");
|
||||
$genre = $this->resolveGenreId($artistData->genres[0]->name ?? "");
|
||||
$starred = $artistData->starred ?? false;
|
||||
|
||||
$artistPayload = [
|
||||
"name_string" => $artistName,
|
||||
"slug" => $slug,
|
||||
|
@ -119,17 +117,18 @@ class ArtistImportHandler extends ApiHandler
|
|||
];
|
||||
|
||||
$this->makeRequest("POST", "artists", ["json" => $artistPayload]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function processAlbums(string $artistId, string $artistName): void
|
||||
{
|
||||
$artist = $this->getArtistByName($artistName);
|
||||
|
||||
if (!$artist) throw new \Exception("Artist not found after insert.");
|
||||
|
||||
$existingAlbums = $this->getExistingAlbums($artist["id"]);
|
||||
$existingAlbumKeys = array_column($existingAlbums, "key");
|
||||
|
||||
$navidromeAlbums = $this->fetchNavidromeAlbums($artistId);
|
||||
|
||||
foreach ($navidromeAlbums as $album) {
|
||||
|
@ -137,9 +136,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
$releaseYearRaw = $album["date"] ?? null;
|
||||
$releaseYear = null;
|
||||
|
||||
if ($releaseYearRaw && preg_match('/^\d{4}/', $releaseYearRaw, $matches)) {
|
||||
$releaseYear = (int)$matches[0];
|
||||
}
|
||||
if ($releaseYearRaw && preg_match('/^\d{4}/', $releaseYearRaw, $matches)) $releaseYear = (int)$matches[0];
|
||||
|
||||
$artistKey = sanitizeMediaString($artistName);
|
||||
$albumKey = "{$artistKey}-" . sanitizeMediaString($albumName);
|
||||
|
@ -170,6 +167,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
private function getArtistByName(string $nameString): ?array
|
||||
{
|
||||
$response = $this->fetchFromApi("artists", "name_string=eq." . urlencode($nameString));
|
||||
|
||||
return $response[0] ?? null;
|
||||
}
|
||||
|
||||
|
@ -181,6 +179,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
private function resolveGenreId(string $genreName): ?string
|
||||
{
|
||||
$genres = $this->fetchFromApi("genres", "name=eq." . urlencode(strtolower($genreName)));
|
||||
|
||||
return $genres[0]["id"] ?? null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue