Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
19f6c5249a | |||
823a2847c8 | |||
6e2c506e72 | |||
3f094a2b47 | |||
cd5f695936 | |||
8aea6446bb | |||
fb38496fe9 | |||
df4e1d0370 | |||
b63ae67204 | |||
f103e564dc | |||
176b80fcf6 |
|
@ -18,6 +18,8 @@ Call ufw -h for help.
|
||||||
|
|
||||||
Dependencies: curl, jq
|
Dependencies: curl, jq
|
||||||
|
|
||||||
|
The config goes into `$XDG_CONFIG_DIR/ufw`.
|
||||||
|
|
||||||
ufwd
|
ufwd
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
# Put your actual secret here, this is just a random string
|
# Put your actual secret here, this is just a random string
|
||||||
secret = 'rooxoosh7Aese7phiPh3Choh3uthiTha'
|
secret='rooxoosh7Aese7phiPh3Choh3uthiTha'
|
||||||
|
|
||||||
# Override the default common curl behaviour:
|
# Override the default common curl behaviour:
|
||||||
#curl() { command curl -sL "$@"; }
|
#curl() { command curl -sL "$@"; }
|
||||||
|
|
||||||
|
#cfg_tmp_dir="$XDG_RUNTIME_DIR/ufw"
|
||||||
|
#cfg_service_url='https://8fw.me'
|
||||||
|
#cfg_max_filesize='200M' # Local limit, doesn't affect the server one :)
|
||||||
|
#flag_shortlink=0 # Display short links
|
||||||
|
#flag_directlink=1 # Display direct file links
|
||||||
|
|
58
ufw
58
ufw
|
@ -25,8 +25,6 @@ err() { printf '(error) %s\n' "$*" >&2; }
|
||||||
|
|
||||||
curl() { command curl -sL "$@"; }
|
curl() { command curl -sL "$@"; }
|
||||||
|
|
||||||
secret() { shift; secret=( "$@" ); }
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
_cat <<- EOF
|
_cat <<- EOF
|
||||||
Usage: ufw [-RsF] [-D num] [file/url]
|
Usage: ufw [-RsF] [-D num] [file/url]
|
||||||
|
@ -45,6 +43,7 @@ usage() {
|
||||||
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
|
-t|--tags "<tag1[, tag2,..]>" # Add tags to the file.
|
||||||
-q|--quiet # Be quiet.
|
-q|--quiet # Be quiet.
|
||||||
-v|--void # Don't add the file to my files.
|
-v|--void # Don't add the file to my files.
|
||||||
|
-c|--clipboard # Throw the result into the clipboard
|
||||||
|
|
||||||
Config options (~/.config/ufw):
|
Config options (~/.config/ufw):
|
||||||
secret # Your personal token. Get it at https://zfh.so/settings_form
|
secret # Your personal token. Get it at https://zfh.so/settings_form
|
||||||
|
@ -85,7 +84,10 @@ get_max_filesize() {
|
||||||
get_album_id() {
|
get_album_id() {
|
||||||
declare api_response api_status api_status_message
|
declare api_response api_status api_status_message
|
||||||
|
|
||||||
api_response=$( curl -f "$cfg_service_url/albumctl.json?m=new&name=$1&secret=$secret" )
|
api_response=$( curl --get \
|
||||||
|
--data-urlencode "name=$1" \
|
||||||
|
--data-urlencode "secret=$secret" \
|
||||||
|
"$cfg_service_url/albumctl.json?m=new" )
|
||||||
|
|
||||||
get_api_status <<< "$api_response"
|
get_api_status <<< "$api_response"
|
||||||
|
|
||||||
|
@ -142,7 +144,7 @@ upload() {
|
||||||
|
|
||||||
api_response=$( curl \
|
api_response=$( curl \
|
||||||
-F file="@$file" \
|
-F file="@$file" \
|
||||||
-F api_format='json' \
|
-F format='json' \
|
||||||
-F flag_private="$flag_private" \
|
-F flag_private="$flag_private" \
|
||||||
-F secret="$secret" \
|
-F secret="$secret" \
|
||||||
-F tags="$tags" \
|
-F tags="$tags" \
|
||||||
|
@ -172,6 +174,8 @@ upload() {
|
||||||
(( flag_directlink )) || file_link="${file_link#*.}"
|
(( flag_directlink )) || file_link="${file_link#*.}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$file_link"
|
||||||
|
|
||||||
printf '%s\n' "$file_link"
|
printf '%s\n' "$file_link"
|
||||||
|
|
||||||
if (( flag_rm )); then
|
if (( flag_rm )); then
|
||||||
|
@ -187,7 +191,10 @@ upload() {
|
||||||
get_shortlink() {
|
get_shortlink() {
|
||||||
declare url=$1 api_response api_status api_status_message
|
declare url=$1 api_response api_status api_status_message
|
||||||
|
|
||||||
api_response=$( curl "$cfg_service_url/shrink.json?url=${url}&secret=$secret" )
|
api_response=$( curl --data-urlencode "url=$url" \
|
||||||
|
--data-urlencode "secret=$secret" \
|
||||||
|
"$cfg_service_url/shrink.json" )
|
||||||
|
|
||||||
get_api_status <<< "$api_response"
|
get_api_status <<< "$api_response"
|
||||||
|
|
||||||
if (( api_status == 200 )); then
|
if (( api_status == 200 )); then
|
||||||
|
@ -195,6 +202,7 @@ get_shortlink() {
|
||||||
jq -r '.data.short_url' <<< "$api_response"
|
jq -r '.data.short_url' <<< "$api_response"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$short_url"
|
||||||
printf '%s\n' "$short_url"
|
printf '%s\n' "$short_url"
|
||||||
else
|
else
|
||||||
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
|
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
|
||||||
|
@ -235,6 +243,7 @@ get_my_ip() {
|
||||||
|
|
||||||
if (( api_status == 200 )); then
|
if (( api_status == 200 )); then
|
||||||
my_ip=$( jq -r '.data.ip' <<< "$api_response" )
|
my_ip=$( jq -r '.data.ip' <<< "$api_response" )
|
||||||
|
(( flag_clipboard )) && xclip "${xclip_args[@]}" <<< "$my_ip"
|
||||||
printf '%s\n' "$my_ip"
|
printf '%s\n' "$my_ip"
|
||||||
else
|
else
|
||||||
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
|
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
|
||||||
|
@ -292,7 +301,7 @@ set_argv() {
|
||||||
unset -v arg opt c
|
unset -v arg opt c
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
(--) argv+=( "$1" ); break;;
|
(--) argv+=( "$1" ); shift; break;;
|
||||||
|
|
||||||
(--*)
|
(--*)
|
||||||
IFS='=' read arg opt <<< "$1"
|
IFS='=' read arg opt <<< "$1"
|
||||||
|
@ -317,6 +326,10 @@ set_argv() {
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if (( $# )); then
|
||||||
|
argv+=( "$@" )
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
@ -344,7 +357,7 @@ main() {
|
||||||
if [[ -f "$cfg_file" ]]; then
|
if [[ -f "$cfg_file" ]]; then
|
||||||
if ! source "$cfg_file"; then
|
if ! source "$cfg_file"; then
|
||||||
printf 'Failed to source configuration file: %s\n' "$cfg_file"
|
printf 'Failed to source configuration file: %s\n' "$cfg_file"
|
||||||
return $?
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -355,6 +368,8 @@ main() {
|
||||||
: ${cfg_max_filesize:='200M'}
|
: ${cfg_max_filesize:='200M'}
|
||||||
: ${flag_shortlink:=0}
|
: ${flag_shortlink:=0}
|
||||||
: ${flag_directlink:=1}
|
: ${flag_directlink:=1}
|
||||||
|
: ${flag_clipboard:=0}
|
||||||
|
: ${xclip_selector:='clipboard'}
|
||||||
|
|
||||||
while [[ "$1" ]]; do
|
while [[ "$1" ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -377,6 +392,10 @@ main() {
|
||||||
(-q|--quiet) flag_quiet=1;;
|
(-q|--quiet) flag_quiet=1;;
|
||||||
(-v|--void) flag_void=1;;
|
(-v|--void) flag_void=1;;
|
||||||
|
|
||||||
|
# Clipboard
|
||||||
|
(-c|--clipboard) flag_clipboard=1;;
|
||||||
|
(-C|--xclip-selector) xclip_selector=$2; shift;;
|
||||||
|
|
||||||
(--notify) flag_notify=1;;
|
(--notify) flag_notify=1;;
|
||||||
(--no-notify|-n) flag_notify=0;;
|
(--no-notify|-n) flag_notify=0;;
|
||||||
|
|
||||||
|
@ -398,11 +417,19 @@ main() {
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*) break;;
|
*) args+=( "$1" );;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
xclip_args+=( -selection "$xclip_selector" )
|
||||||
|
|
||||||
|
# Catch the args after --
|
||||||
|
if (( $# )); then
|
||||||
|
args+=( "$@" )
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
TEMPDIR="$cfg_tmp_dir"
|
TEMPDIR="$cfg_tmp_dir"
|
||||||
|
|
||||||
for i in "$cfg_tmp_dir"; do
|
for i in "$cfg_tmp_dir"; do
|
||||||
|
@ -412,21 +439,18 @@ main() {
|
||||||
case "${action:-upload}" in
|
case "${action:-upload}" in
|
||||||
upload)
|
upload)
|
||||||
get_token || return $?
|
get_token || return $?
|
||||||
|
(( ${#args[@]} )) || return 1
|
||||||
|
|
||||||
if (( $# )); then
|
for t in "${args[@]}"; do
|
||||||
for t in "$@"; do
|
upload "$t"
|
||||||
upload "$t"
|
done
|
||||||
done
|
|
||||||
else
|
|
||||||
upload
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
url)
|
url)
|
||||||
get_token || return $?
|
get_token || return $?
|
||||||
|
|
||||||
for t in "$@"; do
|
for t in "${args[@]}"; do
|
||||||
get_shortlink "$1"
|
get_shortlink "$t"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
1
ufwd
1
ufwd
|
@ -14,6 +14,7 @@ usage() {
|
||||||
printf ' -h # Show this message.\n'
|
printf ' -h # Show this message.\n'
|
||||||
printf ' -n # Enable notifications with notify-send. Must be installed.\n'
|
printf ' -n # Enable notifications with notify-send. Must be installed.\n'
|
||||||
printf ' -d [path] # Set the dir that is to be watched.\n'
|
printf ' -d [path] # Set the dir that is to be watched.\n'
|
||||||
|
printf ' -s # Push the file url into the clipboard.\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user