1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2024-12-28 21:32:36 +01:00

Split response into two variables

This commit is contained in:
aclist 2022-08-12 09:52:07 +09:00
parent b664fb70d0
commit c8c0bfbce4
2 changed files with 13 additions and 10 deletions

View file

@ -4,6 +4,10 @@
- Clean up logging - Clean up logging
- Custom query API - Custom query API
## [2.4.2-rc.2] 2022-08-10
### Fixed
- Pass correct query ports to modlist function
## [2.4.2-rc.1] 2022-08-10 ## [2.4.2-rc.1] 2022-08-10
### Fixed ### Fixed
- Page though API results to list >10 servers - Page though API results to list >10 servers

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -o pipefail set -o pipefail
version=2.4.2-rc.1 version=2.4.2-rc.2
aid=221100 aid=221100
game="dayz" game="dayz"
workshop="steam://url/CommunityFilePage/" workshop="steam://url/CommunityFilePage/"
@ -80,9 +80,6 @@ items=(
"View changelog" "View changelog"
) )
} }
cleanup(){
rm $tmp
}
warn_and_exit(){ warn_and_exit(){
zenity --info --title="DZGUI" --text="$1" --icon-name="dialog-warning" 2>/dev/null zenity --info --title="DZGUI" --text="$1" --icon-name="dialog-warning" 2>/dev/null
printf "[DZGUI] %s\n" "$check_config_msg" printf "[DZGUI] %s\n" "$check_config_msg"
@ -97,6 +94,7 @@ info(){
set_api_params(){ set_api_params(){
response=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "sort=-players" \ response=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "sort=-players" \
-d "filter[game]=$game" -d "filter[ids][whitelist]=$list_of_ids") -d "filter[game]=$game" -d "filter[ids][whitelist]=$list_of_ids")
list_response=$response
} }
query_api(){ query_api(){
#TODO: prevent drawing list if null values returned without API error #TODO: prevent drawing list if null values returned without API error
@ -377,7 +375,7 @@ connect(){
#TODO: sanitize/validate input #TODO: sanitize/validate input
readarray -t qport_arr <<< "$qport_list" readarray -t qport_arr <<< "$qport_list"
if [[ -z ${qport_arr[@]} ]]; then if [[ -z ${qport_arr[@]} ]]; then
err "Failed to process favorite server" err "Failed to obtain query ports"
return return
fi fi
ip=$(echo "$1" | awk -F"$separator" '{print $1}') ip=$(echo "$1" | awk -F"$separator" '{print $1}')
@ -700,15 +698,15 @@ main_menu(){
done done
} }
page_through(){ page_through(){
response=$(curl -s "$page") list_response=$(curl -s "$page")
list=$(echo "$response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"') list=$(echo "$list_response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
idarr+=("$list") idarr+=("$list")
parse_json parse_json
} }
parse_json(){ parse_json(){
page=$(echo "$response" | jq -r '.links.next?') page=$(echo "$list_response" | jq -r '.links.next?')
if [[ "$page" != "null" ]]; then if [[ "$page" != "null" ]]; then
list=$(echo "$response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"') list=$(echo "$list_response" | jq -r '.data[] .attributes | "\(.name)\t\(.ip):\(.port)\t\(.players)/\(.maxPlayers)\t\(.details.time)\t\(.status)\t\(.id)"')
idarr+=("$list") idarr+=("$list")
page_through page_through
else else
@ -763,6 +761,7 @@ create_array(){
} }
set_fav(){ set_fav(){
#TODO: test API key here and return errors #TODO: test API key here and return errors
echo "[DZGUI] Querying favorite server"
query_api query_api
fav_label=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "filter[game]=$game" -d "filter[ids][whitelist]=$fav" \ fav_label=$(curl -s "$api" -H "Authorization: Bearer "$api_key"" -G -d "filter[game]=$game" -d "filter[ids][whitelist]=$fav" \
| jq -r '.data[] .attributes .name') | jq -r '.data[] .attributes .name')
@ -956,4 +955,4 @@ main(){
} }
main main
trap cleanup EXIT #trap cleanup EXIT