From deee448de402f6357da18db7ae0dd929c137bd2e Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Wed, 18 Nov 2020 18:54:36 +0200 Subject: [PATCH] Read s3 creds for upload from URL in private network (VPN) - fix --- data/translations/Internationalization_ca.ts | 30 +++-- data/translations/Internationalization_cs.ts | 30 +++-- .../Internationalization_de_DE.ts | 30 +++-- data/translations/Internationalization_es.ts | 30 +++-- data/translations/Internationalization_eu.ts | 30 +++-- data/translations/Internationalization_fr.ts | 30 +++-- .../Internationalization_it_IT.ts | 30 +++-- data/translations/Internationalization_ja.ts | 30 +++-- data/translations/Internationalization_ka.ts | 30 +++-- data/translations/Internationalization_nl.ts | 30 +++-- .../Internationalization_nl_NL.ts | 30 +++-- data/translations/Internationalization_pl.ts | 30 +++-- .../Internationalization_pt_BR.ts | 30 +++-- data/translations/Internationalization_ru.ts | 30 +++-- data/translations/Internationalization_sk.ts | 30 +++-- .../Internationalization_sr_SP.ts | 30 +++-- .../Internationalization_sv_SE.ts | 30 +++-- data/translations/Internationalization_tr.ts | 30 +++-- data/translations/Internationalization_uk.ts | 30 +++-- .../Internationalization_zh_CN.ts | 30 +++-- .../Internationalization_zh_HK.ts | 30 +++-- .../Internationalization_zh_TW.ts | 30 +++-- src/tools/storage/s3/imgs3settings.cpp | 96 ++-------------- src/tools/storage/s3/imgs3settings.h | 21 +--- src/tools/storage/s3/imgs3uploader.cpp | 106 ++++++++++++------ src/tools/storage/s3/imgs3uploader.h | 10 +- 26 files changed, 401 insertions(+), 492 deletions(-) diff --git a/data/translations/Internationalization_ca.ts b/data/translations/Internationalization_ca.ts index fa37337d38..c80f74a44d 100644 --- a/data/translations/Internationalization_ca.ts +++ b/data/translations/Internationalization_ca.ts @@ -523,7 +523,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 @@ -532,69 +532,67 @@ Press Space to open the side panel. S'està pujant la imatge - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. L'URL s'ha copiat al porta-retalls. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Error - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_cs.ts b/data/translations/Internationalization_cs.ts index 36cd26333f..8beb94f282 100644 --- a/data/translations/Internationalization_cs.ts +++ b/data/translations/Internationalization_cs.ts @@ -530,7 +530,7 @@ Stiskněte mezerník pro otevření postranního panelu. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Stiskněte mezerník pro otevření postranního panelu. Nahrává se obrázek - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. Adresa (URL) zkopírována do schránky. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Chyba - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_de_DE.ts b/data/translations/Internationalization_de_DE.ts index 71a8a2e20f..90fa543244 100644 --- a/data/translations/Internationalization_de_DE.ts +++ b/data/translations/Internationalization_de_DE.ts @@ -526,7 +526,7 @@ Drücke die Leertaste um das Seitenmenü zu öffnen. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Drücke die Leertaste um das Seitenmenü zu öffnen. Bild hochladen - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL kopiert. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Fehler - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_es.ts b/data/translations/Internationalization_es.ts index 906038b193..0c8707bf6a 100644 --- a/data/translations/Internationalization_es.ts +++ b/data/translations/Internationalization_es.ts @@ -526,7 +526,7 @@ Presiona Espacio para abrir el panel lateral. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Presiona Espacio para abrir el panel lateral. Subiendo Imagen - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL copiada al portapapeles. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Error - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_eu.ts b/data/translations/Internationalization_eu.ts index c914e9820f..3b31c5260e 100644 --- a/data/translations/Internationalization_eu.ts +++ b/data/translations/Internationalization_eu.ts @@ -530,7 +530,7 @@ Sakatu Zuriunea alboko panela irekitzeko. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Sakatu Zuriunea alboko panela irekitzeko. Irudia igotzen - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. Arbelean kopiatu da URLa. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Errorea - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_fr.ts b/data/translations/Internationalization_fr.ts index 830234a8fa..1c7b28ae50 100644 --- a/data/translations/Internationalization_fr.ts +++ b/data/translations/Internationalization_fr.ts @@ -530,7 +530,7 @@ Appuyer sur Espace pour ouvrir le panneau latéral. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Appuyer sur Espace pour ouvrir le panneau latéral. Mise en ligne de l'image - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL copiée dans le Presse-papier. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Erreur - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_it_IT.ts b/data/translations/Internationalization_it_IT.ts index 05b667e626..aed180a09a 100644 --- a/data/translations/Internationalization_it_IT.ts +++ b/data/translations/Internationalization_it_IT.ts @@ -507,74 +507,72 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_ja.ts b/data/translations/Internationalization_ja.ts index d931281b07..2b00b7195d 100644 --- a/data/translations/Internationalization_ja.ts +++ b/data/translations/Internationalization_ja.ts @@ -526,7 +526,7 @@ Enter を押すと画面をキャプチャー。 ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Enter を押すと画面をキャプチャー。 画像をアップロード中 - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL をクリップボードにコピーしました。 - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error エラー - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_ka.ts b/data/translations/Internationalization_ka.ts index 6ecbf249d5..860849c13e 100644 --- a/data/translations/Internationalization_ka.ts +++ b/data/translations/Internationalization_ka.ts @@ -522,7 +522,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 @@ -531,69 +531,67 @@ Press Space to open the side panel. სურათის ატვირთვა - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL დაკოპირდა გაცვლის ბუფერში. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error შეცდომა - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_nl.ts b/data/translations/Internationalization_nl.ts index ce7dd6682e..0f76814824 100644 --- a/data/translations/Internationalization_nl.ts +++ b/data/translations/Internationalization_nl.ts @@ -526,7 +526,7 @@ Druk op spatie om het zijpaneel te openen. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Druk op spatie om het zijpaneel te openen. Bezig met uploaden van afbeelding... - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL gekopieerd naar klembord. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Fout - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_nl_NL.ts b/data/translations/Internationalization_nl_NL.ts index 61fb0bfd8a..9cd425706a 100644 --- a/data/translations/Internationalization_nl_NL.ts +++ b/data/translations/Internationalization_nl_NL.ts @@ -530,7 +530,7 @@ Druk op de spatiebalk om het zijpaneel te openen. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Druk op de spatiebalk om het zijpaneel te openen. Afbeelding uploaden - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL gekopieerd naar klembord. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Fout - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_pl.ts b/data/translations/Internationalization_pl.ts index b472bc9b7a..16acdea3a0 100644 --- a/data/translations/Internationalization_pl.ts +++ b/data/translations/Internationalization_pl.ts @@ -529,7 +529,7 @@ Spacja, aby pokazać panel boczny. ImgS3Uploader - + Upload image to S3 @@ -538,69 +538,67 @@ Spacja, aby pokazać panel boczny. Wysyłanie obrazka - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL skopiowany do schowka. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Błąd - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_pt_BR.ts b/data/translations/Internationalization_pt_BR.ts index ff29c0aaeb..cc8eadee56 100644 --- a/data/translations/Internationalization_pt_BR.ts +++ b/data/translations/Internationalization_pt_BR.ts @@ -530,7 +530,7 @@ Pressione espaço abrir o painel lateral. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Pressione espaço abrir o painel lateral. Upando Imagem - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL copiada para a área de transferência. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Erro - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_ru.ts b/data/translations/Internationalization_ru.ts index 6743d7c296..6d5c470551 100644 --- a/data/translations/Internationalization_ru.ts +++ b/data/translations/Internationalization_ru.ts @@ -534,7 +534,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 Загрузка изображения на S3 @@ -543,69 +543,67 @@ Press Space to open the side panel. Загрузка изображения - - + Uploading Image... Выгрузка изображения... - + Delete image from S3 Удалить изображение из S3 - + Deleting image... Удаление изображения... - + URL copied to clipboard. URL скопирован в буфер обмена. - + Unable to remove screenshot from the remote storage. Невозможно удалить снимок экрана из удаленного хранилища. - + Network error Ошибка сети - + Possibly it doesn't exist anymore Возможно, его больше не существует - + Do you want to remove screenshot from local history anyway? Вы все равно хотите удалить скриншот из локальной истории? - + Remove screenshot from history? Удалить скриншот из истории? - - + Retrieving configuration file with s3 creds... Получение конфигурационного файла с параметрами доступа к s3... - + S3 Creds URL is not found in your configuration file S3 Creds URL не найден в вашем файле конфигурации - + Error Ошибка - + Unable to get s3 credentials, please check your VPN connection and try again Не удалось получить конфигурацию для s3, проверьте свое VPN-соединение и повторите попытку diff --git a/data/translations/Internationalization_sk.ts b/data/translations/Internationalization_sk.ts index 7333366ee6..ba5bde0238 100644 --- a/data/translations/Internationalization_sk.ts +++ b/data/translations/Internationalization_sk.ts @@ -530,7 +530,7 @@ Stlačte medzerník pre otvorenie postranného panelu. ImgS3Uploader - + Upload image to S3 @@ -539,69 +539,67 @@ Stlačte medzerník pre otvorenie postranného panelu. Nahrávam obrázok - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL skopírovaná do schránky. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Chyba - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_sr_SP.ts b/data/translations/Internationalization_sr_SP.ts index 202f395773..7ffa1ae504 100644 --- a/data/translations/Internationalization_sr_SP.ts +++ b/data/translations/Internationalization_sr_SP.ts @@ -526,7 +526,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Press Space to open the side panel. Објављујем слику - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. Интернет адреса је сачувана у привременој меморији. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Грешка - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_sv_SE.ts b/data/translations/Internationalization_sv_SE.ts index 4c06d0481b..8bb08d18a1 100644 --- a/data/translations/Internationalization_sv_SE.ts +++ b/data/translations/Internationalization_sv_SE.ts @@ -526,7 +526,7 @@ Tryck Space för att öppna sidopanelen. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Tryck Space för att öppna sidopanelen. Laddar upp bild - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL kopierad till klippbord. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Fel - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_tr.ts b/data/translations/Internationalization_tr.ts index a6170d74ee..5895bcfdec 100644 --- a/data/translations/Internationalization_tr.ts +++ b/data/translations/Internationalization_tr.ts @@ -526,7 +526,7 @@ Yan paneli açmak için Boşluk tuşuna basın. ImgS3Uploader - + Upload image to S3 @@ -535,69 +535,67 @@ Yan paneli açmak için Boşluk tuşuna basın. Resim Yükleniyor - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. URL panoya kopyalandı. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error Hata - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_uk.ts b/data/translations/Internationalization_uk.ts index b23fc6a185..ed86721650 100644 --- a/data/translations/Internationalization_uk.ts +++ b/data/translations/Internationalization_uk.ts @@ -534,7 +534,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 Вивантаження зображення на S3 @@ -543,69 +543,67 @@ Press Space to open the side panel. Вивантаження зображення - - + Uploading Image... Вивантаження зображення... - + Delete image from S3 Видаліть зображення з S3 - + Deleting image... Видалення зображення... - + URL copied to clipboard. URL скопійовано до буферу обміну. - + Unable to remove screenshot from the remote storage. Не вдалося видалити знімок екрана з віддаленого сховища. - + Network error Помилка мережі - + Possibly it doesn't exist anymore Можливо, його вже не існує - + Do you want to remove screenshot from local history anyway? Ви все одно хочете видалити знімок екрана з місцевої історії? - + Remove screenshot from history? Видалити знімок екрана з історії? - - + Retrieving configuration file with s3 creds... Отримання конфігураційного файлу з параметрами доступу до s3 ... - + S3 Creds URL is not found in your configuration file S3 Creds URL не знайдено у вашому файлі конфігурації - + Error Помилка - + Unable to get s3 credentials, please check your VPN connection and try again Не вдалося отримати конфігурацію для s3, перевірити своє з'єднання VPN і повторити спробу diff --git a/data/translations/Internationalization_zh_CN.ts b/data/translations/Internationalization_zh_CN.ts index 8988be30dc..7ec424c195 100644 --- a/data/translations/Internationalization_zh_CN.ts +++ b/data/translations/Internationalization_zh_CN.ts @@ -531,7 +531,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 @@ -540,69 +540,67 @@ Press Space to open the side panel. 正在上传 - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error 错误 - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_zh_HK.ts b/data/translations/Internationalization_zh_HK.ts index 113dfd42de..e1db3e849d 100644 --- a/data/translations/Internationalization_zh_HK.ts +++ b/data/translations/Internationalization_zh_HK.ts @@ -530,74 +530,72 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error 錯誤 - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/data/translations/Internationalization_zh_TW.ts b/data/translations/Internationalization_zh_TW.ts index 8cead83da7..67169b5099 100644 --- a/data/translations/Internationalization_zh_TW.ts +++ b/data/translations/Internationalization_zh_TW.ts @@ -522,7 +522,7 @@ Press Space to open the side panel. ImgS3Uploader - + Upload image to S3 @@ -531,69 +531,67 @@ Press Space to open the side panel. 正在上傳 - - + Uploading Image... - + Delete image from S3 - + Deleting image... - + URL copied to clipboard. 連結已複製到剪貼簿 - + Unable to remove screenshot from the remote storage. - + Network error - + Possibly it doesn't exist anymore - + Do you want to remove screenshot from local history anyway? - + Remove screenshot from history? - - + Retrieving configuration file with s3 creds... - + S3 Creds URL is not found in your configuration file - + Error 錯誤 - + Unable to get s3 credentials, please check your VPN connection and try again diff --git a/src/tools/storage/s3/imgs3settings.cpp b/src/tools/storage/s3/imgs3settings.cpp index dad9e75052..5ce12c3c0c 100644 --- a/src/tools/storage/s3/imgs3settings.cpp +++ b/src/tools/storage/s3/imgs3settings.cpp @@ -4,22 +4,14 @@ #include #include #include -#include #include -#include #include -#include -#include -#include #include #include -#include -ImgS3Settings::ImgS3Settings(QObject* parent) - : QObject(parent) +ImgS3Settings::ImgS3Settings() { m_proxy = nullptr; - m_networkConfig = nullptr; initSettings(); // get remote config url @@ -47,38 +39,9 @@ void ImgS3Settings::initS3Creds() m_xApiKey = configHandler.value("S3", "S3_X_API_KEY").toString(); m_url = configHandler.value("S3", "S3_URL").toString(); normalizeS3Creds(); - updateConfigFromRemote(); } -bool ImgS3Settings::getConfigRemote(int timeout) -{ - if (!m_url.isEmpty() && !m_credsUrl.isEmpty()) { - updateConfigFromRemote(); - return true; - } - QNetworkAccessManager* networkConfig = new QNetworkAccessManager(this); - if (proxy() != nullptr) { - networkConfig->setProxy(*m_proxy); - } - QNetworkReply* reply = networkConfig->get(QNetworkRequest(m_s3ConfigUrl)); - - QEventLoop loop; - QTimer timer; - timer.setSingleShot(true); - connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit())); - timer.start(timeout * 1000); // 30 secs. timeout - loop.exec(); - QString data = QString(reply->readAll()); - parseConfigurationData(data); - - delete reply; - delete networkConfig; - - return !data.isEmpty(); -} - -void ImgS3Settings::parseConfigurationData(const QString& data) +void ImgS3Settings::updateConfigurationData(const QString& data) { // read remote and save to the temporary file QTemporaryFile file; @@ -88,11 +51,11 @@ void ImgS3Settings::parseConfigurationData(const QString& data) stream.flush(); // parse and get configuration data - QSettings remoteConfig(file.fileName(), QSettings::IniFormat, this); + QSettings remoteConfig(file.fileName(), QSettings::IniFormat); remoteConfig.beginGroup("S3"); - m_url = remoteConfig.value("S3_URL").toString(); - m_credsUrl = remoteConfig.value("S3_CREDS_URL").toString(); - m_xApiKey = remoteConfig.value("S3_X_API_KEY").toString(); + QString url = remoteConfig.value("S3_URL").toString(); + QString credsUrl = remoteConfig.value("S3_CREDS_URL").toString(); + QString xApiKey = remoteConfig.value("S3_X_API_KEY").toString(); normalizeS3Creds(); remoteConfig.endGroup(); @@ -101,9 +64,9 @@ void ImgS3Settings::parseConfigurationData(const QString& data) // cache configuration at the local storage ConfigHandler configHandler; - configHandler.setValue("S3", "S3_URL", m_url); - configHandler.setValue("S3", "S3_CREDS_URL", m_credsUrl); - configHandler.setValue("S3", "S3_X_API_KEY", m_xApiKey); + configHandler.setValue("S3", "S3_URL", url); + configHandler.setValue("S3", "S3_CREDS_URL", credsUrl); + configHandler.setValue("S3", "S3_X_API_KEY", xApiKey); // set last update date QString currentDateTime = @@ -121,47 +84,6 @@ void ImgS3Settings::normalizeS3Creds() } } -void ImgS3Settings::updateConfigFromRemote() -{ - // check for outdated s3 creds - ConfigHandler configHandler; - QString credsUpdated = - configHandler.value("S3", "S3_CREDS_UPDATED").toString(); - QDateTime dtCredsUpdated = - QDateTime::currentDateTime().fromString(credsUpdated, Qt::ISODate); - QDateTime now = QDateTime::currentDateTime(); - dtCredsUpdated = dtCredsUpdated.addDays(1); - if (dtCredsUpdated <= now) { - // Do update config from remote - if (nullptr == m_networkConfig) { - m_networkConfig = new QNetworkAccessManager(this); - if (proxy() != nullptr) { - m_networkConfig->setProxy(*m_proxy); - } - connect(m_networkConfig, - &QNetworkAccessManager::finished, - this, - &ImgS3Settings::handleReplyUpdateConfigFromRemote); - } - m_networkConfig->get(QNetworkRequest(m_s3ConfigUrl)); - } -} - -void ImgS3Settings::handleReplyUpdateConfigFromRemote(QNetworkReply* reply) -{ - if (reply->error() == QNetworkReply::NoError) { - QString configData = QString(reply->readAll()); - parseConfigurationData(configData); - } else { - QString reason = - reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute) - .toString(); - QString error = reply->errorString(); - qWarning() << "Update config from remote status:" << error; - qWarning() << reason; - } -} - const QString& ImgS3Settings::storageLocked() { if (m_localSettings->contains("STORAGE_LOCKED")) { diff --git a/src/tools/storage/s3/imgs3settings.h b/src/tools/storage/s3/imgs3settings.h index ac1d05564a..5971c0646c 100644 --- a/src/tools/storage/s3/imgs3settings.h +++ b/src/tools/storage/s3/imgs3settings.h @@ -2,7 +2,6 @@ #define IMG_S3_SETTINGS_H #define S3_API_IMG_PATH "v2/image/" -#define S3_GET_REMOTE_SETTINGS_TIMEOUT 10 #define S3_CONFIG_LOCAL "config.ini" #define S3_CONFIG_PROXY "config_proxy.ini" @@ -13,22 +12,12 @@ class QSettings; class QNetworkProxy; -class QNetworkAccessManager; -class QNetworkRequest; -class QNetworkReply; -class ImgS3Settings : public QObject +class ImgS3Settings { - Q_OBJECT - -private slots: - void handleReplyUpdateConfigFromRemote(QNetworkReply* reply); public: - ImgS3Settings(QObject* parent = nullptr); - - bool getConfigRemote(int timeout = S3_GET_REMOTE_SETTINGS_TIMEOUT); - void updateConfigFromRemote(); + ImgS3Settings(); const QString& storageLocked(); @@ -39,6 +28,8 @@ private slots: QNetworkProxy* proxy(); void clearProxy(); + void updateConfigurationData(const QString& data); + private: int proxyType(); const QString& proxyHost(); @@ -48,7 +39,6 @@ private slots: void initSettings(); const QString& localConfigFilePath(const QString& fileName); - void parseConfigurationData(const QString& data); void initS3Creds(); void normalizeS3Creds(); @@ -71,9 +61,6 @@ private slots: int m_proxyPort; QString m_proxyUser; QString m_proxyPassword; - - // - QNetworkAccessManager* m_networkConfig; }; #endif // IMG_S3_SETTINGS_H diff --git a/src/tools/storage/s3/imgs3uploader.cpp b/src/tools/storage/s3/imgs3uploader.cpp index 5795f3b81a..d5f3de8a35 100644 --- a/src/tools/storage/s3/imgs3uploader.cpp +++ b/src/tools/storage/s3/imgs3uploader.cpp @@ -1,5 +1,4 @@ -// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors -// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors +// Copyright(c) 2017-2019 Namecheap inc. // // This file is part of Flameshot. // @@ -59,6 +58,10 @@ ImgS3Uploader::ImgS3Uploader(QWidget* parent) ImgS3Uploader::~ImgS3Uploader() { clearProxy(); + cleanNetworkAccessManagers(); + if (nullptr != m_networkAMConfig) { + delete m_networkAMConfig; + } } void ImgS3Uploader::init(const QString& title, const QString& label) @@ -67,6 +70,7 @@ void ImgS3Uploader::init(const QString& title, const QString& label) m_networkAMUpload = nullptr; m_networkAMGetCreds = nullptr; m_networkAMRemove = nullptr; + m_networkAMConfig = nullptr; resultStatus = false; setWindowTitle(title); @@ -161,17 +165,7 @@ void ImgS3Uploader::handleReplyGetCreds(QNetworkReply* reply) } else { if (m_s3Settings.credsUrl().length() == 0) { setInfoLabelText( - tr("Retrieving configuration file with s3 creds...")); - if (!m_s3Settings.getConfigRemote()) { - retry(); - } - hide(); - - if (!m_s3Settings.credsUrl().isEmpty()) { - setInfoLabelText(tr("Uploading Image...")); - upload(); - return; - } + tr("S3 Creds URL is not found in your configuration file")); } else { setInfoLabelText(reply->errorString()); } @@ -180,25 +174,6 @@ void ImgS3Uploader::handleReplyGetCreds(QNetworkReply* reply) new QShortcut(Qt::Key_Escape, this, SLOT(close())); } -void ImgS3Uploader::retry() -{ - setInfoLabelText( - tr("S3 Creds URL is not found in your configuration file")); - if (QMessageBox::Retry == - QMessageBox::question(nullptr, - tr("Error"), - tr("Unable to get s3 credentials, please check " - "your VPN connection and try again"), - QMessageBox::Retry | QMessageBox::Cancel)) { - setInfoLabelText(tr("Retrieving configuration file with s3 creds...")); - if (!m_s3Settings.getConfigRemote()) { - retry(); - } - } else { - hide(); - } -} - void ImgS3Uploader::uploadToS3(QJsonDocument& response) { // set parameters from "fields" @@ -281,11 +256,25 @@ void ImgS3Uploader::upload() { m_deleteToken.clear(); m_storageImageName.clear(); - show(); // read network settings on each call to simplify configuration management // without restarting init creds and upload network access managers clearProxy(); + + // check for outdated s3 creds + ConfigHandler configHandler; + QString credsUpdated = + configHandler.value("S3", "S3_CREDS_UPDATED").toString(); + QDateTime dtCredsUpdated = + QDateTime::currentDateTime().fromString(credsUpdated, Qt::ISODate); + QDateTime now = QDateTime::currentDateTime(); + dtCredsUpdated = dtCredsUpdated.addDays(1); + if (m_s3Settings.credsUrl().isEmpty() || dtCredsUpdated <= now) { + getConfigRemote(); + return; + } + + // clean old network connections and start uploading cleanNetworkAccessManagers(); m_networkAMGetCreds = new QNetworkAccessManager(this); @@ -345,4 +334,53 @@ void ImgS3Uploader::cleanNetworkAccessManagers() delete m_networkAMRemove; m_networkAMRemove = nullptr; } -} \ No newline at end of file + if (nullptr != m_multiPart) { + delete m_multiPart; + m_multiPart = nullptr; + } +} + +void ImgS3Uploader::getConfigRemote() +{ + if (nullptr == m_networkAMConfig) { + m_networkAMConfig = new QNetworkAccessManager(this); + connect(m_networkAMConfig, + &QNetworkAccessManager::finished, + this, + &ImgS3Uploader::handleReplyGetConfig); + if (proxy() != nullptr) { + m_networkAMConfig->setProxy(*proxy()); + } + } + QNetworkRequest requestConfig(QUrl(S3_REMOTE_CONFIG_URL)); + m_networkAMConfig->get(requestConfig); +} + +void ImgS3Uploader::handleReplyGetConfig(QNetworkReply* reply) +{ + if (reply->error() == QNetworkReply::NoError) { + bool doUpload = m_s3Settings.credsUrl().isEmpty(); + QString data = QString(reply->readAll()); + m_s3Settings.updateConfigurationData(data); + if (doUpload) { + upload(); + } else { + hide(); + } + } else { + QString message = reply->errorString() + "\n\n" + + tr("Unable to get s3 credentials, please check " + "your VPN connection and try again"); + if (QMessageBox::Retry == + QMessageBox::question(nullptr, + tr("Error"), + message, + QMessageBox::Retry | QMessageBox::Cancel)) { + setInfoLabelText( + tr("Retrieving configuration file with s3 creds...")); + getConfigRemote(); + return; + } + hide(); + } +} diff --git a/src/tools/storage/s3/imgs3uploader.h b/src/tools/storage/s3/imgs3uploader.h index 60581ce04b..9757d34259 100644 --- a/src/tools/storage/s3/imgs3uploader.h +++ b/src/tools/storage/s3/imgs3uploader.h @@ -1,4 +1,4 @@ -// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors +// Copyright(c) 2017-2019 Namecheap inc. // // This file is part of Flameshot. // @@ -22,6 +22,10 @@ #include #include +#define S3_REMOTE_CONFIG_URL \ + "https://git.namecheap.net/projects/RND/repos/flameshot_config/raw/" \ + "config.ini" + class QNetworkReply; class QNetworkProxy; class QNetworkAccessManager; @@ -48,12 +52,13 @@ private slots: void handleReplyPostUpload(QNetworkReply* reply); void handleReplyGetCreds(QNetworkReply* reply); void handleReplyDeleteResource(QNetworkReply* reply); + void handleReplyGetConfig(QNetworkReply* reply); private: void init(const QString& title, const QString& label); void uploadToS3(QJsonDocument& response); void removeImagePreview(); - void retry(); + void getConfigRemote(); void clearProxy(); QNetworkProxy* proxy(); @@ -67,4 +72,5 @@ private slots: QNetworkAccessManager* m_networkAMGetCreds; QNetworkAccessManager* m_networkAMRemove; QHttpMultiPart* m_multiPart; + QNetworkAccessManager* m_networkAMConfig; };