update for kde and non wlroot, add more options for zipline, fix upload errors

This commit is contained in:
creations 2025-04-03 18:41:57 -04:00
parent 78c532808e
commit 8378f5b1d6
Signed by: creations
GPG key ID: 8F553AA4320FC711
3 changed files with 147 additions and 28 deletions

View file

@ -37,6 +37,11 @@ get_value() {
jq -r ".${key} // empty" "$CONFIG_FILE" jq -r ".${key} // empty" "$CONFIG_FILE"
} }
get_starting_with() {
local prefix="$1"
jq -r "to_entries | map(select(.key | startswith(\"$prefix\"))) | from_entries" "$CONFIG_FILE"
}
set_value() { set_value() {
local key="$1" local key="$1"
local value="$2" local value="$2"
@ -107,6 +112,76 @@ setup_domain() {
set_value "DOMAIN" "$domain" set_value "DOMAIN" "$domain"
echo -e "${GREEN}Domain set to: $domain${RESET}" echo -e "${GREEN}Domain set to: $domain${RESET}"
# extra options for zipline
echo -ne "${CYAN}Do you want to change upload options? (y/n): ${RESET}"
read change_options
while ! [[ "$change_options" =~ ^(y|Y|n|N|true|false)$ ]]; do
echo -e "${RED}Invalid option. Please enter 'y' or 'n'.${RESET}"
echo -ne "${CYAN}Do you want to change upload options? (y/n): ${RESET}"
read change_options
done
if [[ "$change_options" =~ ^(y|Y)$ ]]; then
echo -ne "${CYAN}Enter the number of max views (default: 0): ${RESET}"
read max_views
while [[ -n "$max_views" && ! "$max_views" =~ ^[0-9]+$ ]]; do
echo -e "${RED}Invalid number. Please enter a valid number.${RESET}"
echo -ne "${CYAN}Enter the number of views (default: 0): ${RESET}"
read max_views
done
if [[ -n "$max_views" && "$max_views" -ne 0 ]]; then
set_value "x-zipline-max-views" "$max_views"
echo -e "${GREEN}Max views set to: $max_views${RESET}"
else
echo -e "${YELLOW}Using default max views (0). Not saving.${RESET}"
fi
echo -ne "${CYAN}Enter the image compression percent (default: 0): ${RESET}"
read compression_percent
while [[ -n "$compression_percent" && ! "$compression_percent" =~ ^[0-9]+$ ]]; do
echo -e "${RED}Invalid number. Please enter a valid number.${RESET}"
echo -ne "${CYAN}Enter the image compression percent (default: 0): ${RESET}"
read compression_percent
done
if [[ -n "$compression_percent" && "$compression_percent" -ne 0 ]]; then
set_value "x-zipline-image-compression-percent" "$compression_percent"
echo -e "${GREEN}Image compression percent set to: $compression_percent${RESET}"
else
echo -e "${YELLOW}Using default compression percent (0). Not saving.${RESET}"
fi
echo -ne "${CYAN}Do you want to keep the original name on download? (y/n): ${RESET}"
read keep_original_name
while [[ -n "$keep_original_name" && ! "$keep_original_name" =~ ^(y|Y|n|N|true|false)$ ]]; do
echo -e "${RED}Invalid option. Please enter 'y' or 'n'.${RESET}"
echo -ne "${CYAN}Do you want to keep the original name on download? (y/n): ${RESET}"
read keep_original_name
done
if [[ "$keep_original_name" =~ ^(y|Y)$ ]]; then
keep_original_name="true"
else
keep_original_name="false"
fi
set_value "x-zipline-original-name" "$keep_original_name"
echo -e "${GREEN}Keep original name set to: $keep_original_name${RESET}"
echo -ne "${CYAN}What do you want the name format to be? (default: date): ${RESET}"
read name_format
while [[ -n "$name_format" && ! "$name_format" =~ ^(date|random|uuid|name|gfycat)$ ]]; do
echo -e "${RED}Invalid option. Please enter 'date', 'random', 'uuid', 'name', or 'gfycat'.${RESET}"
echo -ne "${CYAN}What do you want the name format to be? (default: date): ${RESET}"
read name_format
done
if [[ -n "$name_format" ]]; then
set_value "x-zipline-format" "$name_format"
echo -e "${GREEN}Name format set to: $name_format${RESET}"
else
echo -e "${YELLOW}Using default name format (date). Not saving.${RESET}"
fi
echo -e "${GREEN}Upload options set successfully.${RESET}"
fi
fi fi
while [[ -z "$auth" ]]; do while [[ -z "$auth" ]]; do

View file

@ -18,6 +18,12 @@ declare -A ALLOWED_KEYS=(
["DOMAIN"]="^.+$" ["DOMAIN"]="^.+$"
["DEFAULT_OPTION"]="^(upload|save|copy)$" ["DEFAULT_OPTION"]="^(upload|save|copy)$"
["SERVICE"]="^(zipline|nest|fakecrime|ez|guns|pixelvault)$" ["SERVICE"]="^(zipline|nest|fakecrime|ez|guns|pixelvault)$"
# zipline specific
["x-zipline-max-views"]="^.+$"
["x-zipline-image-compression-percent"]="^.+$"
["x-zipline-original-name"]="^.+$"
["x-zipline-format"]="^.+$"
) )
REQUIRED_KEYS=( REQUIRED_KEYS=(

84
main.sh
View file

@ -87,8 +87,6 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
REQUIRED_COMMANDS=("notify-send" "curl" "jq")
SHOULD_UPLOAD=$(get_value "DEFAULT_OPTION") SHOULD_UPLOAD=$(get_value "DEFAULT_OPTION")
[[ "$SHOULD_UPLOAD" == "upload" ]] && SHOULD_UPLOAD=true || SHOULD_UPLOAD=false [[ "$SHOULD_UPLOAD" == "upload" ]] && SHOULD_UPLOAD=true || SHOULD_UPLOAD=false
@ -98,10 +96,17 @@ SHOW_NOTIFICATIONS=$(get_value "SHOW_NOTIFICATIONS")
SHOW_CAPTURE_PREVIEW=$(get_value "SHOW_CAPTURE_PREVIEW") SHOW_CAPTURE_PREVIEW=$(get_value "SHOW_CAPTURE_PREVIEW")
[[ "$SHOW_CAPTURE_PREVIEW" == "true" ]] && SHOW_CAPTURE_PREVIEW=true || SHOW_CAPTURE_PREVIEW=false [[ "$SHOW_CAPTURE_PREVIEW" == "true" ]] && SHOW_CAPTURE_PREVIEW=true || SHOW_CAPTURE_PREVIEW=false
REQUIRED_COMMANDS=("notify-send" "curl" "jq")
if [[ -n "$WAYLAND_DISPLAY" ]]; then if [[ -n "$WAYLAND_DISPLAY" ]]; then
if [[ "$XDG_CURRENT_DESKTOP" == "KDE" ]]; then
SCREENSHOT_CMD=("spectacle" "-rbn" "-o")
REQUIRED_COMMANDS+=("xclip" "spectacle")
else
SCREENSHOT_CMD=("grim" "-g") SCREENSHOT_CMD=("grim" "-g")
SELECT_REGION="slurp" SELECT_REGION="slurp"
REQUIRED_COMMANDS+=("wl-copy" "grim" "slurp") REQUIRED_COMMANDS+=("wl-copy" "grim" "slurp")
fi
elif [[ -n "$DISPLAY" ]]; then elif [[ -n "$DISPLAY" ]]; then
SCREENSHOT_CMD=("flameshot" "gui" "-p") SCREENSHOT_CMD=("flameshot" "gui" "-p")
REQUIRED_COMMANDS+=("xclip" "flameshot") REQUIRED_COMMANDS+=("xclip" "flameshot")
@ -183,7 +188,11 @@ if [[ "$SHOULD_COPY" == "true" ]]; then
fi fi
if [[ -n "$WAYLAND_DISPLAY" ]]; then if [[ -n "$WAYLAND_DISPLAY" ]]; then
if [[ "$XDG_CURRENT_DESKTOP" == "KDE" && -n "$WAYLAND_DISPLAY" ]]; then
"${SCREENSHOT_CMD[@]}" "$FILE"
else
"${SCREENSHOT_CMD[@]}" "$("$SELECT_REGION")" "$FILE" "${SCREENSHOT_CMD[@]}" "$("$SELECT_REGION")" "$FILE"
fi
else else
"${SCREENSHOT_CMD[@]}" "$FILE" "${SCREENSHOT_CMD[@]}" "$FILE"
fi fi
@ -272,7 +281,11 @@ if [[ -z "$USER_FILE" ]]; then
fi fi
if [[ -n "$WAYLAND_DISPLAY" ]]; then if [[ -n "$WAYLAND_DISPLAY" ]]; then
if [[ "$XDG_CURRENT_DESKTOP" == "KDE" && -n "$WAYLAND_DISPLAY" ]]; then
"${SCREENSHOT_CMD[@]}" "$FILE"
else
"${SCREENSHOT_CMD[@]}" "$("$SELECT_REGION")" "$FILE" "${SCREENSHOT_CMD[@]}" "$("$SELECT_REGION")" "$FILE"
fi
else else
"${SCREENSHOT_CMD[@]}" "$FILE" "${SCREENSHOT_CMD[@]}" "$FILE"
fi fi
@ -286,10 +299,6 @@ if [[ -z "$USER_FILE" ]]; then
echo "Error: File not found: $FILE" >&2 echo "Error: File not found: $FILE" >&2
exit 1 exit 1
fi fi
if [[ "$SHOULD_SAVE" != "true" ]]; then
[[ -n "$FILE" ]] && rm -f "$FILE"
fi
else else
FILE="$USER_FILE" FILE="$USER_FILE"
fi fi
@ -299,21 +308,56 @@ if [[ ! -f "$FILE" ]]; then
exit 1 exit 1
fi fi
HEADERS=()
if [[ "$SERVICE" == "zipline" ]]; then
declare -A ZIPLINE_HEADERS
ZIPLINE_HEADERS=$(get_starting_with "x-zipline")
for key in "${!ZIPLINE_HEADERS[@]}"; do
header_name="${key#ZIPLINE__}" | tr '[:upper:]' '[:lower:]' | tr '_' '-'
header_value="${ZIPLINE_HEADERS[$key]}"
headers+=("-H" "$header_name: $header_value")
done
fi
headers+=("-H" "${UPLOAD_HEADERS[$SERVICE]}: $AUTH")
echo headers "${headers[@]}"
FILE_URL="" FILE_URL=""
RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/upload_response.json \
-X POST -F "file=@$FILE" "${headers[@]}" "$DOMAIN")
REPONSE=$(curl -s -X POST \ HTTP_CODE="${RESPONSE:(-3)}"
-F "file=@$FILE" \ BODY=$(cat /tmp/upload_response.json)
-H "${UPLOAD_HEADERS[$SERVICE]}: $AUTH" \ rm /tmp/upload_response.json
"$DOMAIN")
if ! echo "$REPONSE" | jq . &>/dev/null; then if [[ "$HTTP_CODE" -ne 200 ]]; then
echo -e "${RED}Error: Invalid response from server.${RESET}" echo -e "${RED}Error: Upload failed with status code $HTTP_CODE.${RESET}"
echo "$BODY"
exit 1 exit 1
fi fi
FILE_URL=$(echo "$REPONSE" | jq -r ".${UPLOAD_JSON_KEYS[$SERVICE]}")
if [[ "$FILE_URL" == "null" ]]; then if ! echo "$BODY" | jq . &>/dev/null; then
echo -e "${RED}Error: Invalid JSON response from server.${RESET}"
echo "$BODY"
exit 1
fi
FILE_URL=$(echo "$BODY" | jq -r ".${UPLOAD_JSON_KEYS[$SERVICE]}")
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"
exit 1
fi
if [[ -n "$WAYLAND_DISPLAY" ]]; then
echo "Using wl-copy for clipboard."
echo "$FILE_URL" | wl-copy
elif [[ -n "$DISPLAY" ]]; then
echo "Using xclip for clipboard."
echo "$FILE_URL" | xclip -selection clipboard
else
echo "Error: Unable to detect display server (Wayland/X11)."
exit 1 exit 1
fi fi
@ -332,13 +376,7 @@ else
fi fi
fi fi
if [[ -n "$WAYLAND_DISPLAY" ]]; then # delete if should not save and not a user file
echo "Using wl-copy for clipboard." if [[ "$SHOULD_SAVE" != "true" && "$USER_FILE" == "" ]]; then
echo "$FILE_URL" | wl-copy rm -f "$FILE"
elif [[ -n "$DISPLAY" ]]; then
echo "Using xclip for clipboard."
echo "$FILE_URL" | xclip -selection clipboard
else
echo "Error: Unable to detect display server (Wayland/X11)."
exit 1
fi fi