Make backend uuid optional if we are adding via API, after context validation it's easy to get the id.
This commit is contained in:
@@ -68,6 +68,10 @@ final class Add
|
||||
return api_error('Invalid url was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (null === ($token = $data->get('token'))) {
|
||||
return api_error('No access token was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (null === ($class = Config::get("supported.{$type}", null))) {
|
||||
throw api_error(r("Unexpected client type '{type}' was given.", [
|
||||
'type' => $type
|
||||
@@ -86,7 +90,7 @@ final class Add
|
||||
backendUrl: new Uri($config->get('url')),
|
||||
cache: Container::get(BackendCache::class),
|
||||
backendId: $config->get('uuid', null),
|
||||
backendToken: $config->get('token'),
|
||||
backendToken: $token,
|
||||
backendUser: $config->get('user', null),
|
||||
options: $config->get('options', []),
|
||||
);
|
||||
@@ -95,6 +99,10 @@ final class Add
|
||||
return api_error('Context information validation failed.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (!$config->get('uuid')) {
|
||||
$config = $config->with('uuid', $instance->withContext($context)->getIdentifier());
|
||||
}
|
||||
|
||||
if (!$config->has('webhook.token')) {
|
||||
$config = $config->with('webhook.token', bin2hex(random_bytes(Config::get('webhook.tokenLength'))));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ final readonly class PlexValidateContext
|
||||
throw new InvalidContextException('Failed to get backend id.');
|
||||
}
|
||||
|
||||
if ($backendId !== $context->backendId) {
|
||||
if (null !== $context->backendId && $backendId !== $context->backendId) {
|
||||
throw new InvalidContextException(
|
||||
r("Backend id mismatch. Expected '{expected}', server responded with '{actual}'.", [
|
||||
'expected' => $context->backendId,
|
||||
|
||||
Reference in New Issue
Block a user