Skip to content

Commit

Permalink
dbhub: Send last modified date when pushing database
Browse files Browse the repository at this point in the history
Also add some code for receiving the last modified data when fetching
but we're not yet able to set it.
  • Loading branch information
MKleusberg committed Sep 30, 2017
1 parent f926a67 commit 8c0e4bf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/RemoteDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QHttpMultiPart>
#include <QTimeZone>

#include "RemoteDatabase.h"
#include "version.h"
Expand Down Expand Up @@ -150,6 +151,17 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
file.write(reply->readAll());
file.close();

// Set last modified data of the new file to the one provided by the server
// TODO Qt doesn't offer any option to set this attribute, so we'd need to figure out a way to do it
// ourselves in a platform-independent way.
/*QString last_modified = reply->rawHeader("Content-Disposition");
QRegExp regex("^.*modification-date=\"(.+)\";.*$");
regex.setMinimal(true); // Set to non-greedy matching
if(regex.indexIn(last_modified) != -1)
{
last_modified = regex.cap(1);
}*/

// Tell the application to open this file
emit openFile(saveFileAs);
}
Expand Down Expand Up @@ -437,6 +449,11 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
request.setUrl(url);
request.setRawHeader("User-Agent", QString("%1 %2").arg(qApp->organizationName()).arg(APP_VERSION).toUtf8());

// Get the last modified date of the file and prepare it for conversion into the ISO date format
QDateTime last_modified = QFileInfo(filename).lastModified();
last_modified.setTimeSpec(Qt::OffsetFromUTC);
last_modified.setTimeZone(QTimeZone::systemTimeZone());

// Prepare HTTP multi part data containing all the information about the commit we're about to push
QHttpMultiPart* multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
addPart(multipart, "file", file, remotename);
Expand All @@ -446,6 +463,7 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
addPart(multipart, "branch", branch);
addPart(multipart, "commit", localLastCommitId(filename));
addPart(multipart, "force", forcePush ? "true" : "false");
addPart(multipart, "lastmodified", last_modified.toString(Qt::ISODate));

// Set SSL configuration when trying to access a file via the HTTPS protocol
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;
Expand Down

0 comments on commit 8c0e4bf

Please sign in to comment.