From be32b3f63ec569ea087503ed6e170ea015ee1214 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 7 Jun 2018 00:29:00 +0200 Subject: [PATCH] share link fixed --- cookbook/helper/dropbox.py | 25 ++++++++++++++++++++++++- cookbook/views/api.py | 3 +-- cookbook/views/data.py | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/cookbook/helper/dropbox.py b/cookbook/helper/dropbox.py index f20aeedc0..7e10049ef 100644 --- a/cookbook/helper/dropbox.py +++ b/cookbook/helper/dropbox.py @@ -46,7 +46,7 @@ def import_all(monitor): return True -def get_share_link(recipe): +def create_share_link(recipe): url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings" headers = { @@ -59,4 +59,27 @@ def get_share_link(recipe): } r = requests.post(url, headers=headers, data=json.dumps(data)) + return r.json() + + +def get_share_link(recipe): + url = "https://api.dropboxapi.com/2/sharing/list_shared_links" + + headers = { + "Authorization": "Bearer " + recipe.storage.token, + "Content-Type": "application/json" + } + + data = { + "path": recipe.file_uid + } + + r = requests.post(url, headers=headers, data=json.dumps(data)) + p = r.json() + + for l in p['links']: + return l['url'] + + response = create_share_link(recipe) + return response['url'] diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 25925e4a1..f369c8d60 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -14,8 +14,7 @@ def get_file_link(request, recipe_id): if recipe.storage.method == Storage.DROPBOX: if recipe.link == "": - response = dropbox.get_share_link(recipe) # TODO response validation - recipe.link = response['url'] + recipe.link = dropbox.get_share_link(recipe) # TODO response validation recipe.save() return HttpResponse(recipe.link) diff --git a/cookbook/views/data.py b/cookbook/views/data.py index 7329e6f55..b7d538d3f 100644 --- a/cookbook/views/data.py +++ b/cookbook/views/data.py @@ -40,7 +40,7 @@ def sync_wait(request): def batch_import(request): imports = RecipeImport.objects.all() for new_recipe in imports: - recipe = Recipe(name=new_recipe.name, file_path=new_recipe.path, storage=new_recipe.storage, file_uid=new_recipe.file_uid) + recipe = Recipe(name=new_recipe.name, file_path=new_recipe.file_path, storage=new_recipe.storage, file_uid=new_recipe.file_uid) recipe.save() new_recipe.delete()