Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/imgag/ngs-bits
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-sturm committed Dec 17, 2024
2 parents f72e57c + 07583c5 commit 04b3463
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
19 changes: 6 additions & 13 deletions src/GSvarServer/ServerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,35 +289,28 @@ HttpResponse ServerController::locateFileByType(const HttpRequest& request)
ServerDB db = ServerDB();
if (db.hasFileLocation(found_file, request.getUrlParams()["type"].toUpper().trimmed(), locus, multiple_files, return_if_missing))
{
QJsonDocument updated_cached_doc;
QJsonArray updated_cached_array;

QJsonDocument cache_doc = db.getFileLocation(found_file, request.getUrlParams()["type"].toUpper().trimmed(), locus, multiple_files, return_if_missing);
db.updateFileLocation(found_file, request.getUrlParams()["type"].toUpper().trimmed(), locus, multiple_files, return_if_missing);

QJsonArray cached_array = cache_doc.array();
for (int index = 0; index < cached_array.size(); index++)
for (const QJsonValue &value : cached_array)
{
if (cached_array.at(index).isObject())
if (value.isObject())
{
QJsonObject cached_object = cached_array.takeAt(index).toObject();
QString cached_filename = cached_object["filename"].toString();

QJsonObject cached_object = value.toObject();
QString cached_filename = cached_object.value("filename").toString();
if (!cached_filename.isEmpty())
{
{
cached_object.insert("filename", createTempUrl(cached_filename, request.getUrlParams()["token"]));
updated_cached_array.append(cached_object);
}
else
{
continue;
}
}
}

// Ignore the cache entry, if no URLs were genereated
if (updated_cached_array.size()>0)
{
QJsonDocument updated_cached_doc;
updated_cached_doc.setArray(updated_cached_array);

BasicResponseData response_data;
Expand Down
5 changes: 2 additions & 3 deletions src/cppREST/ServerDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ bool ServerDB::addFileLocation(const QString filename_with_path, const QString t
{
qint64 requested_as_num = requested.toSecsSinceEpoch();
QString json_string = json_content.replace("'", "''");
// json_string = json_string.replace("\\", "\\\\");
json_string = json_string.replace("\"", "\\\"");
QSqlQuery query = db_->exec("INSERT INTO file_locations (filename_with_path, type, locus, multiple_files, return_if_missing, json_content, requested)"
" VALUES (\"" + filename_with_path + "\", \"" + type + "\", \"" + locus + "\", " + QString::number(static_cast<int>(multiple_files)) + ", " + QString::number(static_cast<int>(return_if_missing)) + ", \"" + json_string + "\", " + QString::number(requested_as_num) + ")");
Expand Down Expand Up @@ -512,8 +511,8 @@ QJsonDocument ServerDB::getFileLocation(const QString filename_with_path, const
QSqlQuery query = db_->exec("SELECT * FROM file_locations WHERE (filename_with_path = \"" + filename_with_path + "\" AND type = \"" + type + "\" AND locus = \"" + locus + "\" AND multiple_files=" + QString::number(static_cast<int>(multiple_files)) + " AND return_if_missing=" + QString::number(static_cast<int>(return_if_missing)) + ")");
if (query.next())
{
int index_json_content = query.record().indexOf("json_content");
return QJsonDocument::fromJson(query.value(index_json_content).toString().toLocal8Bit());
int index_json_content = query.record().indexOf("json_content");
return QJsonDocument::fromJson(query.value(index_json_content).toString().toUtf8());
}
return QJsonDocument();
}
Expand Down

0 comments on commit 04b3463

Please sign in to comment.