diff --git a/cookbook/provider/dropbox.py b/cookbook/provider/dropbox.py
index c058d82ec..8d31b8a5b 100644
--- a/cookbook/provider/dropbox.py
+++ b/cookbook/provider/dropbox.py
@@ -27,7 +27,7 @@ class Dropbox(Provider):
try:
recipes = r.json()
except ValueError:
- log_entry = SyncLog(status='ERROR', msg=str(r), monitor=monitor)
+ log_entry = SyncLog(status='ERROR', msg=str(r), sync=monitor)
log_entry.save()
return r
@@ -105,3 +105,20 @@ class Dropbox(Provider):
r = requests.post(url, headers=headers, data=json.dumps(data))
return r.json()
+
+ @staticmethod
+ def delete_file(recipe):
+ url = "https://api.dropboxapi.com/2/files/delete_v2"
+
+ headers = {
+ "Authorization": "Bearer " + recipe.storage.token,
+ "Content-Type": "application/json"
+ }
+
+ data = {
+ "path": recipe.file_path
+ }
+
+ r = requests.post(url, headers=headers, data=json.dumps(data))
+
+ return r.json()
diff --git a/cookbook/provider/nextcloud.py b/cookbook/provider/nextcloud.py
index 602d6403c..1b50e8e3e 100644
--- a/cookbook/provider/nextcloud.py
+++ b/cookbook/provider/nextcloud.py
@@ -12,13 +12,17 @@ from cookbook.provider.provider import Provider
class Nextcloud(Provider):
@staticmethod
- def import_all(monitor):
+ def get_client(storage):
options = {
- 'webdav_hostname': monitor.storage.url + '/remote.php/dav/files/' + monitor.storage.username,
- 'webdav_login': monitor.storage.username,
- 'webdav_password': monitor.storage.password
+ 'webdav_hostname': storage.url + '/remote.php/dav/files/' + storage.username,
+ 'webdav_login': storage.username,
+ 'webdav_password': storage.password
}
- client = wc.Client(options)
+ return wc.Client(options)
+
+ @staticmethod
+ def import_all(monitor):
+ client = Nextcloud.get_client(monitor.storage)
files = client.list(monitor.path)
files.pop(0) # remove first element because its the folder itself
@@ -79,14 +83,17 @@ class Nextcloud(Provider):
@staticmethod
def rename_file(recipe, new_name):
- options = {
- 'webdav_hostname': recipe.storage.url + '/remote.php/dav/files/' + recipe.storage.username,
- 'webdav_login': recipe.storage.username,
- 'webdav_password': recipe.storage.password
- }
- client = wc.Client(options)
+ client = Nextcloud.get_client(recipe.storage)
client.move(recipe.file_path,
os.path.dirname(recipe.file_path) + '/' + new_name + os.path.splitext(recipe.file_path)[1])
return True
+
+ @staticmethod
+ def delete_file(recipe):
+ client = Nextcloud.get_client(recipe.storage)
+
+ client.clean(recipe.file_path)
+
+ return True
diff --git a/cookbook/provider/provider.py b/cookbook/provider/provider.py
index 746fd0f5c..cecb7728b 100644
--- a/cookbook/provider/provider.py
+++ b/cookbook/provider/provider.py
@@ -14,3 +14,7 @@ class Provider:
@staticmethod
def rename_file(recipe, new_name):
raise Exception('Method not implemented in storage provider')
+
+ @staticmethod
+ def delete_file(recipe, new_name):
+ raise Exception('Method not implemented in storage provider')
diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html
index c09134023..65f4d000a 100644
--- a/cookbook/templates/forms/edit_internal_recipe.html
+++ b/cookbook/templates/forms/edit_internal_recipe.html
@@ -40,25 +40,29 @@
{% if view_url %}
{% trans 'View' %}
{% endif %}
+ {% if form.instance.storage %}
+ {% trans 'Delete original file' %}
+ {% endif %}