Allow adding jellyfin/emby backends via API.

This commit is contained in:
Abdulmhsen B. A. A
2024-04-20 20:57:52 +03:00
parent 7149540c74
commit 1ca6c1bc48
8 changed files with 177 additions and 31 deletions

View File

@@ -44,10 +44,16 @@ final class Add
return api_error('No type was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
$type = strtolower($type);
if (null === ($name = $data->get('name'))) {
return api_error('No name was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
if (false === isValidName($name)) {
return api_error('Invalid name was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
$backend = $this->getBackends(name: $name);
if (!empty($backend)) {
@@ -56,10 +62,6 @@ final class Add
]), HTTP_STATUS::HTTP_CONFLICT);
}
if (false === isValidName($name)) {
return api_error('Invalid name was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
if (null === ($url = $data->get('url'))) {
return api_error('No url was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
}
@@ -73,9 +75,8 @@ final class Add
}
if (null === ($class = Config::get("supported.{$type}", null))) {
throw api_error(r("Unexpected client type '{type}' was given.", [
'type' => $type
]), HTTP_STATUS::HTTP_BAD_REQUEST);
return api_error(r("Unexpected client type '{type}' was given.", ['type' => $type]),
HTTP_STATUS::HTTP_BAD_REQUEST);
}
$instance = Container::getNew($class);