Skip to content

Commit

Permalink
fix: handle api issues properly
Browse files Browse the repository at this point in the history
  • Loading branch information
decipher3114 committed Nov 22, 2024
1 parent 38d034c commit 896b310
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
18 changes: 7 additions & 11 deletions modules/assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fetchAssetsInfo() {
if [ "$("${CURL[@]}" "https://api.github.com/rate_limit" | jq -r '.resources.core.remaining')" -gt 5 ]; then
notify info "Fetching Assets Info..."

source <("${CURL[@]}" "https://api.github.com/repos/ReVanced/revanced-cli/releases$ENDPOINT" | jq -r '
source <("${CURL[@]}" "https://api.github.com/repos/ReVanced/revanced-cli/releases" | jq -r '
if type == "array" then .[0] else . end |
"CLI_VERSION="+.tag_name,
(
Expand All @@ -26,22 +26,18 @@ fetchAssetsInfo() {

readarray -t SOURCE_INFO < <(jq -r --arg SOURCE "$SOURCE" '
.[] | select(.source == $SOURCE) |
.api |
.patches,
(.json // empty),
(.version // empty)
.repository,
(.api | .json, .version)
' "$SRC/sources.json"
)

if [ "${#SOURCE_INFO[@]}" -gt 2 ]; then
VERSION=$("${CURL[@]}" "${SOURCE_INFO[2]}" | jq -r '.version')
eval "PATCHES_API_URL=\"${SOURCE_INFO[0]}\""
if [ "${#SOURCE_INFO[@]}" -gt 2 ] && VERSION=$("${CURL[@]}" "${SOURCE_INFO[2]}" | jq -r '.version' 2> /dev/null); then
JSON_URL="${SOURCE_INFO[1]}"
PATCHES_API_URL="https://api.github.com/repos/${SOURCE_INFO[0]}/releases/tags/$VERSION"
else
PATCHES_API_URL="${SOURCE_INFO[0]}"
PATCHES_API_URL="https://api.github.com/repos/${SOURCE_INFO[0]}/releases/latest"
fi

JSON_URL="${SOURCE_INFO[1]}"

source <("${CURL[@]}" "$PATCHES_API_URL" | jq -r '
if type == "array" then .[0] else . end |
"PATCHES_VERSION="+.tag_name,
Expand Down
2 changes: 1 addition & 1 deletion modules/json/api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

parseJsonFromAPI() {

RESPONSE=$("${CURL[@]}" "$JSON_URL") || return 1
RESPONSE=$("${CURL[@]}" "$JSON_URL" | jq -c '.' 2> /dev/null) || return 1

AVAILABLE_PATCHES=$(jq -c '
reduce .[] as {
Expand Down
17 changes: 9 additions & 8 deletions modules/json/parse.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/bash

parsePatchesJson() {
if [ ! -e "$SOURCE-patches-$PATCHES_VERSION.json" ]; then
if [ "$JSON_URL" == "" ]; then
parseJsonFromCLI |
"${DIALOG[@]}" --gauge "Please Wait!!\nParsing JSON file for $SOURCE patches from CLI Output.\nThis might take some time." -1 -1 0
tput civis
else
while [ ! -e "$SOURCE-patches-$PATCHES_VERSION.json" ]; do
if [ "$JSON_URL" != "" ]; then
notify info "Please Wait!!\nParsing JSON file for $SOURCE patches from API."
if ! parseJsonFromAPI; then
return 1
unset JSON_URL
notify info "Unable to access API!!\nFalling back to CLI method..."
fi
continue
fi
parseJsonFromCLI |
"${DIALOG[@]}" --gauge "Please Wait!!\nParsing JSON file for $SOURCE patches from CLI Output.\nThis might take some time." -1 -1 0
tput civis
fetchAppsInfo || return 1
fi
done

if [ ! -e "$SOURCE-apps.json" ]; then
fetchAppsInfo || return 1
Expand Down
6 changes: 3 additions & 3 deletions sources.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"source": "ReVanced",
"repository": "ReVanced/revanced-patches",
"api": {
"version": "https://api.revanced.app/v4/patches/version",
"patches": "https://api.github.com/repos/ReVanced/revanced-patches/releases/tags/$VERSION",
"json": "https://api.revanced.app/v4/patches/list"
"json": "https://api.revanced.app/v4/patches/list",
"version": "https://api.revanced.app/v4/patches/version"
}
}
]

0 comments on commit 896b310

Please sign in to comment.