pdf display working

This commit is contained in:
vabene1111
2020-02-19 18:13:11 +01:00
parent 88dc713683
commit 0c1763b347
6 changed files with 65 additions and 53 deletions

View File

@@ -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):

View File

@@ -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)

View File

@@ -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