external delete button

This commit is contained in:
vabene1111
2019-12-25 15:54:23 +01:00
parent 4b0164a676
commit e2301c0c3a
7 changed files with 84 additions and 31 deletions

View File

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

View File

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

View File

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