commit 76efd1a938e3bed54956b86d995d3cc7b43da910 Author: Kibi Kelburton Date: Sat Jun 13 15:58:47 2026 +0200 init f0ckm-uploader diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd5af8b --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +# f0ckm-uploader + +A KDE Plasma integration for uploading files directly to a f0ckm instance via the API. Adds an **"Upload to f0ckm"** action to Dolphin's right-click context menu and Spectacle's export/share menu. + +## Features + +- **Dolphin integration** — right-click any file and upload it via the Actions/Service Menu +- **Spectacle integration** — export screenshots directly from the share menu +- **Clipboard support** — the resulting URL is automatically copied to your clipboard +- **Wayland & X11** — uses `wl-copy` or `xclip` depending on the session +- **KDE notifications** — upload progress and results via `kdialog` passive popups +- **Accurate MIME detection** — uses `file --mime-type` to avoid API rejections + +## Requirements + +| Dependency | Purpose | +| -------------------------- | --------------------------- | +| `bash` | Script runtime | +| `curl` | HTTP uploads | +| `kdialog` | Desktop notifications (KDE) | +| `wl-clipboard` (`wl-copy`) | Clipboard on Wayland | +| `xclip` | Clipboard on X11 | +| `file` (libmagic) | MIME type detection | + +## Configuration + +Before installing, edit `uploader.sh` and set your API endpoint and key: + +```bash +API_URL="http:///api/v2/upload" +API_KEY="your_api_key_here" +``` + +## Installation + +```bash +git clone https://git.lat/kibi/f0ckm-uploader +cd f0ckm-uploader +# Edit uploader.sh — set API_URL and API_KEY +chmod +x install.sh +./install.sh +``` + +The installer will: + +1. Copy `uploader.sh` → `~/.local/bin/kde-uploader` +2. Install the `.desktop` application entry for Spectacle → `~/.local/share/applications/` +3. Install the KDE Service Menu for Dolphin → `~/.local/share/kio/servicemenus/` (and the legacy KF5 path) + +> [!NOTE] +> You may need to restart Dolphin or log out/in for the service menu entry to appear. + +## Uninstallation + +```bash +./uninstall.sh +``` + +## Usage + +### Dolphin + +Right-click any file → **Actions** → **Upload to f0ckm** + +### Spectacle + +After capturing a screenshot → **Export** or **Share** → **Upload to f0ckm** + +A notification will confirm the upload and the link will be in your clipboard. + +## File Structure + +``` +f0ckm-uploader/ +├── uploader.sh # Main upload script +├── kde-uploader.desktop # Application entry (Spectacle) +├── kde-uploader-servicemenu.desktop # Dolphin right-click action +├── install.sh # Installer +└── uninstall.sh # Uninstaller +``` + +## License + +MIT diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..791f805 --- /dev/null +++ b/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Configuration directories +INSTALL_DIR="$HOME/.local/bin" +APP_DIR="$HOME/.local/share/applications" +SERVICE_MENU_DIR="$HOME/.local/share/kio/servicemenus" +LEGACY_SERVICE_MENU_DIR="$HOME/.local/share/kservices5/ServiceMenus" + +# Create necessary directories +mkdir -p "$INSTALL_DIR" "$APP_DIR" "$SERVICE_MENU_DIR" "$LEGACY_SERVICE_MENU_DIR" + +# 1. Install the script +cp uploader.sh "$INSTALL_DIR/kde-uploader" +chmod +x "$INSTALL_DIR/kde-uploader" + +# 2. Install standard application entry (for Spectacle) +sed "s|__EXEC_PATH__|$INSTALL_DIR/kde-uploader|g" kde-uploader.desktop > "$APP_DIR/kde-uploader.desktop" +chmod +x "$APP_DIR/kde-uploader.desktop" +update-desktop-database "$APP_DIR" &> /dev/null + +# 3. Install KDE Service Menu entry (for Dolphin) +sed "s|__EXEC_PATH__|$INSTALL_DIR/kde-uploader|g" kde-uploader-servicemenu.desktop > "$SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" +chmod +x "$SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" +sed "s|__EXEC_PATH__|$INSTALL_DIR/kde-uploader|g" kde-uploader-servicemenu.desktop > "$LEGACY_SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" +chmod +x "$LEGACY_SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" + +echo "Installation complete!" +echo "The script has been installed to $INSTALL_DIR/kde-uploader" +echo "You can now right click files in Dolphin and find 'Upload to Custom API' in the Actions menu." +echo "In Spectacle, you should find 'Upload to Custom API' in the Export or Share menu." diff --git a/kde-uploader-servicemenu.desktop b/kde-uploader-servicemenu.desktop new file mode 100644 index 0000000..c6b935b --- /dev/null +++ b/kde-uploader-servicemenu.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Service +ServiceTypes=KonqPopupMenu/Plugin +MimeType=all/allfiles;image/png;image/jpeg;image/gif;image/webp;image/bmp;image/tiff;image/avif; +Actions=upload_custom_api; +X-KDE-Priority=TopLevel +X-KDE-Submenu=Upload + +[Desktop Action upload_custom_api] +Name=Upload to f0ckm +Icon=cloud-upload-symbolic +Exec=__EXEC_PATH__ "%u" diff --git a/kde-uploader.desktop b/kde-uploader.desktop new file mode 100644 index 0000000..c4816b1 --- /dev/null +++ b/kde-uploader.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Type=Application +Name=f0ckm Uploader +Comment=Upload to f0ckm +Exec=__EXEC_PATH__ %F +Icon=network-server +Terminal=false +Categories=Utility;Network; +MimeType=image/png;image/jpeg;image/gif;image/webp;image/bmp;image/tiff;image/avif;image/heic;video/mp4;video/webm;audio/mpeg;audio/ogg; +NoDisplay=false + +[Desktop Action upload] +Name=Upload to Custom API +Exec=__EXEC_PATH__ %F +Icon=network-server diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..2ce48c8 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Configuration directories +INSTALL_DIR="$HOME/.local/bin" +APP_DIR="$HOME/.local/share/applications" +SERVICE_MENU_DIR="$HOME/.local/share/kio/servicemenus" +LEGACY_SERVICE_MENU_DIR="$HOME/.local/share/kservices5/ServiceMenus" + +# 1. Remove the executable script +if [ -f "$INSTALL_DIR/kde-uploader" ]; then + rm "$INSTALL_DIR/kde-uploader" + echo "Removed executable from $INSTALL_DIR" +fi + +# 2. Remove the standard application entry +if [ -f "$APP_DIR/kde-uploader.desktop" ]; then + rm "$APP_DIR/kde-uploader.desktop" + echo "Removed application entry from $APP_DIR" +fi +update-desktop-database "$APP_DIR" &> /dev/null + +# 3. Remove the modern KDE Service Menu entry +if [ -f "$SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" ]; then + rm "$SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" + echo "Removed service menu entry from $SERVICE_MENU_DIR" +fi + +# 4. Remove the legacy KDE Service Menu entry +if [ -f "$LEGACY_SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" ]; then + rm "$LEGACY_SERVICE_MENU_DIR/kde-uploader-servicemenu.desktop" + echo "Removed legacy service menu entry from $LEGACY_SERVICE_MENU_DIR" +fi + +echo "Uninstallation complete! The custom upload options and script have been removed." diff --git a/uploader.sh b/uploader.sh new file mode 100755 index 0000000..a781938 --- /dev/null +++ b/uploader.sh @@ -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:///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!

$URL" "cloud-upload-symbolic" +else + show_notification "Upload Failed" "HTTP Error $HTTP_CODE\n$BODY" "dialog-error" + exit 1 +fi