From 020bb203276552e5f38467716afbe46e77ea165f Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Tue, 21 Aug 2018 14:56:56 +0300 Subject: [PATCH] direct url extract for flip --- code/app.py | 33 +++++++++++++++++---------------- code/templates/flip | 12 +++++++++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/code/app.py b/code/app.py index d6d04dd..3529d43 100644 --- a/code/app.py +++ b/code/app.py @@ -358,22 +358,23 @@ def file_delete(name, token, filename): return "OK", 200 -#~ @app.route('/file/direct///', methods=['GET']) -#~ def file_direct(name, token, filename): - #~ (ok,share) = get_share(name, token = token) - #~ if not ok: - #~ return share - #~ full_path = os.path.join( - #~ share['path'], - #~ secure_filename_hidden(filename) - #~ ) - #~ if not os.path.exists(full_path): - #~ return "-1", 403 - #~ allow_direct = get_or_none('direct_links', share) if get_or_none('pass_hash', share) else False - #~ if not allow_direct: - #~ return "-1", 403 - #~ token = get_direct_token(share, filename) - #~ return token, 200 +@app.route('/file/direct///', methods=['GET']) +def file_direct(name, token, filename): + (ok,share) = get_share(name, token = token) + if not ok: + return share + full_path = os.path.join( + share['path'], + secure_filename_hidden(filename) + ) + if not os.path.exists(full_path): + return "-1", 403 + allow_direct = get_or_none('direct_links', share) if get_or_none('pass_hash', share) else False + if not allow_direct: + return "-1", 403 + token = get_direct_token(share, filename) + url = url_for('download_direct', name = name, token = token, filename = filename ) + return app.config['PUBLIC_URL'] + url, 200 @app.route('/file/ls//', methods=['GET']) diff --git a/code/templates/flip b/code/templates/flip index c7fe8db..5484b27 100755 --- a/code/templates/flip +++ b/code/templates/flip @@ -8,10 +8,11 @@ _help() { Usage: $SELF [command] [name] [filename] Commands: + (l)ist [default] List names of clipboards (r)ead Display on screen / copies to file (w)rite Save from stdin / from file / folder (d)elete Delete an entry - (l)ist [default] List names of clipboards + url Get the direct share url Name: Any string for the clipboard name. default: 0 Filename: @@ -107,6 +108,10 @@ _delete() { # name curl -s "$FLEES_ROOTURL/file/delete/$FLEES_SHARE/$FLEES_TOKEN/$1" } +_url() { # name + curl -s "$FLEES_ROOTURL/file/direct/$FLEES_SHARE/$FLEES_TOKEN/$1" + echo '' +} _msg() { echo "$@" >&2 } @@ -145,6 +150,7 @@ 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" = "url" ]] && { CMD=url; ARG1=$CMD; } [[ "$1" = "update" ]] && { _update_client; } [[ "$1" = "h" || "$1" = "help" ]] && _help # if stdout redirected, default to read @@ -171,8 +177,8 @@ _get_file _write exit $? } -[[ "$CMD" = edit ]] && { - _edit +[[ "$CMD" = url ]] && { + _url "$NAME" exit $? }