added renaming for nextcloud/webdav backends
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user