mirror of
https://github.com/hyzendust/command_upload.git
synced 2026-02-15 02:21:16 +01:00
Add: the -C flag to check URLs is now async. Multiple URLs in parallel.
This commit is contained in:
136
upload.sh
136
upload.sh
@@ -7,6 +7,7 @@ UPLOAD_URL="https://upload.freedoms4.top"
|
|||||||
HISTORY_FILE="$HOME/.uploaded_files.txt"
|
HISTORY_FILE="$HOME/.uploaded_files.txt"
|
||||||
COPY_TO_CLIPBOARD=false
|
COPY_TO_CLIPBOARD=false
|
||||||
USE_COLOR=true
|
USE_COLOR=true
|
||||||
|
MAX_JOBS=10
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
print_usage() {
|
print_usage() {
|
||||||
@@ -46,58 +47,97 @@ set_colors() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# HISTORY
|
# ASYNC URL CHECK with bracket/space/parenthesis encoding
|
||||||
check_url_alive() {
|
check_url() {
|
||||||
local url="$1"
|
local timestamp="$1"
|
||||||
# Encode only spaces, brackets, and parentheses; leave existing % encodings as they are
|
local filename="$2"
|
||||||
local encoded="${url// /%20}"
|
local url="$3"
|
||||||
encoded="${encoded//[/\%5B}"
|
|
||||||
encoded="${encoded//]/%5D}"
|
|
||||||
encoded="${encoded//\(/%28}"
|
|
||||||
encoded="${encoded//\)/%29}"
|
|
||||||
local status
|
|
||||||
status=$(curl -s -o /dev/null -w "%{http_code}" -L "$encoded")
|
|
||||||
[[ "$status" == "200" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
show_active() {
|
# Encode spaces, brackets, parentheses
|
||||||
[[ ! -f "$HISTORY_FILE" ]] && { echo "No history found."; return; }
|
url="${url// /%20}"
|
||||||
echo -e "${BOLD}Active uploads:${RESET}"
|
url="${url//[/\%5B}"
|
||||||
while IFS='|' read -r timestamp filename url; do
|
url="${url//]/%5D}"
|
||||||
url="$(echo "$url" | xargs)"
|
url="${url//\(/%28}"
|
||||||
if check_url_alive "$url"; then
|
url="${url//\)/%29}"
|
||||||
echo -e "${GREEN}${timestamp} | ${filename} | ${url}${RESET}"
|
|
||||||
fi
|
|
||||||
done < "$HISTORY_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
show_expired() {
|
status=$(curl -s -o /dev/null -w "%{http_code}" -L "$url" || echo 0)
|
||||||
[[ ! -f "$HISTORY_FILE" ]] && { echo "No history found."; return; }
|
if [[ "$status" == "200" ]]; then
|
||||||
echo -e "${BOLD}Expired uploads:${RESET}"
|
echo "ACTIVE|$timestamp|$filename|$url"
|
||||||
while IFS='|' read -r timestamp filename url; do
|
else
|
||||||
url="$(echo "$url" | xargs)"
|
echo "EXPIRED|$timestamp|$filename|$url"
|
||||||
if ! check_url_alive "$url"; then
|
fi
|
||||||
echo -e "${RED}${timestamp} | ${filename} | ${url}${RESET}"
|
|
||||||
fi
|
|
||||||
done < "$HISTORY_FILE"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
show_all() {
|
|
||||||
show_active
|
|
||||||
echo
|
|
||||||
show_expired
|
|
||||||
}
|
|
||||||
|
|
||||||
show_active_only() { show_active; }
|
|
||||||
show_expired_only() { show_expired; }
|
|
||||||
|
|
||||||
show_recent() {
|
show_recent() {
|
||||||
[[ ! -f "$HISTORY_FILE" ]] && { echo "No history found."; return; }
|
[[ ! -f "$HISTORY_FILE" ]] && { echo "No history found."; return; }
|
||||||
echo -e "${BOLD}Recent uploads:${RESET}"
|
echo -e "${BOLD}Recent uploads:${RESET}"
|
||||||
cat "$HISTORY_FILE"
|
cat "$HISTORY_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ARG
|
show_async() {
|
||||||
|
[[ ! -f "$HISTORY_FILE" ]] && { echo "No history found."; return; }
|
||||||
|
|
||||||
|
active_urls=()
|
||||||
|
expired_urls=()
|
||||||
|
pids=()
|
||||||
|
tmp_output=$(mktemp)
|
||||||
|
trap 'rm -f "$tmp_output"' EXIT
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
timestamp=$(echo "$line" | cut -d'|' -f1 | xargs)
|
||||||
|
filename=$(echo "$line" | cut -d'|' -f2 | xargs)
|
||||||
|
url=$(echo "$line" | cut -d'|' -f3 | xargs)
|
||||||
|
|
||||||
|
{
|
||||||
|
check_url "$timestamp" "$filename" "$url"
|
||||||
|
} >> "$tmp_output" &
|
||||||
|
|
||||||
|
pids+=($!)
|
||||||
|
while (( ${#pids[@]} >= MAX_JOBS )); do
|
||||||
|
for i in "${!pids[@]}"; do
|
||||||
|
if ! kill -0 "${pids[i]}" 2>/dev/null; then
|
||||||
|
wait "${pids[i]}"
|
||||||
|
unset 'pids[i]'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
sleep 0.05
|
||||||
|
done
|
||||||
|
done < "$HISTORY_FILE"
|
||||||
|
|
||||||
|
wait
|
||||||
|
|
||||||
|
# Read tmp_output and separate
|
||||||
|
while IFS= read -r line; do
|
||||||
|
status=$(echo "$line" | cut -d'|' -f1)
|
||||||
|
content=$(echo "$line" | cut -d'|' -f2-)
|
||||||
|
if [[ "$status" == "ACTIVE" ]]; then
|
||||||
|
active_urls+=("$content")
|
||||||
|
else
|
||||||
|
expired_urls+=("$content")
|
||||||
|
fi
|
||||||
|
done < "$tmp_output"
|
||||||
|
|
||||||
|
# Sort arrays by timestamp (first field)
|
||||||
|
IFS=$'\n' active_urls=($(printf "%s\n" "${active_urls[@]}" | sort))
|
||||||
|
IFS=$'\n' expired_urls=($(printf "%s\n" "${expired_urls[@]}" | sort))
|
||||||
|
|
||||||
|
# Print in groups with colors
|
||||||
|
if [[ "$CHECK_ACTIVE" == true ]] || [[ "$CHECK_ACTIVE" == false && "$CHECK_EXPIRED" == false ]]; then
|
||||||
|
echo -e "${BOLD}Active uploads:${RESET}"
|
||||||
|
for line in "${active_urls[@]}"; do
|
||||||
|
echo -e "${GREEN}${line}${RESET}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CHECK_EXPIRED" == true ]] || [[ "$CHECK_ACTIVE" == false && "$CHECK_EXPIRED" == false ]]; then
|
||||||
|
echo -e "${BOLD}Expired uploads:${RESET}"
|
||||||
|
for line in "${expired_urls[@]}"; do
|
||||||
|
echo -e "${RED}${line}${RESET}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ARGUMENTS
|
||||||
USER_AUTH=""
|
USER_AUTH=""
|
||||||
declare -a HEADERS
|
declare -a HEADERS
|
||||||
declare -a FIELDS
|
declare -a FIELDS
|
||||||
@@ -134,22 +174,14 @@ done
|
|||||||
|
|
||||||
set_colors
|
set_colors
|
||||||
|
|
||||||
# RECENT/CHECK FLAGS
|
# RECENT / CHECK FLAGS
|
||||||
if $SHOW_RECENT; then
|
if $SHOW_RECENT; then
|
||||||
show_recent
|
show_recent
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $CHECK; then
|
if $CHECK; then
|
||||||
if $CHECK_ACTIVE && $CHECK_EXPIRED; then
|
show_async
|
||||||
show_all
|
|
||||||
elif $CHECK_ACTIVE; then
|
|
||||||
show_active_only
|
|
||||||
elif $CHECK_EXPIRED; then
|
|
||||||
show_expired_only
|
|
||||||
else
|
|
||||||
show_all
|
|
||||||
fi
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user