From 418677ef310ebde9e2ce6fa98e224b6d4d1aa9f4 Mon Sep 17 00:00:00 2001
From: Rachel Powers <508861+Ryex@users.noreply.github.com>
Date: Thu, 1 Jun 2023 20:15:39 -0700
Subject: refactor: override / mask static `make` functions for ApiDownload
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
---
launcher/net/ApiDownload.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 launcher/net/ApiDownload.cpp
(limited to 'launcher/net/ApiDownload.cpp')
diff --git a/launcher/net/ApiDownload.cpp b/launcher/net/ApiDownload.cpp
new file mode 100644
index 00000000..69b39c4a
--- /dev/null
+++ b/launcher/net/ApiDownload.cpp
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "ByteArraySink.h"
+#include "ChecksumValidator.h"
+#include "MetaCacheSink.h"
+#include "net/ApiDownload.h"
+#include "net/NetAction.h"
+
+namespace Net {
+
+auto ApiDownload::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Download::Ptr
+{
+ auto dl = makeShared();
+ dl->m_url = url;
+ dl->setObjectName(QString("CACHE:") + url.toString());
+ dl->m_options = options;
+ auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
+ auto cachedNode = new MetaCacheSink(entry, md5Node, options.testFlag(Option::MakeEternal));
+ dl->m_sink.reset(cachedNode);
+ return dl;
+}
+
+auto ApiDownload::makeByteArray(QUrl url, QByteArray* output, Options options) -> Download::Ptr
+{
+ auto dl = makeShared();
+ dl->m_url = url;
+ dl->setObjectName(QString("BYTES:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new ByteArraySink(output));
+ return dl;
+}
+
+auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download::Ptr
+{
+ auto dl = makeShared();
+ dl->m_url = url;
+ dl->setObjectName(QString("FILE:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new FileSink(path));
+ return dl;
+}
+
+
+void ApiDownload::init()
+{
+ qDebug() << "Setting up api download";
+ auto api_headers = new ApiHeaderProxy();
+ addHeaderProxy(api_headers);
+}
+} // namespace Net
--
cgit
From 6db906d62378a040e55c35f196d208bed7aebbef Mon Sep 17 00:00:00 2001
From: Rachel Powers <508861+Ryex@users.noreply.github.com>
Date: Thu, 1 Jun 2023 20:31:23 -0700
Subject: chore: format
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
---
launcher/net/ApiDownload.cpp | 3 +--
launcher/net/ApiDownload.h | 1 -
launcher/net/ApiHeaderProxy.h | 26 +++++++++++++-------------
launcher/net/HeaderProxy.h | 5 +++--
4 files changed, 17 insertions(+), 18 deletions(-)
(limited to 'launcher/net/ApiDownload.cpp')
diff --git a/launcher/net/ApiDownload.cpp b/launcher/net/ApiDownload.cpp
index 69b39c4a..df476ce8 100644
--- a/launcher/net/ApiDownload.cpp
+++ b/launcher/net/ApiDownload.cpp
@@ -17,10 +17,10 @@
*
*/
+#include "net/ApiDownload.h"
#include "ByteArraySink.h"
#include "ChecksumValidator.h"
#include "MetaCacheSink.h"
-#include "net/ApiDownload.h"
#include "net/NetAction.h"
namespace Net {
@@ -57,7 +57,6 @@ auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download:
return dl;
}
-
void ApiDownload::init()
{
qDebug() << "Setting up api download";
diff --git a/launcher/net/ApiDownload.h b/launcher/net/ApiDownload.h
index 7a1f2e92..4d0a3292 100644
--- a/launcher/net/ApiDownload.h
+++ b/launcher/net/ApiDownload.h
@@ -33,7 +33,6 @@ class ApiDownload : public Download {
static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
void init() override;
-
};
} // namespace Net
diff --git a/launcher/net/ApiHeaderProxy.h b/launcher/net/ApiHeaderProxy.h
index 5de503a6..6fd3e4c1 100644
--- a/launcher/net/ApiHeaderProxy.h
+++ b/launcher/net/ApiHeaderProxy.h
@@ -19,9 +19,9 @@
#pragma once
-#include "net/HeaderProxy.h"
#include "Application.h"
#include "BuildConfig.h"
+#include "net/HeaderProxy.h"
namespace Net {
@@ -31,19 +31,19 @@ class ApiHeaderProxy : public HeaderProxy {
virtual ~ApiHeaderProxy() = default;
public:
- virtual QList headers(const QNetworkRequest& request) const override {
- QList hdrs;
- if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
- hdrs.append({ "x-api-key", APPLICATION->getFlameAPIKey().toUtf8() });
- } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
- request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
- QString token = APPLICATION->getModrinthAPIToken();
- if (!token.isNull())
- hdrs.append({ "Authorization", token.toUtf8() });
- }
- return hdrs;
+ virtual QList headers(const QNetworkRequest& request) const override
+ {
+ QList hdrs;
+ if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
+ hdrs.append({ "x-api-key", APPLICATION->getFlameAPIKey().toUtf8() });
+ } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
+ request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
+ QString token = APPLICATION->getModrinthAPIToken();
+ if (!token.isNull())
+ hdrs.append({ "Authorization", token.toUtf8() });
+ }
+ return hdrs;
};
-
};
} // namespace Net
diff --git a/launcher/net/HeaderProxy.h b/launcher/net/HeaderProxy.h
index bb3c8b03..308455e4 100644
--- a/launcher/net/HeaderProxy.h
+++ b/launcher/net/HeaderProxy.h
@@ -19,8 +19,8 @@
#pragma once
-#include
#include
+#include
namespace Net {
@@ -38,7 +38,8 @@ class HeaderProxy {
virtual QList headers(const QNetworkRequest& request) const = 0;
public:
- void writeHeaders(QNetworkRequest& request) {
+ void writeHeaders(QNetworkRequest& request)
+ {
for (auto header : headers(request)) {
request.setRawHeader(header.headerName, header.headerValue);
}
--
cgit