Skip to content

Commit

Permalink
feat(url): Automatically select best mirror for Xiaomi URLs
Browse files Browse the repository at this point in the history
Co-authored-by: Jyotiraditya Panda <[email protected]>
  • Loading branch information
AntoninoScordino and imjyotiraditya committed Sep 27, 2024
1 parent e3eb12f commit d1d4eea
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extract_and_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ else
terminate 1
}

# If the device contains a link from Xiaomi's CDN, replace it (when applicable)
# with the fastest one
if [[ "${URL}" == *"d.miui.com"* ]] && [ ! "$(echo "${URL}" | grep -q cdnorg)" ] && [ ! "$(echo "${URL}" | grep -q bkt-sgp-miui-ota-update-alisgp)" ]; then
# Set '${URL_ORIGINAL}' in case we might need to roll back
URL_ORIGINAL=${URL%/*}
FILE_PATH=${URL#*d.miui.com/}

# Array of different possible mirrors
MIRRORS=(
"https://cdnorg.d.miui.com"
"https://bkt-sgp-miui-ota-update-alisgp.oss-ap-southeast-1.aliyuncs.com"
"${URL_ORIGINAL}"
)

for URLS in "${MIRRORS[@]}"; do
URL=${URLS}/${FILE_PATH}
if [ $(curl -s -o /dev/null -w "%{http_code}" "${URL}") == "404" ]; then
echo "[ERROR] ${URLS} is down. Trying with other mirror(s)..."
else
echo "[INFO] Found best available mirror."
break
fi
done
fi

# Properly check for different hosting websties.
case ${URL} in
*drive.google.com*)
Expand Down

0 comments on commit d1d4eea

Please sign in to comment.