mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-24 02:39:20 -05:00
pdf display working
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user