downloaders respect folders

This commit is contained in:
Ville Rantanen
2018-03-10 16:09:14 +02:00
parent 00008c9c7d
commit 4d43fc1a5b
2 changed files with 20 additions and 31 deletions

View File

@@ -195,12 +195,9 @@ def list_view(name, token = None):
files = [] files = []
for file in iter_folder_files(share['path']): for file in iter_folder_files(share['path']):
fp = os.path.join(share['path'],file) status = file_stat(share['path'],file)
status = file_stat(fp)
status.update({ status.update({
'token': get_direct_token(share, file), 'token': get_direct_token(share, file),
'name': file,
'url': path2url(file)
}) })
files.append(status) files.append(status)
# direct share links not allowed if password isnt set # direct share links not allowed if password isnt set
@@ -346,16 +343,8 @@ def script_download(name = None, token = None):
if not ok: if not ok:
return share return share
files = [] files = []
for file in sorted(os.listdir(share['path'])): for file in iter_folder_files(share['path']):
fp = os.path.join(share['path'],file) status = file_stat(share['path'], file)
if os.path.isdir(fp):
continue
if file.startswith("."):
continue
status = file_stat(fp)
status.update({
'token': get_direct_token(share, file)
})
files.append(status) files.append(status)
script = """#!/bin/bash script = """#!/bin/bash
test "$1" = "-h" && { test "$1" = "-h" && {
@@ -377,6 +366,7 @@ get_file() {
test -f "${FILENAME}" || WRITE=1 test -f "${FILENAME}" || WRITE=1
test "$WRITE" = "1" && { test "$WRITE" = "1" && {
echo Downloading ${FILENAME} echo Downloading ${FILENAME}
mkdir -p $( dirname "$FILENAME" )
curl "${ROOTURL}download/${SHARE}/${TOKEN}/${FILENAME}" > "${FILENAME}" curl "${ROOTURL}download/${SHARE}/${TOKEN}/${FILENAME}" > "${FILENAME}"
} || { } || {
echo Skipping ${FILENAME} echo Skipping ${FILENAME}
@@ -390,7 +380,7 @@ get_file() {
for file in files: for file in files:
script += 'get_file "%s"\n'%( script += 'get_file "%s"\n'%(
file['name'], file['url'],
) )
return script return script
@@ -401,13 +391,8 @@ def script_direct(name = None, token = None):
if not ok: if not ok:
return share return share
files = [] files = []
for file in sorted(os.listdir(share['path'])): for file in iter_folder_files(share['path']):
fp = os.path.join(share['path'],file) status = file_stat(share['path'], file)
if os.path.isdir(fp):
continue
if file.startswith("."):
continue
status = file_stat(fp)
status.update({ status.update({
'token': get_direct_token(share, file) 'token': get_direct_token(share, file)
}) })
@@ -432,6 +417,7 @@ get_file() {
test -f "${FILENAME}" || WRITE=1 test -f "${FILENAME}" || WRITE=1
test "$WRITE" = "1" && { test "$WRITE" = "1" && {
echo Downloading ${FILENAME} echo Downloading ${FILENAME}
mkdir -p $( dirname "$FILENAME" )
curl "${ROOTURL}direct/${SHARE}/${TOKEN}/${FILENAME}" > "${FILENAME}" curl "${ROOTURL}direct/${SHARE}/${TOKEN}/${FILENAME}" > "${FILENAME}"
} || { } || {
echo Skipping ${FILENAME} echo Skipping ${FILENAME}
@@ -444,7 +430,7 @@ get_file() {
for file in files: for file in files:
script += 'get_file "%s" "%s"\n'%( script += 'get_file "%s" "%s"\n'%(
file['name'], file['url'],
file['token'], file['token'],
) )
return script return script
@@ -550,14 +536,15 @@ def download_file(name, filename, token = None):
return send_from_directory(directory=share['path'], filename=filename) return send_from_directory(directory=share['path'], filename=filename)
def file_versionize(filename): def file_versionize(full_path):
""" Move file to versioned with integer """ """ Move file to versioned with integer """
stats = file_stat(filename) file_dir = os.path.dirname(full_path)
basename, extension = os.path.splitext(stats['name']) file_name = os.path.basename(full_path)
basename, extension = os.path.splitext(file_name)
version = 1 version = 1
while True: while True:
new_name = os.path.join( new_name = os.path.join(
os.path.dirname(filename), file_dir,
secure_filename("%s.v%d%s"%( secure_filename("%s.v%d%s"%(
basename, basename,
version, version,
@@ -568,7 +555,7 @@ def file_versionize(filename):
version += 1 version += 1
else: else:
break break
os.rename(filename,new_name) os.rename(full_path,new_name)
def get_share(name, require_auth = True, token = None): def get_share(name, require_auth = True, token = None):

View File

@@ -12,12 +12,14 @@ def file_date_human(num):
).strftime(app.config['DATE_FORMAT']) ).strftime(app.config['DATE_FORMAT'])
def file_stat(filename): def file_stat(path, filename):
s = os.stat(filename) full_path = os.path.join(path, filename)
s = os.stat(full_path)
return { return {
'size': file_size_MB(s.st_size), 'size': file_size_MB(s.st_size),
'mtime': file_date_human(s.st_mtime), 'mtime': file_date_human(s.st_mtime),
'name': os.path.basename(filename) 'name': filename,
'url': path2url(filename)
} }