added renaming for nextcloud/webdav backends

This commit is contained in:
vabene1111
2019-12-24 00:04:41 +01:00
parent 3b5dd7e51d
commit dbea9c80da
4 changed files with 24 additions and 9 deletions

View File

@ -26,7 +26,8 @@ class Nextcloud(Provider):
import_count = 0
for file in files:
path = monitor.path + '/' + file
if not Recipe.objects.filter(file_path=path).exists() and not RecipeImport.objects.filter(file_path=path).exists():
if not Recipe.objects.filter(file_path=path).exists() and not RecipeImport.objects.filter(
file_path=path).exists():
name = os.path.splitext(file)[0]
new_recipe = RecipeImport(name=name, file_path=path, storage=monitor.storage)
new_recipe.save()
@ -51,7 +52,8 @@ class Nextcloud(Provider):
data = {'path': recipe.file_path, 'shareType': 3}
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password), data=data)
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password),
data=data)
response_json = r.json()
@ -74,3 +76,17 @@ class Nextcloud(Provider):
return element['url']
return Nextcloud.create_share_link(recipe)
@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.move(recipe.file_path,
os.path.dirname(recipe.file_path) + '/' + new_name + os.path.splitext(recipe.file_path)[1])
return True