new version allows downloads from subfolders
This commit is contained in:
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
from utils.utils import *
|
||||
from utils.crypt import *
|
||||
|
||||
|
||||
def get_root_path(opts):
|
||||
root_folder = os.path.dirname(
|
||||
os.path.dirname(
|
||||
@@ -57,6 +58,7 @@ def list_folders(shares,config):
|
||||
for path, folders, files in os.walk(data_folder):
|
||||
full_path = os.path.join(data_folder, path)
|
||||
share_name = None
|
||||
parent_is_share = False
|
||||
for share in shares:
|
||||
share_path = os.path.join(data_folder, share['path'])
|
||||
if not os.path.exists(share_path):
|
||||
@@ -64,6 +66,13 @@ def list_folders(shares,config):
|
||||
if os.path.samefile(full_path, share_path):
|
||||
share_name = share['name']
|
||||
break
|
||||
parents = full_path.split(os.sep)
|
||||
for p in range(len(parents)):
|
||||
test_path = os.sep+os.sep.join(parents[1:(p+2)])
|
||||
if os.path.samefile(test_path, share_path):
|
||||
parent_is_share = True
|
||||
if parent_is_share:
|
||||
continue
|
||||
if share_name == None:
|
||||
# skip folder if it's not a share, and not a leaf
|
||||
if len(folders) > 0:
|
||||
@@ -83,6 +92,7 @@ def list_folders(shares,config):
|
||||
))
|
||||
print(tabulate(table, headers = "firstrow"))
|
||||
|
||||
|
||||
def add_share(shares, config, opts):
|
||||
|
||||
# Make name and path safe:
|
||||
@@ -214,7 +224,6 @@ def modify_share(shares, config, opts):
|
||||
if not token in share['tokens']:
|
||||
share['tokens'].append(token)
|
||||
|
||||
|
||||
if opts.expire:
|
||||
if opts.expire == "":
|
||||
# REMOVE EXPIRATION
|
||||
@@ -306,7 +315,6 @@ def show_share(shares, config, opts):
|
||||
print_share(share, config)
|
||||
|
||||
|
||||
|
||||
def print_rest_api(shares, config, opts):
|
||||
if 'public_url' not in config:
|
||||
print("Set public_url variable in your config.json")
|
||||
@@ -412,16 +420,12 @@ def print_rest_api_download(config, share, token):
|
||||
if not os.path.exists(share_path):
|
||||
print("no files")
|
||||
sys.exit(0)
|
||||
for filename in sorted(os.listdir(share_path)):
|
||||
if os.path.isdir(os.path.join(share_path,filename)):
|
||||
continue
|
||||
if filename.startswith("."):
|
||||
continue
|
||||
for filename in iter_folder_files(share_path):
|
||||
print("%s/download/%s/%s/%s"%(
|
||||
config['public_url'],
|
||||
share['name'],
|
||||
token,
|
||||
filename
|
||||
path2url(filename)
|
||||
))
|
||||
print("or \n\n# curl -s %s/script/download/%s/%s | bash /dev/stdin [-f]"%(
|
||||
config['public_url'],
|
||||
@@ -444,16 +448,12 @@ def print_rest_api_direct(config, share, token):
|
||||
if not os.path.exists(share_path):
|
||||
print("no files")
|
||||
sys.exit(0)
|
||||
for filename in sorted(os.listdir(share_path)):
|
||||
if os.path.isdir(os.path.join(share_path,filename)):
|
||||
continue
|
||||
if filename.startswith("."):
|
||||
continue
|
||||
for filename in iter_folder_files(share_path):
|
||||
print("%s/direct/%s/%s/%s"%(
|
||||
config['public_url'],
|
||||
share['name'],
|
||||
get_direct_token(share,filename),
|
||||
filename
|
||||
path2url(filename)
|
||||
))
|
||||
print("or \n\n# curl -s %s/script/direct/%s/%s | bash /dev/stdin [-f]"%(
|
||||
config['public_url'],
|
||||
|
||||
Reference in New Issue
Block a user