From cd76452779270804a39547ff613fd2a1682a79d0 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Fri, 2 Mar 2018 15:37:37 +0200 Subject: [PATCH] new route to list files in a share. TODO: use for split upload to check existing splits --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ code/app.py | 17 +++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/README.md b/README.md index 10b5e18..f1dee74 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,43 @@ Operation is one of download, direct_download, zip_download, or upload direct links. You can have many tokens for single share. - Direct download token is (password hash + filename) hashed + +# Routes + +- @app.route("/") + Display the list of public shares, or the ones logged in to +- @app.route('/authenticate/', methods=['GET','POST']) + Query the password for the share +- @app.route('/upload//', methods=['POST']) + Upload a file from command line +- @app.route('/upload', methods=['POST']) + Upload file from the browser +- @app.route('/upload_join//', methods=['POST']) + Commence joining of a splitted upload file +- @app.route('/files//', methods=['GET']) + Return plain text list of files in the share +- @app.route('/list//', methods=['GET']) + Login to a share with a token +- @app.route('/list/', methods=['GET']) + List share contents for the browser +- @app.route('/logout/', methods=['GET']) + Logout from share. Only for browser. +- @app.route('/direct///', methods=['GET']) + Download a file using the filename token (if direct download enabled) +- @app.route('/download///', methods=['GET']) + Download a file using the share token +- @app.route('/download//', methods=['GET']) + Download a file with a browser +- @app.route('/zip//', methods=['GET']) + Download the whole share as a zip file using share token +- @app.route('/zip/', methods=['GET']) + Download the whole share as a zip file using browser +- @app.route('/script/upload//', methods=['GET']) + Get a bash script that uploads multiple files. Folders are uploaded as .tar.gz +- @app.route('/script/download//', methods=['GET']) + Get a bash script that downloads all the files in a share. +- @app.route('/script/direct//', methods=['GET']) + Get a bash script that downloads all the files in a share using direct filename tokens. +- @app.route('/script/upload_split//', methods=['GET']) + Get a bash script that uploads multiple files and folders. The script splits files + to smaller chunks, to prevent timeouts. Folders are uploaded as .tar diff --git a/code/app.py b/code/app.py index 64ca719..4689bea 100644 --- a/code/app.py +++ b/code/app.py @@ -8,6 +8,7 @@ from flask import Flask, render_template, jsonify, current_app, Response, \ redirect, url_for, request, g, session, send_file, send_from_directory from werkzeug.utils import secure_filename import zipfile +import urllib from multiprocessing import Process from revprox import ReverseProxied from utils.utils import * @@ -169,6 +170,22 @@ def send(name): return share return render_template('send.html',name=name) +@app.route('/files//', methods=['GET']) +def list_files(name, token): + (ok,share) = get_share(name, token = token) + if not ok: + return share + files = [] + for file in sorted(os.listdir(share['path'])): + fp = os.path.join(share['path'],file) + if os.path.isdir(fp): + continue + if file.startswith("."): + continue + files.append(urllib.parse.quote_plus(file)) + files.append("") + return "\n".join(files), 200 + @app.route('/list//', methods=['GET']) @app.route('/list/', methods=['GET']) def list_view(name, token = None):