diff --git a/cookbook/provider/dropbox.py b/cookbook/provider/dropbox.py index c6641202e..0782c1339 100644 --- a/cookbook/provider/dropbox.py +++ b/cookbook/provider/dropbox.py @@ -1,3 +1,4 @@ +import base64 import os from datetime import datetime @@ -89,14 +90,14 @@ class Dropbox(Provider): return response['url'] @staticmethod - def get_cors_link(recipe): + def get_base64_file(recipe): if not recipe.link: recipe.link = Dropbox.get_share_link(recipe) recipe.save() - recipe.cors_link = recipe.link.replace('www.dropbox.', 'dl.dropboxusercontent.') + response = requests.get(recipe.link.replace('www.dropbox.', 'dl.dropboxusercontent.')) - return recipe.cors_link + return base64.b64encode(response.content) @staticmethod def rename_file(recipe, new_name): diff --git a/cookbook/provider/nextcloud.py b/cookbook/provider/nextcloud.py index 1b50e8e3e..2c36ff4d7 100644 --- a/cookbook/provider/nextcloud.py +++ b/cookbook/provider/nextcloud.py @@ -1,8 +1,10 @@ +import base64 import os +import tempfile from datetime import datetime import webdav3.client as wc import requests - +from io import BytesIO from requests.auth import HTTPBasicAuth from cookbook.models import Recipe, RecipeImport, SyncLog @@ -81,6 +83,20 @@ class Nextcloud(Provider): return Nextcloud.create_share_link(recipe) + @staticmethod + def get_base64_file(recipe): + client = Nextcloud.get_client(recipe.storage) + + tmp_file_path = tempfile.gettempdir() + '/' + recipe.name + '.pdf' + + client.download_file(remote_path=recipe.file_path, local_path=tmp_file_path) + + val = base64.b64encode(open(tmp_file_path, 'rb').read()) + + os.remove(tmp_file_path) + + return val + @staticmethod def rename_file(recipe, new_name): client = Nextcloud.get_client(recipe.storage) diff --git a/cookbook/provider/provider.py b/cookbook/provider/provider.py index ad84430ec..c7528f27b 100644 --- a/cookbook/provider/provider.py +++ b/cookbook/provider/provider.py @@ -12,7 +12,7 @@ class Provider: raise Exception('Method not implemented in storage provider') @staticmethod - def get_cors_link(recipe): + def get_base64_file(recipe): raise Exception('Method not implemented in storage provider') @staticmethod diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index a2b60eb78..df010dd89 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -141,6 +141,9 @@
+
@@ -168,58 +171,53 @@
-