Avoid creating json if upload fails

This commit is contained in:
2024-08-12 10:13:52 +10:00
parent d04602332f
commit 74f4787cc5

View File

@@ -18,8 +18,10 @@ if test -f "$media_path"; then
echo "Could not find $media_path.json, uploading media!"
id=$(wp media import "$media_path" --porcelain $WP_FLAGS)
url=$(wp rest attachment get "$id" --field=source_url $WP_FLAGS | sed 's/127.0.0.1/streetspeoplelove.org/')
jq -n --arg id $id --arg url "$url" '{"id": $id, "url": $url}' > "$media_path.json"
cat "$media_path.json"
if [ $? -eq 0 ]; then
jq -n --arg id $id --arg url "$url" '{"id": $id, "url": $url}' > "$media_path.json"
cat "$media_path.json"
fi
fi
else
echo "Could not find $media_path"