shareable upload tokens

This commit is contained in:
Q
2023-08-28 22:13:22 +03:00
parent 4629bf2976
commit 3b69ce7ae1
6 changed files with 145 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ _help() {
(w)rite Save to share, read from stdin/file/folder
(d)elete Delete an entry
show Show details on file
upload Get URL for uploads [no arguments]
upload_token Get URL for uploads ( -d expiry )
autocomplete Get Bash autocompletion script
update Update self
@@ -154,6 +154,27 @@ _maintain() {
"$MFL_ROOTURL"/maintenance
}
_upload_token() {
token=$( curl -fL -s \
-H "Expires-Days: $MAXDAYS" \
-H "Secret: $MFL_TOKEN" \
"$MFL_ROOTURL"/new_token )
cat <<EOF
curl -fL -g --upload-file "file_to_upload.ext" \\
-H "Name: name_to_store_as.ext" \\
-H "Max-Downloads: 10" \\
-H "Expires-Days: 10" \\
-H "Token: $token" \\
-H "Password: lock_with_password" \\
"$MFL_ROOTURL"/upload
curl -fL -g --upload-file "file_to_upload.ext" \\
-H "Name: name_to_store_as.ext" \\
-H "Token: $token" \\
"$MFL_ROOTURL"/upload
EOF
}
_msg() {
echo "$@" >&2
@@ -166,7 +187,7 @@ _get_completer() {
local curr_arg
curr_arg=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -W "help autocomplete list write delete show update" -- $curr_arg ) );
COMPREPLY=( $(compgen -W "help autocomplete list write delete show update upload_token" -- $curr_arg ) );
fi
if [[ $COMP_CWORD -eq 2 ]]; then
case ${COMP_WORDS[$(( $COMP_CWORD - 1 ))]} in
@@ -227,7 +248,7 @@ fi
[[ "$1" = "simplelist" ]] && { CMD=simple_list; ARG1=$CMD; }
[[ "$1" = "autocomplete" ]] && { _get_completer; }
[[ "$1" = "update" ]] && { _update_client; }
[[ "$1" = "upload" ]] && { _upload_url; }
[[ "$1" = "upload_token" ]] && { _upload_token; exit; }
[[ "$1" = "self" ]] && { _self_url; }
[[ "$1" = "h" || "$1" = "help" ]] && CMD=help