62 lines
1.4 KiB
Bash
62 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Define the domain
|
|
domain=https://paste.fascinated.cc
|
|
|
|
# Initialize an associative array to hold arguments and their values
|
|
declare -A args
|
|
|
|
# Default values for optional arguments
|
|
args["expires"]=""
|
|
|
|
# Function to handle arguments
|
|
parse_args() {
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
--expires) args["expires"]=$2; shift ;;
|
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
|
esac
|
|
shift
|
|
done
|
|
}
|
|
|
|
# Parse the command-line arguments
|
|
parse_args "$@"
|
|
|
|
# Read stdin if available
|
|
if [ -t 0 ]; then
|
|
echo "Nothing to upload. Please provide input data."
|
|
exit 1
|
|
fi
|
|
|
|
stdin=$(cat)
|
|
|
|
# Check if stdin is empty
|
|
if [[ -z "$stdin" ]]; then
|
|
echo "Nothing to upload. Please provide input data."
|
|
exit 1
|
|
fi
|
|
|
|
# Construct the upload URL with optional parameters
|
|
upload_url="$domain/api/upload"
|
|
if [[ -n "${args[expires]}" ]]; then
|
|
upload_url="$upload_url?expires=${args[expires]}"
|
|
fi
|
|
|
|
# Make the POST request and capture the response
|
|
response=$(curl -s -H "Accept: application/json" -X POST -d "$stdin" "$upload_url")
|
|
|
|
# Check for errors in the response
|
|
error_message=$(echo "$response" | jq -r '.error // .message // empty')
|
|
|
|
if [[ -n "$error_message" ]]; then
|
|
echo "Error: $error_message"
|
|
exit 1
|
|
fi
|
|
|
|
# Extract the JSON part from the response using jq
|
|
key=$(echo "$response" | jq -r '.key')
|
|
|
|
# Print the URL
|
|
echo "$domain/$key"
|