summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Stigge <stigge@antcom.de>2018-01-07 13:15:39 +0100
committerRoland Stigge <stigge@antcom.de>2018-01-07 13:15:39 +0100
commit3bccf120e0a6653804a1678f383e973ceffb9955 (patch)
treeeb138355aadd373f132a020844be81ea4b10d52b
parent329d00741ca0fee084d0f7c5b43ef3fab6df0570 (diff)
Fix ZIP download
-rw-r--r--TODO1
-rw-r--r--debian/control1
-rw-r--r--html/webbox.js1
-rw-r--r--src/webbox.cpp60
4 files changed, 58 insertions, 5 deletions
diff --git a/TODO b/TODO
index e9877fb..e9d6667 100644
--- a/TODO
+++ b/TODO
@@ -10,6 +10,7 @@ download zip
Prio 2 (for future versions)
======
+handle errors from http
gallery
chromecast
player
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..7725dc4
--- /dev/null
+++ b/debian/control
@@ -0,0 +1 @@
+Depends: zip
diff --git a/html/webbox.js b/html/webbox.js
index 2b70292..faa2bb2 100644
--- a/html/webbox.js
+++ b/html/webbox.js
@@ -299,6 +299,7 @@ function download(filename) {
xhr.open("POST", "/bin/query" + currentDir + "?command=download-zip", true);
xhr.setRequestHeader("Content-type", "text/xml");
+ xhr.responseType = 'blob';
xhr.send(xmlDocument);
}
} else {
diff --git a/src/webbox.cpp b/src/webbox.cpp
index b5d35c2..190d7e7 100644
--- a/src/webbox.cpp
+++ b/src/webbox.cpp
@@ -7,6 +7,8 @@
#include <QFileInfo>
#include <QXmlStreamReader>
#include <QDateTime>
+#include <QProcess>
+#include <QTemporaryFile>
#define PROGRAMVERSION "1.0"
#define BUFSIZE 1000000
@@ -218,6 +220,16 @@ int main(int argc, char* argv[]) {
QXmlStreamReader xml(content);
QByteArray zipData;
+ QStringList argumentList;
+ QTemporaryFile tempfile(QDir::tempPath() + "/webboxXXXXXX.zip");
+ tempfile.open();
+ QFileInfo fileInfo(tempfile);
+ QString tempfilePath = fileInfo.absolutePath();
+ QString tempfileName = fileInfo.fileName();
+ tempfile.close();
+ tempfile.remove();
+
+ argumentList << tempfileName; // zip filename
while (!xml.atEnd()) {
while (xml.readNextStartElement()) {
@@ -226,17 +238,55 @@ int main(int argc, char* argv[]) {
if (xml.name() == "file") {
QString filename = xml.readElementText();
- zipData.append(filename.toUtf8()); // TBD
+ argumentList.append(path + filename); // add parts
}
}
}
}
}
- FCGX_PutS(QString("Content-Disposition: attachment; filename=\"%1\"\r\n").arg("webbox-download.zip").toUtf8().data(), request.out);
- FCGX_PutS("Content-Type: application/octet-stream\r\n\r\n", request.out);
-
- FCGX_PutStr(zipData.data(), zipData.size(), request.out);
+ QProcess process;
+ process.setWorkingDirectory(tempfilePath);
+ process.setProgram("/usr/bin/zip");
+ process.setArguments(argumentList);
+ process.start();
+ process.waitForFinished();
+
+ QString debugText = process.readAll();
+ process.setReadChannel(QProcess::StandardError);
+ debugText += process.readAll();
+
+ if (process.state() != QProcess::NotRunning ||
+ process.exitCode() != 0 ||
+ process.exitStatus() != QProcess::NormalExit)
+ {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Error running process: %1 %2 %3 %4 %5 %6 %7").
+ arg(process.state()).
+ arg(process.exitCode()).
+ arg(process.exitStatus()).
+ arg(tempfilePath).
+ arg(tempfileName).
+ arg(argumentList[0]).
+ arg(debugText).toUtf8().data(), request.out);
+ } else {
+
+ QFile tempfile(tempfilePath + "/" + tempfileName);
+ if (!tempfile.open(QIODevice::ReadOnly)) {
+ FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
+ FCGX_PutS(QString("Error reading file").toUtf8().data(), request.out);
+ } else {
+ zipData = tempfile.readAll();
+
+ FCGX_PutS(QString("Content-Disposition: attachment; filename=\"%1\"\r\n").arg("webbox-download.zip").toUtf8().data(), request.out);
+ FCGX_PutS("Content-Type: application/octet-stream\r\n\r\n", request.out);
+
+ FCGX_PutStr(zipData.data(), zipData.size(), request.out);
+ }
+
+ tempfile.close();
+ tempfile.remove();
+ }
}
}
} else if (command == "upload") { // POST!