flip copy/paste a file

This commit is contained in:
ville rantanen
2019-10-24 21:10:15 +03:00
parent 18ecc3668e
commit 3195c87840
2 changed files with 52 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ from revprox import ReverseProxied
from utils import *
__FLEES_VERSION__ = "20191020.0"
__FLEES_VERSION__ = "20191024.0"
app = Flask(__name__)
app.config.from_object(__name__)
config_values = read_config(app)

View File

@@ -12,6 +12,8 @@ _help() {
(r)ead Read from clipboard, write to stdout or file
(w)rite Save to clipboard, read from stdin/file/folder
(d)elete Delete an entry
(c)opy Copy file/folder
(p)aste Paste file/folder (will overwrite)
url Get the direct share url
upload Get URL for uploads [no arguments]
update Update flip client [no arguments]
@@ -71,6 +73,32 @@ _simple_list() {
printf "\n"
}
_copy() {
# stdin is open
[ -t 0 ] || stream_in=1
# no file mentioned, use the name as file
[[ -z "$FILE" ]] && {
FILE="$NAME"
}
NAME=file.tar
[[ -e "$FILE" ]] && {
# Input file exists, dont use stream
stream_in=0
}
[[ $stream_in -ne 1 ]] && [[ -z "$FILE" ]] && {
_msg File to read needed, or use stdin
exit 1
}
_msg "Writing $NAME"
[[ "$stream_in" -eq 1 ]] && {
_write_stdin "$NAME"
return $?
}
_write_folder "$NAME" "$FILE"
}
_write() {
# stdin is open
[ -t 0 ] || stream_in=1
@@ -116,6 +144,17 @@ _write_stdin() { # name
cat - | curl -L -F "file=@-;filename=$1" "${FLEES_ROOTURL}upload/${FLEES_SHARE}/${FLEES_TOKEN}"
}
_paste() {
[[ "$NAME" = "-" ]] && stream_out=1
[[ -d "$NAME" ]] && cd "$NAME"
[ -t 1 ] || stream_out=1
[[ "$stream_out" -eq 1 ]] && {
_read_stdout "file.tar"
return
}
_read_stdout "file.tar" | tar xv
}
_read() {
[[ "$FILE" = "-" ]] && stream_out=1
[ -t 1 ] || stream_out=1
@@ -197,7 +236,7 @@ _get_completer() {
local curr_arg
curr_arg=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -W "help autocomplete list read write delete url update upload self" -- $curr_arg ) );
COMPREPLY=( $(compgen -W "help autocomplete list copy paste read write delete url update upload self" -- $curr_arg ) );
fi
if [[ $COMP_CWORD -eq 2 ]]; then
case ${COMP_WORDS[$(( $COMP_CWORD - 1 ))]} in
@@ -205,7 +244,7 @@ if [[ $COMP_CWORD -eq 2 ]]; then
local remotelist=$( eval FLIP_EXEC simplelist )
COMPREPLY=( $(compgen -W "$remotelist" -- $curr_arg ) );
;;
w*)
w*|c*|p*)
COMPREPLY=( $(compgen -f -d -- $curr_arg ) );
;;
esac
@@ -239,6 +278,8 @@ CMD=list
[[ "$1" = "w" || "$1" = "write" ]] && { CMD=write; ARG1=$CMD; }
[[ "$1" = "d" || "$1" = "delete" || "$1" = "del" ]] && { CMD=delete; ARG1=$CMD; }
[[ "$1" = "l" || "$1" = "list" ]] && { CMD=list; ARG1=$CMD; }
[[ "$1" = "c" || "$1" = "copy" ]] && { CMD=copy; ARG1=$CMD; }
[[ "$1" = "p" || "$1" = "paste" ]] && { CMD=paste; ARG1=$CMD; }
[[ "$1" = "simplelist" ]] && { CMD=simple_list; ARG1=$CMD; }
[[ "$1" = "autocomplete" ]] && { _get_completer; }
[[ "$1" = "url" ]] && { CMD=url; ARG1=$CMD; }
@@ -263,6 +304,10 @@ _get_file
_read
exit $?
}
[[ "$CMD" = copy ]] && {
_copy
exit $?
}
[[ "$CMD" = delete ]] && {
_delete "$NAME"
exit $?
@@ -271,6 +316,10 @@ _get_file
_write
exit $?
}
[[ "$CMD" = paste ]] && {
_paste
exit $?
}
[[ "$CMD" = url ]] && {
_url "$NAME"
exit $?