init f0ckm-uploader
This commit is contained in:
75
uploader.sh
Executable file
75
uploader.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==========================================
|
||||
# Notification Wrapper
|
||||
# ==========================================
|
||||
show_notification() {
|
||||
local title="$1"
|
||||
local message="$2"
|
||||
local icon="${3:-cloud-upload-symbolic}"
|
||||
if command -v kdialog &> /dev/null; then
|
||||
kdialog --passivepopup "$message" 5 --title "$title" --icon "$icon"
|
||||
else
|
||||
echo "$title: $message"
|
||||
fi
|
||||
}
|
||||
|
||||
# ==========================================
|
||||
# Configuration
|
||||
# ==========================================
|
||||
API_URL="http://<f0ckm>/api/v2/upload"
|
||||
API_KEY=""
|
||||
|
||||
# ==========================================
|
||||
|
||||
FILE="$1"
|
||||
|
||||
if [ -z "$FILE" ]; then
|
||||
show_notification "Upload Failed" "No file provided to uploader." "dialog-error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine clipboard command (Wayland or X11)
|
||||
if command -v wl-copy &> /dev/null; then
|
||||
COPY_CMD="wl-copy"
|
||||
elif command -v xclip &> /dev/null; then
|
||||
COPY_CMD="xclip -selection clipboard"
|
||||
else
|
||||
show_notification "Upload Error" "Please install wl-clipboard (Wayland) or xclip (X11)." "dialog-error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
show_notification "Uploading..." "Uploading $(basename "$FILE")" "cloud-upload-symbolic"
|
||||
|
||||
# Detect the real MIME type so curl doesn't fall back to application/octet-stream
|
||||
MIME_TYPE=$(file --mime-type -b "$FILE")
|
||||
|
||||
# Perform the upload
|
||||
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$API_URL" \
|
||||
-H "X-Api-Key: $API_KEY" \
|
||||
-F "file=@$FILE;type=$MIME_TYPE" \
|
||||
-F "rating=" \
|
||||
-F "tags=" \
|
||||
-F "is_oc=0")
|
||||
|
||||
# Extract the HTTP status code (last line) and the body
|
||||
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
|
||||
BODY=$(echo "$RESPONSE" | sed '$d')
|
||||
|
||||
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
|
||||
# Parse the URL from the JSON response.
|
||||
# This assumes a response like {"url": "https://..."}
|
||||
# You might need to adjust the regex or use jq depending on your API structure.
|
||||
URL=$(echo "$BODY" | grep -oP '"url"\s*:\s*"\K[^"]+')
|
||||
|
||||
# Fallback: if no URL field is found, just copy the whole body if it's a raw string
|
||||
if [ -z "$URL" ]; then
|
||||
URL="$BODY"
|
||||
fi
|
||||
|
||||
echo -n "$URL" | $COPY_CMD
|
||||
show_notification "Upload Successful" "Link copied to clipboard!<br><br><a href=\"$URL\">$URL</a>" "cloud-upload-symbolic"
|
||||
else
|
||||
show_notification "Upload Failed" "HTTP Error $HTTP_CODE\n$BODY" "dialog-error"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user