fix non images always show notifications, add override domain, fix headers
This commit is contained in:
parent
270d531d6e
commit
6040cb0142
3 changed files with 35 additions and 10 deletions
|
@ -123,6 +123,24 @@ setup_domain() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$change_options" =~ ^(y|Y)$ ]]; then
|
if [[ "$change_options" =~ ^(y|Y)$ ]]; then
|
||||||
|
while true; do
|
||||||
|
echo -ne "${CYAN}Enter override domain for accessing files (e.g. random.domain.com): ${RESET}"
|
||||||
|
read override_domain
|
||||||
|
|
||||||
|
if [[ -z "$override_domain" ]]; then
|
||||||
|
echo -e "${YELLOW}No override domain set.${RESET}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$override_domain" =~ ^[a-zA-Z0-9.-]+$ ]]; then
|
||||||
|
set_value "x-zipline-domain" "$override_domain"
|
||||||
|
echo -e "${GREEN}x-zipline-domain set to: $override_domain${RESET}"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}Invalid format. Must be like: domain.tld (no https, no trailing slash). Try again or press Enter to skip.${RESET}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo -ne "${CYAN}Enter the number of max views (default: 0): ${RESET}"
|
echo -ne "${CYAN}Enter the number of max views (default: 0): ${RESET}"
|
||||||
read max_views
|
read max_views
|
||||||
while [[ -n "$max_views" && ! "$max_views" =~ ^[0-9]+$ ]]; do
|
while [[ -n "$max_views" && ! "$max_views" =~ ^[0-9]+$ ]]; do
|
||||||
|
|
|
@ -25,6 +25,7 @@ declare -A ALLOWED_KEYS=(
|
||||||
["x-zipline-image-compression-percent"]="^.+$"
|
["x-zipline-image-compression-percent"]="^.+$"
|
||||||
["x-zipline-original-name"]="^.+$"
|
["x-zipline-original-name"]="^.+$"
|
||||||
["x-zipline-format"]="^.+$"
|
["x-zipline-format"]="^.+$"
|
||||||
|
["x-zipline-domain"]="^.+$"
|
||||||
)
|
)
|
||||||
|
|
||||||
REQUIRED_KEYS=(
|
REQUIRED_KEYS=(
|
||||||
|
|
26
main.sh
26
main.sh
|
@ -136,7 +136,10 @@ if [[ ${#MISSING_COMMANDS[@]} -gt 0 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
send_notification() {
|
send_notification() {
|
||||||
[[ "$SHOW_NOTIFICATIONS" == "false" ]] && return
|
local force="$4"
|
||||||
|
if [[ "$SHOW_NOTIFICATIONS" == "false" && "$force" != "true" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
local title="$1"
|
local title="$1"
|
||||||
local message="$2"
|
local message="$2"
|
||||||
|
@ -320,19 +323,16 @@ fi
|
||||||
|
|
||||||
HEADERS=()
|
HEADERS=()
|
||||||
if [[ "$SERVICE" == "zipline" ]]; then
|
if [[ "$SERVICE" == "zipline" ]]; then
|
||||||
declare -A ZIPLINE_HEADERS
|
mapfile -t zipline_keys < <(get_starting_with "x-zipline" | jq -r 'to_entries[] | "\(.key)=\(.value)"')
|
||||||
ZIPLINE_HEADERS=$(get_starting_with "x-zipline")
|
for entry in "${zipline_keys[@]}"; do
|
||||||
for key in "${!ZIPLINE_HEADERS[@]}"; do
|
key="${entry%%=*}"
|
||||||
header_name="${key#ZIPLINE__}" | tr '[:upper:]' '[:lower:]' | tr '_' '-'
|
value="${entry#*=}"
|
||||||
header_value="${ZIPLINE_HEADERS[$key]}"
|
headers+=("-H" "$key: $value")
|
||||||
headers+=("-H" "$header_name: $header_value")
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
headers+=("-H" "${UPLOAD_HEADERS[$SERVICE]}: $AUTH")
|
headers+=("-H" "${UPLOAD_HEADERS[$SERVICE]}: $AUTH")
|
||||||
|
|
||||||
echo headers "${headers[@]}"
|
|
||||||
|
|
||||||
FILE_URL=""
|
FILE_URL=""
|
||||||
RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/upload_response.json \
|
RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/upload_response.json \
|
||||||
-X POST -F "file=@$FILE" "${headers[@]}" "$DOMAIN")
|
-X POST -F "file=@$FILE" "${headers[@]}" "$DOMAIN")
|
||||||
|
@ -344,12 +344,14 @@ rm /tmp/upload_response.json
|
||||||
if [[ "$HTTP_CODE" -ne 200 ]]; then
|
if [[ "$HTTP_CODE" -ne 200 ]]; then
|
||||||
echo -e "${RED}Error: Upload failed with status code $HTTP_CODE.${RESET}"
|
echo -e "${RED}Error: Upload failed with status code $HTTP_CODE.${RESET}"
|
||||||
echo "$BODY"
|
echo "$BODY"
|
||||||
|
send_notification "Upload failed" "Status code: $HTTP_CODE" "" "true"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "$BODY" | jq . &>/dev/null; then
|
if ! echo "$BODY" | jq . &>/dev/null; then
|
||||||
echo -e "${RED}Error: Invalid JSON response from server.${RESET}"
|
echo -e "${RED}Error: Invalid JSON response from server.${RESET}"
|
||||||
echo "$BODY"
|
echo "$BODY"
|
||||||
|
send_notification "Upload failed" "Invalid JSON from $SERVICE" "" "true"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -357,6 +359,7 @@ FILE_URL=$(echo "$BODY" | jq -r ".${UPLOAD_JSON_KEYS[$SERVICE]}")
|
||||||
if [[ "$FILE_URL" == "null" || -z "$FILE_URL" ]]; then
|
if [[ "$FILE_URL" == "null" || -z "$FILE_URL" ]]; then
|
||||||
echo -e "${RED}Error: File URL not found in response.${RESET}"
|
echo -e "${RED}Error: File URL not found in response.${RESET}"
|
||||||
echo "$BODY"
|
echo "$BODY"
|
||||||
|
send_notification "Upload failed" "Missing file URL in response" "" "true"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -385,7 +388,10 @@ if [[ "$MIME_TYPE" == image/* ]]; then
|
||||||
else
|
else
|
||||||
if [[ "$SHOW_NOTIFICATIONS" == "true" ]]; then
|
if [[ "$SHOW_NOTIFICATIONS" == "true" ]]; then
|
||||||
send_notification "Uploaded to $SERVICE" "$FILE_URL"
|
send_notification "Uploaded to $SERVICE" "$FILE_URL"
|
||||||
play_sound
|
play_sound
|
||||||
|
else
|
||||||
|
send_notification "Uploaded to $SERVICE" "$FILE_URL" "" "true"
|
||||||
|
play_sound
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue