aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/content-repo.cpp
blob: 7ae89739a14eb8c9696e470d07670155ba97b100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#include "content-repo.h"

#include <QtCore/QStringBuilder>

using namespace Quotient;

auto queryToUploadContent(const QString& filename)
{
    BaseJob::Query _q;
    addParam<IfNotEmpty>(_q, QStringLiteral("filename"), filename);
    return _q;
}

UploadContentJob::UploadContentJob(QIODevice* content, const QString& filename,
                                   const QString& contentType)
    : BaseJob(HttpVerb::Post, QStringLiteral("UploadContentJob"),
              QStringLiteral("/_matrix/media/r0") % "/upload",
              queryToUploadContent(filename))
{
    setRequestHeader("Content-Type", contentType.toLatin1());
    setRequestData(Data(content));
    addExpectedKey("content_uri");
}

auto queryToGetContent(bool allowRemote)
{
    BaseJob::Query _q;
    addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote);
    return _q;
}

QUrl GetContentJob::makeRequestUrl(QUrl baseUrl, const QString& serverName,
                                   const QString& mediaId, bool allowRemote)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
                                   QStringLiteral("/_matrix/media/r0")
                                       % "/download/" % serverName % "/"
                                       % mediaId,
                                   queryToGetContent(allowRemote));
}

GetContentJob::GetContentJob(const QString& serverName, const QString& mediaId,
                             bool allowRemote)
    : BaseJob(HttpVerb::Get, QStringLiteral("GetContentJob"),
              QStringLiteral("/_matrix/media/r0") % "/download/" % serverName
                  % "/" % mediaId,
              queryToGetContent(allowRemote), {}, false)
{
    setExpectedContentTypes({ "*/*" });
}

auto queryToGetContentOverrideName(bool allowRemote)
{
    BaseJob::Query _q;
    addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote);
    return _q;
}

QUrl GetContentOverrideNameJob::makeRequestUrl(QUrl baseUrl,
                                               const QString& serverName,
                                               const QString& mediaId,
                                               const QString& fileName,
                                               bool allowRemote)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
                                   QStringLiteral("/_matrix/media/r0")
                                       % "/download/" % serverName % "/"
                                       % mediaId % "/" % fileName,
                                   queryToGetContentOverrideName(allowRemote));
}

GetContentOverrideNameJob::GetContentOverrideNameJob(const QString& serverName,
                                                     const QString& mediaId,
                                                     const QString& fileName,
                                                     bool allowRemote)
    : BaseJob(HttpVerb::Get, QStringLiteral("GetContentOverrideNameJob"),
              QStringLiteral("/_matrix/media/r0") % "/download/" % serverName
                  % "/" % mediaId % "/" % fileName,
              queryToGetContentOverrideName(allowRemote), {}, false)
{
    setExpectedContentTypes({ "*/*" });
}

auto queryToGetContentThumbnail(int width, int height, const QString& method,
                                bool allowRemote)
{
    BaseJob::Query _q;
    addParam<>(_q, QStringLiteral("width"), width);
    addParam<>(_q, QStringLiteral("height"), height);
    addParam<IfNotEmpty>(_q, QStringLiteral("method"), method);
    addParam<IfNotEmpty>(_q, QStringLiteral("allow_remote"), allowRemote);
    return _q;
}

QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl,
                                            const QString& serverName,
                                            const QString& mediaId, int width,
                                            int height, const QString& method,
                                            bool allowRemote)
{
    return BaseJob::makeRequestUrl(
        std::move(baseUrl),
        QStringLiteral("/_matrix/media/r0") % "/thumbnail/" % serverName % "/"
            % mediaId,
        queryToGetContentThumbnail(width, height, method, allowRemote));
}

GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName,
                                               const QString& mediaId, int width,
                                               int height, const QString& method,
                                               bool allowRemote)
    : BaseJob(HttpVerb::Get, QStringLiteral("GetContentThumbnailJob"),
              QStringLiteral("/_matrix/media/r0") % "/thumbnail/" % serverName
                  % "/" % mediaId,
              queryToGetContentThumbnail(width, height, method, allowRemote),
              {}, false)
{
    setExpectedContentTypes({ "image/jpeg", "image/png" });
}

auto queryToGetUrlPreview(const QString& url, Omittable<qint64> ts)
{
    BaseJob::Query _q;
    addParam<>(_q, QStringLiteral("url"), url);
    addParam<IfNotEmpty>(_q, QStringLiteral("ts"), ts);
    return _q;
}

QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url,
                                      Omittable<qint64> ts)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
                                   QStringLiteral("/_matrix/media/r0")
                                       % "/preview_url",
                                   queryToGetUrlPreview(url, ts));
}

GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, Omittable<qint64> ts)
    : BaseJob(HttpVerb::Get, QStringLiteral("GetUrlPreviewJob"),
              QStringLiteral("/_matrix/media/r0") % "/preview_url",
              queryToGetUrlPreview(url, ts))
{}

QUrl GetConfigJob::makeRequestUrl(QUrl baseUrl)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
                                   QStringLiteral("/_matrix/media/r0")
                                       % "/config");
}

GetConfigJob::GetConfigJob()
    : BaseJob(HttpVerb::Get, QStringLiteral("GetConfigJob"),
              QStringLiteral("/_matrix/media/r0") % "/config")
{}