arr-init: fix bazarr API endpoint and update test

This commit is contained in:
2026-02-19 22:43:27 -05:00
parent 8ced6a530c
commit 1facd8a764
2 changed files with 80 additions and 13 deletions

View File

@@ -366,26 +366,28 @@ let
enabledInstances = lib.filterAttrs (_: inst: inst.enable) cfg;
mkBazarrProviderSection = type: provider: ''
mkBazarrProviderSection = type: provider:
let
ltype = lib.toLower type;
in ''
# ${type} provider
echo "Checking ${type} provider..."
PROVIDER_API_KEY=$(${grep} -oP '(?<=<ApiKey>)[^<]+' ${lib.escapeShellArg "${provider.dataDir}/config.xml"})
EXISTING=$(${curl} -sf "$BASE_URL/api/${lib.toLower type}" -H "X-API-KEY: $API_KEY")
if echo "$EXISTING" | ${jq} -e '. | length > 0' > /dev/null 2>&1; then
EXISTING=$(${curl} -sf "$BASE_URL/api/system/settings" -H "X-API-KEY: $API_KEY")
USE_FLAG=$(echo "$EXISTING" | ${jq} -r '.general.use_${ltype}')
EXISTING_KEY=$(echo "$EXISTING" | ${jq} -r '.${ltype}.apikey // ""')
if [ "$USE_FLAG" = "true" ] && [ -n "$EXISTING_KEY" ]; then
echo "${type} provider already configured, skipping"
else
echo "Adding ${type} provider..."
PAYLOAD=$(${jq} -n \
--arg ip "localhost" \
--argjson port ${builtins.toString provider.port} \
--arg apikey "$PROVIDER_API_KEY" \
--argjson ssl false \
--arg base_url "/" \
'{ip: $ip, port: $port, apikey: $apikey, ssl: $ssl, base_url: $base_url}')
${curl} -sf -X POST "$BASE_URL/api/${lib.toLower type}" \
${curl} -sf -X POST "$BASE_URL/api/system/settings" \
-H "X-API-KEY: $API_KEY" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
-d "settings-general-use_${ltype}=true" \
-d "settings-${ltype}-ip=localhost" \
-d "settings-${ltype}-port=${builtins.toString provider.port}" \
-d "settings-${ltype}-apikey=$PROVIDER_API_KEY" \
-d "settings-${ltype}-ssl=false" \
-d "settings-${ltype}-base_url=/"
echo "${type} provider added"
fi
'';