Mass initial commit
This commit is contained in:
parent
b4d5146fdc
commit
4e4048561f
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
from flask import Flask, render_template, send_file, request
|
||||
|
||||
|
@ -61,6 +63,57 @@ def index(path):
|
|||
return send_file(internal_path)
|
||||
|
||||
|
||||
@app.route('/mass_download')
|
||||
def mass_download():
|
||||
internal_base = config.get('base_path')
|
||||
|
||||
base = request.args.get('base', '')
|
||||
files = request.args.getlist('file')
|
||||
|
||||
# Checks ###################################################
|
||||
|
||||
if base == '':
|
||||
return {"error": "Base path not supplied"}, 400
|
||||
|
||||
if '..' in base or base[0] != '/':
|
||||
return {"error": "Invalid base path"}, 400
|
||||
|
||||
# TODO: If it's 1 file and it's not a directory, then redirect to the file
|
||||
if len(files) < 1:
|
||||
return {"error": "A minimum of two files is required"}, 400
|
||||
|
||||
# TODO: Check if the files exist
|
||||
# TODO: Check if the files are bigger than a certain amount?
|
||||
|
||||
# Actual serving ###########################################
|
||||
|
||||
for i_file in files:
|
||||
internal_path = os.path.join(internal_base, base[1:], i_file)
|
||||
|
||||
# FIXME: I'm broke
|
||||
if os.path.isdir(internal_path):
|
||||
for root, _, subfiles in os.walk(internal_path):
|
||||
for i_subfile in subfiles:
|
||||
external_root = root[len(internal_base) + 1:]
|
||||
print(external_root)
|
||||
files.append(os.path.join(root, external_root))
|
||||
print(files)
|
||||
|
||||
with zipfile.ZipFile('/tmp/download.zip', 'w') as f_zip:
|
||||
for i_file in files:
|
||||
internal_path = os.path.join(internal_base, base[1:], i_file)
|
||||
|
||||
# print(internal_path)
|
||||
|
||||
if not os.path.exists(internal_path):
|
||||
# And what is this?¿
|
||||
return {'error': f'The following path does not exist: "{i_file}"'}, 400
|
||||
|
||||
f_zip.write(internal_path)
|
||||
|
||||
return [base, files], 200
|
||||
|
||||
|
||||
@app.route('/search')
|
||||
def search():
|
||||
q = request.args.get('q', '')
|
||||
|
|
|
@ -15,7 +15,13 @@
|
|||
<br /><br />
|
||||
{% endif %}
|
||||
|
||||
<form action="/mass_download" method="GET" id="mass_form">
|
||||
<input type="submit" value="Download" />
|
||||
<input type="hidden" name="base" value="{{ path }}" >
|
||||
</form>
|
||||
|
||||
{% for dir in dirs %}
|
||||
<input type="checkbox" name="file" value="{{ dir }}" form="mass_form"/>
|
||||
<a href="{{ path_join(path, dir) }}">{{ dir }}</a><br />
|
||||
{% endfor %}
|
||||
|
||||
|
@ -26,6 +32,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% for file in files %}
|
||||
<input type="checkbox" name="file" value="{{ file }}" form="mass_form"/>
|
||||
<a href="{{ path_join(path, file) }}">{{ file }}</a><br />
|
||||
{% endfor %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue