update all components
This commit is contained in:
@@ -1,93 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# ── 0. Load Environment Variables from .env ─────────────────────────────
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DOTENV_PATH="${SCRIPT_DIR}/.env"
|
||||
|
||||
if [ -f "$DOTENV_PATH" ]; then
|
||||
set -o allexport
|
||||
source "$DOTENV_PATH"
|
||||
set +o allexport
|
||||
fi
|
||||
|
||||
# Environment variables from .env
|
||||
F0CKM_URL="${F0CKM_URL}"
|
||||
API_KEY="${API_KEY}"
|
||||
RATING="${RATING}" # sfw, nsfw, or nsfl
|
||||
TAGS="${TAGS}" # Comma-separated tags
|
||||
VISIBILITY="${VISIBILITY}" # 0 = public, 1 = unlisted, 2 = private
|
||||
|
||||
# Notification app header title & preview dimensions
|
||||
APP_NAME="${APP_NAME:-f0ckm}"
|
||||
PREVIEW_HEIGHT="${PREVIEW_HEIGHT:-80}" # Center crop height in pixels (e.g. 80)
|
||||
|
||||
# ── 1. Clipboard Helper Function (Wayland / X11) ───────────────────────────
|
||||
copy_to_clipboard() {
|
||||
local content="$1"
|
||||
if command -v wl-copy &>/dev/null; then
|
||||
echo -n "$content" | wl-copy
|
||||
elif command -v xclip &>/dev/null; then
|
||||
echo -n "$content" | xclip -selection clipboard
|
||||
elif command -v xsel &>/dev/null; then
|
||||
echo -n "$content" | xsel -b
|
||||
else
|
||||
echo "Warning: No clipboard utility found (wl-clipboard or xclip)."
|
||||
fi
|
||||
}
|
||||
|
||||
# ── 1. Create Output Directory & Timestamped File Path ───────────────────
|
||||
SCREENSHOT_DIR="${HOME}/Pictures/Screenshots"
|
||||
mkdir -p "$SCREENSHOT_DIR"
|
||||
|
||||
SAVE_PATH="${SCREENSHOT_DIR}/screenshot_$(date +%Y%m%d_%H%M%S).png"
|
||||
|
||||
# ── 2. Capture Region Screenshot with Spectacle ──────────────────────────
|
||||
spectacle -r -b -n -o "$SAVE_PATH"
|
||||
|
||||
# ── 3. Upload File & Process Response ────────────────────────────────────
|
||||
if [ -f "$SAVE_PATH" ]; then
|
||||
echo "Uploading '$SAVE_PATH' to ${F0CKM_URL}/api/v2/upload..."
|
||||
|
||||
RESPONSE=$(curl -s -X POST "${F0CKM_URL}/api/v2/upload" \
|
||||
-H "X-Api-Key: ${API_KEY}" \
|
||||
-F "file=@${SAVE_PATH}" \
|
||||
-F "rating=${RATING}" \
|
||||
-F "tags=${TAGS}" \
|
||||
-F "visibility=${VISIBILITY}")
|
||||
|
||||
# Parse response JSON
|
||||
SUCCESS=$(echo "$RESPONSE" | jq -r '.success // false')
|
||||
ITEM_URL=$(echo "$RESPONSE" | jq -r '.url // empty')
|
||||
MSG=$(echo "$RESPONSE" | jq -r '.msg // "Upload failed"')
|
||||
|
||||
if [ "$SUCCESS" = "true" ] && [ -n "$ITEM_URL" ]; then
|
||||
# Copy URL to clipboard
|
||||
copy_to_clipboard "$ITEM_URL"
|
||||
|
||||
# Create center-cropped preview banner (exact 80px height)
|
||||
PREVIEW_THUMB="/tmp/f0ckm_preview.png"
|
||||
if command -v magick &>/dev/null; then
|
||||
magick "$SAVE_PATH" -gravity center -crop "x${PREVIEW_HEIGHT}+0+0" +repage "$PREVIEW_THUMB"
|
||||
else
|
||||
PREVIEW_THUMB="$SAVE_PATH"
|
||||
fi
|
||||
|
||||
# HTML body with fixed height preview banner (no scrolling), and link on a new line
|
||||
BODY_TEXT="<div><a href=\"${ITEM_URL}\"><img src=\"file://${PREVIEW_THUMB}\" height=\"${PREVIEW_HEIGHT}\" style=\"height:${PREVIEW_HEIGHT}px; max-width:100%; object-fit:cover;\" /></a></div><br/><br/><a href=\"${ITEM_URL}\">${ITEM_URL}</a>"
|
||||
|
||||
# Send Notification
|
||||
notify-send \
|
||||
-a "${APP_NAME}" \
|
||||
"" \
|
||||
"${BODY_TEXT}"
|
||||
|
||||
echo "Success! $ITEM_URL"
|
||||
else
|
||||
# Show error notification
|
||||
notify-send -a "${APP_NAME}" -u critical "Upload Failed" "$MSG"
|
||||
echo "Upload failed: $RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Screenshot capture canceled."
|
||||
fi
|
||||
# Pass execution directly to the Python GUI engine
|
||||
exec kde-uploader-gui --spectacle "$@"
|
||||
|
||||
Reference in New Issue
Block a user