Page MenuHomePhorge

D216.1750656349.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D216.1750656349.diff

diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
--- a/src/base/CMakeLists.txt
+++ b/src/base/CMakeLists.txt
@@ -8,6 +8,7 @@
event.cpp
basejob.cpp
file-desc.cpp
+ get-content-job-v1.cpp
)
add_library(kazvbase ${kazvbase_SRCS})
diff --git a/src/base/get-content-job-v1.hpp b/src/base/get-content-job-v1.hpp
new file mode 100644
--- /dev/null
+++ b/src/base/get-content-job-v1.hpp
@@ -0,0 +1,28 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2025 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "basejob.hpp"
+#include "file-desc.hpp"
+
+#include <string>
+#include <optional>
+
+namespace Kazv {
+ class GetContentJobV1 : public Kazv::BaseJob
+ {
+ public:
+ explicit GetContentJobV1(std::string serverUrl, std::string token,
+ std::string serverName, std::string mediaId,
+ bool allowRemote = true,
+ std::optional<FileDesc> downloadTo = std::nullopt);
+
+ static BaseJob::Query buildQuery(bool allowRemote);
+ static constexpr auto needsAuth()
+ {
+ return true;
+ }
+ };
+}
diff --git a/src/base/get-content-job-v1.cpp b/src/base/get-content-job-v1.cpp
new file mode 100644
--- /dev/null
+++ b/src/base/get-content-job-v1.cpp
@@ -0,0 +1,32 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2025 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "get-content-job-v1.hpp"
+#include "basejob.hpp"
+
+#include <string>
+#include <utility>
+
+using namespace std::literals::string_literals;
+
+namespace Kazv
+{
+ GetContentJobV1::GetContentJobV1(std::string serverUrl, std::string token,
+ std::string serverName, std::string mediaId, bool allowRemote,
+ std::optional<FileDesc> downloadTo)
+ : BaseJob(std::move(serverUrl),
+ "/_matrix/client/v1/media/download/"s + serverName + "/" + mediaId,
+ GET, "GetContent"s, token, ReturnType::File, BaseJob::EmptyBody{},
+ buildQuery(allowRemote), {}, downloadTo)
+ {}
+
+ BaseJob::Query GetContentJobV1::buildQuery(bool allowRemote)
+ {
+ BaseJob::Query query;
+ addToQueryIfNeeded(query, "allow_remotes"s, allowRemote);
+ return query;
+ }
+}
diff --git a/src/client/client.hpp b/src/client/client.hpp
--- a/src/client/client.hpp
+++ b/src/client/client.hpp
@@ -17,6 +17,7 @@
#include "client/client-model.hpp"
#include "client/actions/content.hpp"
#include "sdk-model-cursor-tag.hpp"
+#include "get-content-job-v1.hpp"
#include "room/room.hpp"
#include "notification-handler.hpp"
@@ -372,6 +373,24 @@
.make(serverName, mediaId).url();
}
+ /**
+ * Convert a MXC URI to an HTTP(s) URI that needs Authorization.
+ *
+ * The converted URI will be using the homeserver of
+ * this Client.
+ *
+ * @param mxcUri The MXC URI to convert.
+ * @return The HTTP(s) URI that has the content indicated
+ * by `mxcUri`.
+ */
+ inline std::string mxcUriToHttpV1(std::string mxcUri) const {
+ using namespace CursorOp;
+ auto [serverName, mediaId] = mxcUriToMediaDesc(mxcUri);
+ return (+clientCursor())
+ .template job<GetContentJobV1>()
+ .make(serverName, mediaId).url();
+ }
+
/**
* Download content from the content repository
*

File Metadata

Mime Type
text/plain
Expires
Sun, Jun 22, 10:25 PM (16 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
234568
Default Alt Text
D216.1750656349.diff (3 KB)

Event Timeline