nextcloud storage working
This commit is contained in:
@ -42,55 +42,37 @@ class Nextcloud(Provider):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def url_from_ocs_response(response):
|
|
||||||
if response['ocs']['data']:
|
|
||||||
elements = response['ocs']['data']['element']
|
|
||||||
if isinstance(elements, list):
|
|
||||||
for element in elements:
|
|
||||||
if element['share_type'] == '3':
|
|
||||||
return element['url']
|
|
||||||
else:
|
|
||||||
if elements['share_type'] == '3':
|
|
||||||
return elements['url']
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_share_link(recipe):
|
def create_share_link(recipe):
|
||||||
url = recipe.storage.url + '/ocs/v2.php/apps/files_sharing/api/v1/shares'
|
url = recipe.storage.url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json'
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"OCS-APIRequest": "true",
|
"OCS-APIRequest": "true",
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
}
|
}
|
||||||
|
|
||||||
data = {
|
data = {'path': recipe.file_path, 'shareType': 3}
|
||||||
"path": recipe.file_path,
|
|
||||||
"shareType ": 3
|
|
||||||
}
|
|
||||||
|
|
||||||
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password), data=json.dumps(data))
|
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password), data=data)
|
||||||
|
|
||||||
json_response = xmltodict.parse(r.text)
|
response_json = r.json()
|
||||||
|
|
||||||
return Nextcloud.url_from_ocs_response(json_response)
|
return response_json['ocs']['data']['url']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_share_link(recipe):
|
def get_share_link(recipe):
|
||||||
url = recipe.storage.url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?path=' + recipe.file_path
|
url = recipe.storage.url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json&path=' + recipe.file_path
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"OCS-APIRequest": "true",
|
"OCS-APIRequest": "true",
|
||||||
"Content-Type": "application/xml"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
r = requests.get(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password))
|
r = requests.get(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password))
|
||||||
|
|
||||||
json_response = xmltodict.parse(r.text)
|
response_json = r.json()
|
||||||
|
for element in response_json['ocs']['data']:
|
||||||
url = Nextcloud.url_from_ocs_response(json_response)
|
if element['share_type'] == '3':
|
||||||
if url:
|
return element['url']
|
||||||
return url
|
|
||||||
|
|
||||||
return Nextcloud.create_share_link(recipe)
|
return Nextcloud.create_share_link(recipe)
|
||||||
|
@ -97,8 +97,8 @@
|
|||||||
xhttp.onreadystatechange = function () {
|
xhttp.onreadystatechange = function () {
|
||||||
if (this.readyState === 4 && this.status === 200) {
|
if (this.readyState === 4 && this.status === 200) {
|
||||||
window.open(this.responseText);
|
window.open(this.responseText);
|
||||||
link.attr("href", this.responseText);
|
//link.attr("href", this.responseText);
|
||||||
link.show();
|
//link.show();
|
||||||
$('#div_loader').hide();
|
$('#div_loader').hide();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ def get_file_link(request, recipe_id):
|
|||||||
if recipe.storage.method == Storage.NEXTCLOUD:
|
if recipe.storage.method == Storage.NEXTCLOUD:
|
||||||
if recipe.link == "":
|
if recipe.link == "":
|
||||||
recipe.link = Nextcloud.get_share_link(recipe) # TODO response validation
|
recipe.link = Nextcloud.get_share_link(recipe) # TODO response validation
|
||||||
#recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
return HttpResponse(recipe.link)
|
return HttpResponse(recipe.link)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user