urlo upload as js function
This commit is contained in:
@@ -184,7 +184,9 @@ def upload_url():
|
|||||||
)
|
)
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
file_versionize(filename)
|
file_versionize(filename)
|
||||||
download_url(url, filename)
|
ok,error = download_url(url, filename)
|
||||||
|
if not ok:
|
||||||
|
return error
|
||||||
set_rights(filename)
|
set_rights(filename)
|
||||||
notify({
|
notify({
|
||||||
"recipient": get_or_none('recipient', share),
|
"recipient": get_or_none('recipient', share),
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ tr:nth-child(odd) {
|
|||||||
}
|
}
|
||||||
#list_url_upload_button {
|
#list_url_upload_button {
|
||||||
float: right;
|
float: right;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#list_info_toggle {
|
#list_info_toggle {
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ function UploadFile(file,file_no,files_total) {
|
|||||||
var file_counter = "(" + (file_no + 1) + "/" + files_total + ") ";
|
var file_counter = "(" + (file_no + 1) + "/" + files_total + ") ";
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
if (xhr.upload) {
|
if (xhr.upload) {
|
||||||
|
|
||||||
var o = document.getElementById("progress");
|
var o = document.getElementById("progress");
|
||||||
xhr.upload.addEventListener("progress", function(e) {
|
xhr.upload.addEventListener(
|
||||||
|
"progress",
|
||||||
|
function(e) {
|
||||||
var pc = parseInt((e.loaded / e.total * 100));
|
var pc = parseInt((e.loaded / e.total * 100));
|
||||||
o.className = "";
|
o.className = "";
|
||||||
o.innerHTML = "Uploading: " + file_counter + pc + "%";
|
o.innerHTML = "Uploading: " + file_counter + pc + "%";
|
||||||
@@ -52,7 +53,9 @@ function UploadFile(file,file_no,files_total) {
|
|||||||
}
|
}
|
||||||
// upload works, hide button
|
// upload works, hide button
|
||||||
document.getElementById("list_upload_button").hidden = true;
|
document.getElementById("list_upload_button").hidden = true;
|
||||||
}, false);
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
// file received/failed
|
// file received/failed
|
||||||
xhr.onreadystatechange = function(e) {
|
xhr.onreadystatechange = function(e) {
|
||||||
@@ -95,3 +98,45 @@ function FileSelectHandler(e) {
|
|||||||
// Variable to stop parallel uploads
|
// Variable to stop parallel uploads
|
||||||
var uploadTurn = -1;
|
var uploadTurn = -1;
|
||||||
|
|
||||||
|
function UploadURL() {
|
||||||
|
var URL = document.getElementById("list_url_upload_text").value;
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
if (xhr.upload) {
|
||||||
|
var o = document.getElementById("progress");
|
||||||
|
xhr.upload.addEventListener(
|
||||||
|
"progress",
|
||||||
|
function(e) {
|
||||||
|
o.className = "";
|
||||||
|
o.innerHTML = "Uploading...";
|
||||||
|
console.log(e);
|
||||||
|
// upload works, hide button
|
||||||
|
document.getElementById("list_url_upload_button").setAttribute("disabled", "disabled");
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
// file received/failed
|
||||||
|
xhr.onreadystatechange = function(e) {
|
||||||
|
if (xhr.readyState == 4) {
|
||||||
|
o.className = (xhr.status == 200 ? "success" : "failure");
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
// refresh page at upload finish
|
||||||
|
location = location;
|
||||||
|
} else {
|
||||||
|
o.innerHTML = xhr.response;
|
||||||
|
document.getElementById("list_url_upload_button").removeAttribute("disabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// start upload
|
||||||
|
xhr.open("POST", document.getElementById("url_upload_form").action, true);
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('name', document.getElementById("list_upload_name").value);
|
||||||
|
formData.append('from_gui', 'true');
|
||||||
|
formData.append('url', URL);
|
||||||
|
xhr.send(formData);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@
|
|||||||
<input type=hidden name=from_gui value="true" />
|
<input type=hidden name=from_gui value="true" />
|
||||||
<input id="list_url_upload_text" type=text name=url
|
<input id="list_url_upload_text" type=text name=url
|
||||||
value="https://..." onclick="clear_text(this.id,'https://...')"><br>
|
value="https://..." onclick="clear_text(this.id,'https://...')"><br>
|
||||||
<input id="list_url_upload_button" type=submit value="Upload URL">
|
|
||||||
<div class="clear"></div>
|
|
||||||
</form>
|
</form>
|
||||||
|
<input id="list_url_upload_button" type=submit value="Upload URL" onclick="UploadURL()">
|
||||||
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -5,16 +5,22 @@ try:
|
|||||||
from urllib.request import pathname2url
|
from urllib.request import pathname2url
|
||||||
from urllib.request import URLopener
|
from urllib.request import URLopener
|
||||||
from urllib.request import urlparse
|
from urllib.request import urlparse
|
||||||
|
from urllib.error import HTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import pathname2url
|
from urllib import pathname2url
|
||||||
from urllib import URLopener
|
from urllib import URLopener
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
from urllib2 import HTTPError
|
||||||
|
|
||||||
|
|
||||||
def download_url(url,filename):
|
def download_url(url,filename):
|
||||||
downloader = URLopener()
|
downloader = URLopener()
|
||||||
|
try:
|
||||||
downloader.retrieve(url, filename)
|
downloader.retrieve(url, filename)
|
||||||
return
|
except HTTPError as e:
|
||||||
|
return (False, ("%s %s"%(e.code,e.reason), e.code))
|
||||||
|
return (True, ("OK", 200 ))
|
||||||
|
|
||||||
|
|
||||||
def file_date_human(num):
|
def file_date_human(num):
|
||||||
return datetime.fromtimestamp(
|
return datetime.fromtimestamp(
|
||||||
|
|||||||
Reference in New Issue
Block a user