libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
authed-content-repo.h
Go to the documentation of this file.
1// THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2
3#pragma once
4
5#include <Quotient/jobs/basejob.h>
6
7#include <QtCore/QIODevice>
8#include <QtNetwork/QNetworkReply>
9
10namespace Quotient {
11
12//! \brief Download content from the content repository.
13//!
14//! \note
15//! Clients SHOULD NOT generate or use URLs which supply the access token in
16//! the query string. These URLs may be copied by users verbatim and provided
17//! in a chat message to another user, disclosing the sender's access token.
18//!
19//! Clients MAY be redirected using the 307/308 responses below to download
20//! the request object. This is typical when the homeserver uses a Content
21//! Delivery Network (CDN).
23public:
24 //! \param serverName
25 //! The server name from the `mxc://` URI (the authority component).
26 //!
27 //! \param mediaId
28 //! The media ID from the `mxc://` URI (the path component).
29 //!
30 //! \param timeoutMs
31 //! The maximum number of milliseconds that the client is willing to wait to
32 //! start receiving data, in the case that the content has not yet been
33 //! uploaded. The default value is 20000 (20 seconds). The content
34 //! repository SHOULD impose a maximum value for this parameter. The
35 //! content repository MAY respond before the timeout.
37 qint64 timeoutMs = 20000);
38
39 //! \brief Construct a URL without creating a full-fledged job object
40 //!
41 //! This function can be used when a URL for GetContentAuthedJob
42 //! is necessary but the job itself isn't.
44 const QString& mediaId, qint64 timeoutMs = 20000);
45
46 // Result properties
47
48 //! The content type of the file that was previously uploaded.
49 //!
50 //! The server MUST return a `Content-Type` which is either exactly the same
51 //! as the original upload, or reasonably close. The bounds of "reasonable"
52 //! are:
53 //!
54 //! * Adding a charset to `text/*` content types.
55 //! * Detecting HTML and using `text/html` instead of `text/plain`.
56 //! * Using `application/octet-stream` when the server determines the
57 //! content type is obviously wrong. For example, an encrypted file being
58 //! claimed as `image/png`.
59 //! * Returning `application/octet-stream` when the media has an
60 //! unknown/unprovided `Content-Type`. For example, being uploaded before
61 //! the server tracked content types or when the remote server is
62 //! non-compliantly omitting the header entirely.
63 //!
64 //! Actions not in the spirit of the above are not considered "reasonable".
65 QString contentType() const { return QString::fromUtf8(reply()->rawHeader("Content-Type")); }
66
67 //! The
68 //! [disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
69 //! of the returned content. MUST be one of `inline` or `attachment`,
70 //! and SHOULD contain a file name.
71 //!
72 //! If the `Content-Type` is allowed in the [restrictions for serving
73 //! inline content](/client-server-api/#serving-inline-content),
74 //! servers SHOULD use `inline`, otherwise they SHOULD use
75 //! `attachment`.
76 //!
77 //! If the upload was made with a `filename`, this header MUST
78 //! contain the same `filename`. Otherwise, `filename` is excluded
79 //! from the header. If the media being downloaded is remote, the
80 //! remote server's `filename` in the `Content-Disposition` header
81 //! is used as the `filename` instead. When the header is not
82 //! supplied, or does not supply a `filename`, the local download
83 //! response does not include a `filename`.
85 {
86 return QString::fromUtf8(reply()->rawHeader("Content-Disposition"));
87 }
88
89 //! The content that was previously uploaded.
90 QIODevice* data() { return reply(); }
91};
92
93//! \brief Download content from the content repository overriding the file name.
94//!
95//! This will download content from the content repository (same as
96//! the previous endpoint) but replaces the target file name with the one
97//! provided by the caller.
98//!
99//! \note
100//! Clients SHOULD NOT generate or use URLs which supply the access token in
101//! the query string. These URLs may be copied by users verbatim and provided
102//! in a chat message to another user, disclosing the sender's access token.
103//!
104//! Clients MAY be redirected using the 307/308 responses below to download
105//! the request object. This is typical when the homeserver uses a Content
106//! Delivery Network (CDN).
108public:
109 //! \param serverName
110 //! The server name from the `mxc://` URI (the authority component).
111 //!
112 //! \param mediaId
113 //! The media ID from the `mxc://` URI (the path component).
114 //!
115 //! \param fileName
116 //! A filename to give in the `Content-Disposition` header.
117 //!
118 //! \param timeoutMs
119 //! The maximum number of milliseconds that the client is willing to wait to
120 //! start receiving data, in the case that the content has not yet been
121 //! uploaded. The default value is 20000 (20 seconds). The content
122 //! repository SHOULD impose a maximum value for this parameter. The
123 //! content repository MAY respond before the timeout.
125 const QString& fileName, qint64 timeoutMs = 20000);
126
127 //! \brief Construct a URL without creating a full-fledged job object
128 //!
129 //! This function can be used when a URL for GetContentOverrideNameAuthedJob
130 //! is necessary but the job itself isn't.
132 const QString& mediaId, const QString& fileName,
133 qint64 timeoutMs = 20000);
134
135 // Result properties
136
137 //! The content type of the file that was previously uploaded.
138 //!
139 //! The server MUST return a `Content-Type` which is either exactly the same
140 //! as the original upload, or reasonably close. The bounds of "reasonable"
141 //! are:
142 //!
143 //! * Adding a charset to `text/*` content types.
144 //! * Detecting HTML and using `text/html` instead of `text/plain`.
145 //! * Using `application/octet-stream` when the server determines the
146 //! content type is obviously wrong. For example, an encrypted file being
147 //! claimed as `image/png`.
148 //! * Returning `application/octet-stream` when the media has an
149 //! unknown/unprovided `Content-Type`. For example, being uploaded before
150 //! the server tracked content types or when the remote server is
151 //! non-compliantly omitting the header entirely.
152 //!
153 //! Actions not in the spirit of the above are not considered "reasonable".
154 QString contentType() const { return QString::fromUtf8(reply()->rawHeader("Content-Type")); }
155
156 //! The
157 //! [disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
158 //! of the returned content. MUST be one of `inline` or `attachment`,
159 //! and MUST contain the file name requested in the path.
160 //!
161 //! If the `Content-Type` is allowed in the [restrictions for serving
162 //! inline content](/client-server-api/#serving-inline-content),
163 //! servers SHOULD use `inline`, otherwise they SHOULD use
164 //! `attachment`.
166 {
167 return QString::fromUtf8(reply()->rawHeader("Content-Disposition"));
168 }
169
170 //! The content that was previously uploaded.
171 QIODevice* data() { return reply(); }
172};
173
174//! \brief Download a thumbnail of content from the content repository
175//!
176//! Download a thumbnail of content from the content repository.
177//! See the [Thumbnails](/client-server-api/#thumbnails) section for more information.
178//!
179//! \note
180//! Clients SHOULD NOT generate or use URLs which supply the access token in
181//! the query string. These URLs may be copied by users verbatim and provided
182//! in a chat message to another user, disclosing the sender's access token.
183//!
184//! Clients MAY be redirected using the 307/308 responses below to download
185//! the request object. This is typical when the homeserver uses a Content
186//! Delivery Network (CDN).
188public:
189 //! \param serverName
190 //! The server name from the `mxc://` URI (the authority component).
191 //!
192 //! \param mediaId
193 //! The media ID from the `mxc://` URI (the path component).
194 //!
195 //! \param width
196 //! The *desired* width of the thumbnail. The actual thumbnail may be
197 //! larger than the size specified.
198 //!
199 //! \param height
200 //! The *desired* height of the thumbnail. The actual thumbnail may be
201 //! larger than the size specified.
202 //!
203 //! \param method
204 //! The desired resizing method. See the [Thumbnails](/client-server-api/#thumbnails)
205 //! section for more information.
206 //!
207 //! \param timeoutMs
208 //! The maximum number of milliseconds that the client is willing to wait to
209 //! start receiving data, in the case that the content has not yet been
210 //! uploaded. The default value is 20000 (20 seconds). The content
211 //! repository SHOULD impose a maximum value for this parameter. The
212 //! content repository MAY respond before the timeout.
213 //!
214 //! \param animated
215 //! Indicates preference for an animated thumbnail from the server, if possible. Animated
216 //! thumbnails typically use the content types `image/gif`, `image/png` (with APNG format),
217 //! `image/apng`, and `image/webp` instead of the common static `image/png` or `image/jpeg`
218 //! content types.
219 //!
220 //! When `true`, the server SHOULD return an animated thumbnail if possible and supported.
221 //! When `false`, the server MUST NOT return an animated thumbnail. For example, returning a
222 //! static `image/png` or `image/jpeg` thumbnail. When not provided, the server SHOULD NOT
223 //! return an animated thumbnail.
224 //!
225 //! Servers SHOULD prefer to return `image/webp` thumbnails when supporting animation.
226 //!
227 //! When `true` and the media cannot be animated, such as in the case of a JPEG or PDF, the
228 //! server SHOULD behave as though `animated` is `false`.
230 int width, int height, const QString& method = {},
231 qint64 timeoutMs = 20000,
232 std::optional<bool> animated = std::nullopt);
233
234 //! \brief Construct a URL without creating a full-fledged job object
235 //!
236 //! This function can be used when a URL for GetContentThumbnailAuthedJob
237 //! is necessary but the job itself isn't.
239 const QString& mediaId, int width, int height,
240 const QString& method = {}, qint64 timeoutMs = 20000,
241 std::optional<bool> animated = std::nullopt);
242
243 // Result properties
244
245 //! The
246 //! [disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
247 //! of the returned content. MUST be `inline`, and SHOULD contain a file name (e.g.
248 //! `thumbnail.png`).
249 //!
250 //! Servers should note the [Content-Type restrictions for serving inline
251 //! content](/client-server-api/#serving-inline-content), as these limitations imply which
252 //! formats should be used for thumbnail generation.
254 {
255 return QString::fromUtf8(reply()->rawHeader("Content-Disposition"));
256 }
257
258 //! The content type of the thumbnail.
259 QString contentType() const { return QString::fromUtf8(reply()->rawHeader("Content-Type")); }
260
261 //! A thumbnail of the requested content.
262 QIODevice* data() { return reply(); }
263};
264
265//! \brief Get information about a URL for a client
266//!
267//! Get information about a URL for the client. Typically this is called when a
268//! client sees a URL in a message and wants to render a preview for the user.
269//!
270//! \note
271//! Clients should consider avoiding this endpoint for URLs posted in encrypted
272//! rooms. Encrypted rooms often contain more sensitive information the users
273//! do not want to share with the homeserver, and this can mean that the URLs
274//! being shared should also not be shared with the homeserver.
276public:
277 //! \param url
278 //! The URL to get a preview of.
279 //!
280 //! \param ts
281 //! The preferred point in time to return a preview for. The server may
282 //! return a newer version if it does not have the requested version
283 //! available.
285
286 //! \brief Construct a URL without creating a full-fledged job object
287 //!
288 //! This function can be used when a URL for GetUrlPreviewAuthedJob
289 //! is necessary but the job itself isn't.
292
293 // Result properties
294
295 //! The byte-size of the image. Omitted if there is no image attached.
297 {
298 return loadFromJson<std::optional<qint64>>("matrix:image:size"_L1);
299 }
300
301 //! An [`mxc://` URI](/client-server-api/#matrix-content-mxc-uris) to the image. Omitted if
302 //! there is no image.
303 QUrl ogImage() const { return loadFromJson<QUrl>("og:image"_L1); }
304
305 struct Response {
306 //! The byte-size of the image. Omitted if there is no image attached.
308
309 //! An [`mxc://` URI](/client-server-api/#matrix-content-mxc-uris) to the image. Omitted if
310 //! there is no image.
312 };
313};
314
316constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetUrlPreviewAuthedJob::Response {
317 return { j->matrixImageSize(), j->ogImage() };
318};
319
320//! \brief Get the configuration for the content repository.
321//!
322//! This endpoint allows clients to retrieve the configuration of the content
323//! repository, such as upload limitations.
324//! Clients SHOULD use this as a guide when using content repository endpoints.
325//! All values are intentionally left optional. Clients SHOULD follow
326//! the advice given in the field description when the field is not available.
327//!
328//! \note
329//! Both clients and server administrators should be aware that proxies
330//! between the client and the server may affect the apparent behaviour of content
331//! repository APIs, for example, proxies may enforce a lower upload size limit
332//! than is advertised by the server on this endpoint.
334public:
336
337 //! \brief Construct a URL without creating a full-fledged job object
338 //!
339 //! This function can be used when a URL for GetConfigAuthedJob
340 //! is necessary but the job itself isn't.
342
343 // Result properties
344
345 //! The maximum size an upload can be in bytes.
346 //! Clients SHOULD use this as a guide when uploading content.
347 //! If not listed or null, the size limit should be treated as unknown.
349 {
350 return loadFromJson<std::optional<qint64>>("m.upload.size"_L1);
351 }
352};
353
354inline auto collectResponse(const GetConfigAuthedJob* job) { return job->uploadSize(); }
355
356} // namespace Quotient
Get the configuration for the content repository.
Download content from the content repository.
Download content from the content repository overriding the file name.
Download a thumbnail of content from the content repository.
Get information about a URL for a client.
auto collectResponse(const GetAccountDataJob *job)
#define QUOTIENT_API