remake the whole thing. still not finished

This commit is contained in:
creations 2025-04-03 10:06:43 -04:00
parent 12741ce4ba
commit 78c532808e
Signed by: creations
GPG key ID: 8F553AA4320FC711
8 changed files with 611 additions and 160 deletions

186
helpers/config.sh Normal file
View file

@ -0,0 +1,186 @@
#!/bin/bash
[[ ! -d "$CONFIG_DIR" ]] && mkdir -p "$CONFIG_DIR"
if [[ ! -f "$CONFIG_FILE" || ! -s "$CONFIG_FILE" ]]; then
echo "{}" > "$CONFIG_FILE"
NEEDS_SETUP=1
fi
validate_config() {
local is_valid=true
local temp_file=$(mktemp)
local keys
keys=$(jq -r 'keys[]' "$CONFIG_FILE")
for key in $keys; do
if [[ -z "${ALLOWED_KEYS[$key]}" ]]; then
jq "del(.\"$key\")" "$CONFIG_FILE" > "$temp_file" && mv "$temp_file" "$CONFIG_FILE"
else
local value
value=$(jq -r --arg key "$key" '.[$key]' "$CONFIG_FILE")
if ! [[ "$value" =~ ${ALLOWED_KEYS[$key]} ]]; then
jq "del(.\"$key\")" "$CONFIG_FILE" > "$temp_file" && mv "$temp_file" "$CONFIG_FILE"
fi
fi
done
for req_key in "${REQUIRED_KEYS[@]}"; do
if ! jq -e --arg key "$req_key" 'has($key)' "$CONFIG_FILE" >/dev/null; then
NEEDS_SETUP=1
fi
done
}
get_value() {
local key="$1"
jq -r ".${key} // empty" "$CONFIG_FILE"
}
set_value() {
local key="$1"
local value="$2"
if [[ -z "$key" || -z "$value" ]]; then
echo "Usage: $0 set <key> <value>"
exit 1
fi
if [[ -z "${ALLOWED_KEYS[$key]}" ]]; then
echo "Invalid key: $key"
exit 1
fi
if ! [[ "$value" =~ ${ALLOWED_KEYS[$key]} ]]; then
echo "Invalid value for $key: $value"
exit 1
fi
jq ". + {\"$key\": \"$value\"}" "$CONFIG_FILE" > temp.json && mv temp.json "$CONFIG_FILE"
}
remove_value() {
local key="$1"
jq "del(.${key})" "$CONFIG_FILE" > temp.json && mv temp.json "$CONFIG_FILE"
echo "Removed $key."
}
list_values() {
cat "$CONFIG_FILE" | jq .
}
setup_domain() {
local domain
local service
local auth
if [[ -z "$SERVICE" ]]; then
while true; do
echo -ne "${CYAN}Choose a service (${valid_services[*]}): ${RESET}"
read service
if [[ " ${valid_services[*]} " =~ " $service " ]]; then
break
else
echo -e "${RED}Invalid service. Please choose from: ${valid_services[*]}${RESET}"
fi
done
set_value "SERVICE" "$service"
else
service="$SERVICE"
fi
if [[ "$service" == "zipline" ]]; then
while true; do
echo -ne "${CYAN}Enter the domain (e.g. example.com): ${RESET}"
read domain
if [[ "$domain" =~ ^[a-zA-Z0-9.-]+$ ]]; then
break
else
echo -e "${RED}Invalid domain format. Please enter a valid domain (e.g. example.com).${RESET}"
fi
done
domain="https://$domain"
domain="${domain%/}"
[[ "$domain" != */api/upload ]] && domain="$domain/api/upload"
set_value "DOMAIN" "$domain"
echo -e "${GREEN}Domain set to: $domain${RESET}"
fi
while [[ -z "$auth" ]]; do
echo -ne "${CYAN}Enter your auth token: ${RESET}"
read auth
[[ -z "$auth" ]] && echo -e "${RED}Auth token cannot be empty. Please enter a valid token.${RESET}"
done
set_value "${service}_auth" "$auth"
echo -e "${GREEN}Auth token set successfully.${RESET}"
}
setup_config() {
local save_dir
local show_capture_preview
local show_notifications
local save_images
local default_option
echo -ne "${CYAN}What do you want the default option to be? (upload/save/copy): ${RESET}"
read default_option
while ! [[ "$default_option" =~ ^(upload|save|copy)$ ]]; do
echo -e "${RED}Invalid option. Please enter 'upload', 'save', or 'copy'.${RESET}"
echo -ne "${CYAN}Choose (upload/save/copy): ${RESET}"
read default_option
done
set_value "DEFAULT_OPTION" "$default_option"
[[ "$default_option" == "upload" ]] && setup_domain
echo -ne "${CYAN}Do you want to save images? (y/n): ${RESET}"
read save_images
while ! [[ "$save_images" =~ ^(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 save images? (y/n): ${RESET}"
read save_images
done
[[ "$save_images" =~ ^(y|Y)$ ]] && save_images="true" || save_images="false"
set_value "SAVE_IMAGES" "$save_images"
if [[ "$save_images" == "true" ]]; then
echo -ne "${CYAN}Enter the directory to save images (default: $HOME/Pictures): ${RESET}"
read save_dir
save_dir="${save_dir:-$HOME/Pictures}"
while [[ ! -d "$save_dir" ]]; do
echo -e "${RED}Directory does not exist. Please enter a valid directory.${RESET}"
echo -ne "${CYAN}Enter the directory to save images: ${RESET}"
read save_dir
done
set_value "SAVE_DIR" "$save_dir"
fi
echo -ne "${CYAN}Do you want to show capture notifications? (y/n): ${RESET}"
read show_notifications
while ! [[ "$show_notifications" =~ ^(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 show capture notifications? (y/n): ${RESET}"
read show_notifications
done
[[ "$show_notifications" =~ ^(y|Y)$ ]] && show_notifications="true" || show_notifications="false"
set_value "SHOW_NOTIFICATIONS" "$show_notifications"
echo -ne "${CYAN}Do you want to show capture preview? (y/n): ${RESET}"
read show_capture_preview
while ! [[ "$show_capture_preview" =~ ^(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 show capture preview? (y/n): ${RESET}"
read show_capture_preview
done
[[ "$show_capture_preview" =~ ^(y|Y)$ ]] && show_capture_preview="true" || show_capture_preview="false"
set_value "SHOW_CAPTURE_PREVIEW" "$show_capture_preview"
echo -e "${GREEN}${BOLD}Configuration completed successfully!${RESET}"
echo -e "${YELLOW}You can change the configuration later by running the script with the --config option.${RESET}"
[[ "$show_capture_preview" == "true" ]] && setup_venv
}

17
helpers/installer.sh Normal file
View file

@ -0,0 +1,17 @@
VENV_DIR="$SCRIPT_DIR/.venv"
setup_venv() {
if [[ ! -d "$VENV_DIR" ]]; then
python3 -m venv "$VENV_DIR" >/dev/null 2>&1
"$VENV_DIR/bin/pip" install --upgrade pip >/dev/null 2>&1
"$VENV_DIR/bin/pip" install pillow screeninfo >/dev/null 2>&1
PYTHON_EXEC="$VENV_DIR/bin/python3"
if [[ ! -f "$PYTHON_EXEC" ]]; then
echo -e "${RED}Python executable not found in virtual environment.${RESET}"
exit 1
fi
else
PYTHON_EXEC="$VENV_DIR/bin/python3"
fi
}

68
helpers/show_image.py Normal file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env python3
import tkinter as tk
from PIL import Image, ImageTk
import screeninfo, sys, os
def show_image(image_path, box_width=400, box_height=300, hover_header=None, click_url=None):
root = tk.Tk()
root.overrideredirect(True)
root.withdraw()
root.after(100, root.deiconify)
root.attributes("-topmost", True)
root.attributes("-alpha", 0.85)
img = Image.open(image_path)
img.thumbnail((box_width, box_height))
img_tk = ImageTk.PhotoImage(img)
monitors = screeninfo.get_monitors()
primary_screen = next((m for m in monitors if m.is_primary), monitors[0])
screen_x = primary_screen.x
screen_y = primary_screen.y
screen_width = primary_screen.width
screen_height = primary_screen.height
x_pos = screen_x + screen_width - box_width - 20
y_pos = screen_y + screen_height - box_height - 60
root.geometry(f"{box_width}x{box_height}+{x_pos}+{y_pos}")
frame = tk.Frame(root, bg="black")
frame.pack(fill="both", expand=True)
label = tk.Label(frame, image=img_tk, borderwidth=0)
label.image = img_tk
label.place(relx=0.5, rely=0.5, anchor="center")
header_label = tk.Label(root, text=hover_header, bg="black", fg="white", font=("Arial", 10))
def show_header(event):
if hover_header:
header_label.place(relx=0.5, rely=0, anchor="n", relwidth=1)
def hide_header(event):
if hover_header:
header_label.place_forget()
def close_window(event=None):
root.destroy()
root.bind("<Button-1>", close_window if click_url is None else lambda e: os.system(f"xdg-open {click_url}"))
root.bind("<Enter>", show_header)
root.bind("<Leave>", hide_header)
root.after(5000, close_window)
root.mainloop()
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: show_image.py <image_path> [hover_header] [click_url]")
sys.exit(1)
image_path = sys.argv[1]
hover_header = sys.argv[2] if len(sys.argv) > 2 else None
click_url = sys.argv[3] if len(sys.argv) > 3 else None
show_image(image_path, hover_header=hover_header, click_url=click_url)

62
helpers/variables.sh Normal file
View file

@ -0,0 +1,62 @@
GREEN="\e[32m"
YELLOW="\e[33m"
RED="\e[31m"
CYAN="\e[36m"
BOLD="\e[1m"
RESET="\e[0m"
CONFIG_DIR="$HOME/.config/grabIT"
CONFIG_FILE="$CONFIG_DIR/config.json"
NEEDS_SETUP=0
declare -A ALLOWED_KEYS=(
["log_level"]="^(DEBUG|INFO|WARN|ERROR)$"
["SHOW_CAPTURE_PREVIEW"]="^(true|false)$"
["SHOW_NOTIFICATIONS"]="^(true|false)$"
["SAVE_IMAGES"]="^(true|false)$"
["SAVE_DIR"]="^.+$"
["DOMAIN"]="^.+$"
["DEFAULT_OPTION"]="^(upload|save|copy)$"
["SERVICE"]="^(zipline|nest|fakecrime|ez|guns|pixelvault)$"
)
REQUIRED_KEYS=(
"SHOW_CAPTURE_PREVIEW"
"SHOW_NOTIFICATIONS"
"SAVE_IMAGES"
"DEFAULT_OPTION"
)
valid_services=("zipline" "nest" "fakecrime" "ez" "guns" "pixelvault")
valid_args=("--help" "--version" "--config" "-c" "-u" "-f" "-d" "--silent")
for service in "${valid_services[@]}"; do
valid_args+=("--$service")
ALLOWED_KEYS["${service}_auth"]="^.+$"
done
declare -A UPLOADERS=(
["pixelvault"]="https://pixelvault.co"
["guns"]="https://guns.lol/api/upload"
["ez"]="https://api.e-z.host/files"
["fakecrime"]="https://upload.fakecrime.bio"
["nest"]="https://nest.rip/api/files/upload"
)
declare -A UPLOAD_HEADERS=(
["pixelvault"]="https://pixelvault.co|Authorization"
["guns"]="key"
["ez"]="key"
["fakecrime"]="Authorization"
["nest"]="Authorization"
["zipline"]="authorization"
)
declare -A UPLOAD_JSON_KEYS=(
["pixelvault"]="resource"
["nest"]="fileURL"
["guns"]="link"
["ez"]="imageUrl"
["fakecrime"]="url"
["zipline"]="files[0].url"
)