Browse Source

Bypass cache when uploading a torrent file in Web UI (closes #68)

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
de43a0b7a1
  1. 28
      src/webui/html/upload.html
  2. 5
      src/webui/httpconnection.cpp

28
src/webui/html/upload.html

@ -7,31 +7,30 @@ @@ -7,31 +7,30 @@
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript">
function hideAll() {
function stateChangeHandler() {
if (this.readyState == this.DONE) {
if (this.status == 200)
window.parent.closeWindows();
else
alert("Upload Failed!");
}
}
function uploadFiles(files) {
var xhr = new XMLHttpRequest();
if (xhr.upload) {
// file received/failed
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
if (xhr.status == 200)
hideAll();
else
alert("Upload Failed!");
}
};
// start upload
var formData = new FormData();
for (var i = 0, file; file = files[i]; ++i) {
for (var i = 0, file; file = files[i]; ++i)
formData.append(file.name, file);
}
xhr.open("POST", "command/upload", true);
xhr.onreadystatechange = stateChangeHandler;
xhr.open("POST", "command/upload");
// Bypass cache
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.send(formData);
}
}
// file selection
function fileSelectHandler(e) {
// fetch FileList object
@ -44,9 +43,8 @@ window.addEvent('load', function() { @@ -44,9 +43,8 @@ window.addEvent('load', function() {
$('fileselect').addEvent('change', fileSelectHandler);
// is XHR2 available?
var xhr = new XMLHttpRequest();
if (xhr.upload) {
if (xhr.upload)
$('submitbutton').addClass("invisible");
}
});
</script>
</head>

5
src/webui/httpconnection.cpp

@ -297,7 +297,7 @@ void HttpConnection::respond() { @@ -297,7 +297,7 @@ void HttpConnection::respond() {
}
// Icons from theme
qDebug() << "list[0]" << list[0];
//qDebug() << "list[0]" << list[0];
if (list[0] == "theme" && list.size() == 2) {
#ifdef DISABLE_GUI
url = ":/Icons/oxygen/"+list[1]+".png";
@ -393,6 +393,7 @@ void HttpConnection::respondGlobalTransferInfoJson() { @@ -393,6 +393,7 @@ void HttpConnection::respondGlobalTransferInfoJson() {
}
void HttpConnection::respondCommand(const QString& command) {
qDebug() << Q_FUNC_INFO << command;
if (command == "download") {
QString urls = m_parser.post("urls");
QStringList list = urls.split('\n');
@ -434,7 +435,7 @@ void HttpConnection::respondCommand(const QString& command) { @@ -434,7 +435,7 @@ void HttpConnection::respondCommand(const QString& command) {
const QList<QByteArray>& torrents = m_parser.torrents();
foreach(const QByteArray& torrentContent, torrents) {
// Get a unique filename
QTemporaryFile *tmpfile = new QTemporaryFile (QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent"));
QTemporaryFile *tmpfile = new QTemporaryFile(QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent"));
tmpfile->setAutoRemove(false);
if (tmpfile->open()) {
QString filePath = tmpfile->fileName();

Loading…
Cancel
Save