fix: download remote image URLs in DOS/C++

this should resolve the CI issues in `e2e` target by moving away the
httpclient NIM impl to DOS (C++)
This commit is contained in:
Lukáš Tinkl 2023-06-08 19:41:13 +02:00 committed by Lukáš Tinkl
parent 0cf01871b4
commit 9aeba367df
4 changed files with 17 additions and 17 deletions

View File

@ -32,7 +32,7 @@ pipeline {
string(
name: 'NIMFLAGS',
description: 'Extra Nim flags. Examples: --verbosity:2 --passL:"-v" --passC:"-v"',
defaultValue: '-d:useOpenssl3 --colors:off'
defaultValue: '--colors:off'
)
}
@ -67,7 +67,7 @@ pipeline {
QTDIR = '/opt/qt/5.15.2/gcc_64'
PATH = "${env.QTDIR}/bin:${env.PATH}"
/* Include library in order to compile the project */
LD_LIBRARY_PATH = "$QTDIR/lib:$WORKSPACE/vendor/status-go/build/bin:$WORKSPACE/vendor/status-keycard-go/build/libkeycard/:${env.LD_LIBRARY_PATH}"
LD_LIBRARY_PATH = "$QTDIR/lib:$WORKSPACE/vendor/status-go/build/bin:$WORKSPACE/vendor/status-keycard-go/build/libkeycard/"
/* Container ports */
RPC_PORT = "${8545 + env.EXECUTOR_NUMBER.toInteger()}"
P2P_PORT = "${6010 + env.EXECUTOR_NUMBER.toInteger()}"

View File

@ -1,5 +1,5 @@
import NimQml, Tables, json, sequtils, strformat, chronicles, os, std/algorithm, strutils, uuids, base64
import std/[times, os, httpclient, uri]
import std/[times, os]
import ../../../app/core/tasks/[qt, threadpool]
import ./dto/chat as chat_dto
@ -474,17 +474,7 @@ QtObject:
var imagePaths: seq[string] = @[]
for imagePathOrSource in images.mitems:
var imageUrl = imagePathOrSource
if not imageUrl.startsWith(base64JPGPrefix):
let parsedImageUrl = parseUri(imageUrl)
if parsedImageUrl.scheme.startsWith("http"): # remote URL, download it first
var client = newHttpClient()
let tmpPath = TMPDIR & $genUUID() & ".jpg"
client.downloadFile(parsedImageUrl, tmpPath)
imageUrl = tmpPath
let imagePath = image_resizer(imageUrl, 2000, TMPDIR)
let imagePath = image_resizer(imagePathOrSource, 2000, TMPDIR)
if imagePath != "":
imagePaths.add(imagePath)

View File

@ -31,7 +31,7 @@ macro(add_target name type)
target_compile_definitions(${name} PRIVATE -DWIN32)
endif()
set_target_properties(${name} PROPERTIES CXX_STANDARD 11 AUTOMOC ON)
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 AUTOMOC ON)
target_include_directories(${name} PUBLIC include include/Qt)

View File

@ -1454,8 +1454,18 @@ char *dos_image_resizer(const char* imagePathOrData, int maxSize, const char* tm
if (qstrncmp(base64JPGPrefix, imagePathOrData, qstrlen(base64JPGPrefix)) == 0) { // binary BLOB
loadResult = img.loadFromData(QByteArray::fromBase64(QByteArray(imagePathOrData).mid(qstrlen(base64JPGPrefix)))); // strip the prefix, decode from b64
} else { // local file or URL
const auto localFileUrl = QUrl::fromUserInput(imagePathOrData).toLocalFile(); // accept both "file:/foo/bar" and "/foo/bar"
loadResult = img.load(localFileUrl);
const auto localFileOrUrl = QUrl::fromUserInput(imagePathOrData); // accept both "file:/foo/bar" and "/foo/bar"
if (localFileOrUrl.isLocalFile()) {
loadResult = img.load(localFileOrUrl.toLocalFile());
} else {
QEventLoop loop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
auto reply = mgr.get(QNetworkRequest(localFileOrUrl));
loop.exec();
loadResult = img.loadFromData(reply->readAll());
reply->deleteLater();
}
}
if (!loadResult) {