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