aboutsummaryrefslogtreecommitdiff
path: root/jobs/generated/content-repo.cpp
blob: ec6683bb803bbe925dc73be71f2ff521902dce52 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#include "content-repo.h"

#include "converters.h"

#include <QtNetwork/QNetworkReply>
#include <QtCore/QStringBuilder>

using namespace QMatrixClient;

static const auto basePath = QStringLiteral("/_matrix/media/r0");

class UploadContentJob::Private
{
    public:
        QString contentUri;
};

UploadContentJob::UploadContentJob(QByteArray content, const QString& filename, const QString& contentType)
    : BaseJob(HttpVerb::Post, "UploadContentJob",
        basePath % "/upload")
    , d(new Private)
{
    setRequestHeader("Content-Type", contentType.toLatin1());

    QUrlQuery _q;
    if (!filename.isEmpty())
        _q.addQueryItem("filename", filename);
    setRequestQuery(_q);
    setRequestData(Data(content));
}

UploadContentJob::~UploadContentJob() = default;

const QString& UploadContentJob::contentUri() const
{
    return d->contentUri;
}

BaseJob::Status UploadContentJob::parseJson(const QJsonDocument& data)
{
    auto json = data.object();
    if (!json.contains("content_uri"))
        return { JsonParseError,
            "The key 'content_uri' not found in the response" };
    d->contentUri = fromJson<QString>(json.value("content_uri"));
    return Success;
}

class GetContentJob::Private
{
    public:
        QString contentType;
        QString contentDisposition;
        QByteArray content;
};

GetContentJob::GetContentJob(const QString& serverName, const QString& mediaId)
    : BaseJob(HttpVerb::Get, "GetContentJob",
        basePath % "/download/" % serverName % "/" % mediaId, false)
    , d(new Private)
{
    setExpectedContentTypes({ "*/*" });
}

GetContentJob::~GetContentJob() = default;

const QString& GetContentJob::contentType() const
{
    return d->contentType;
}

const QString& GetContentJob::contentDisposition() const
{
    return d->contentDisposition;
}

QByteArray GetContentJob::content() const
{
    return d->content;
}

BaseJob::Status GetContentJob::parseReply(QNetworkReply* reply)
{
    d->contentType = reply->rawHeader("Content-Type"); 
    d->contentDisposition = reply->rawHeader("Content-Disposition"); 
    d->content = reply->readAll();
    return Success;
}

class GetContentOverrideNameJob::Private
{
    public:
        QString contentType;
        QString contentDisposition;
        QByteArray content;
};

GetContentOverrideNameJob::GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName)
    : BaseJob(HttpVerb::Get, "GetContentOverrideNameJob",
        basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName, false)
    , d(new Private)
{
    setExpectedContentTypes({ "*/*" });
}

GetContentOverrideNameJob::~GetContentOverrideNameJob() = default;

const QString& GetContentOverrideNameJob::contentType() const
{
    return d->contentType;
}

const QString& GetContentOverrideNameJob::contentDisposition() const
{
    return d->contentDisposition;
}

QByteArray GetContentOverrideNameJob::content() const
{
    return d->content;
}

BaseJob::Status GetContentOverrideNameJob::parseReply(QNetworkReply* reply)
{
    d->contentType = reply->rawHeader("Content-Type"); 
    d->contentDisposition = reply->rawHeader("Content-Disposition"); 
    d->content = reply->readAll();
    return Success;
}

class GetContentThumbnailJob::Private
{
    public:
        QString contentType;
        QByteArray content;
};

GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method)
    : BaseJob(HttpVerb::Get, "GetContentThumbnailJob",
        basePath % "/thumbnail/" % serverName % "/" % mediaId, false)
    , d(new Private)
{
    QUrlQuery _q;
    _q.addQueryItem("width", QString("%1").arg(width));
    _q.addQueryItem("height", QString("%1").arg(height));
    if (!method.isEmpty())
        _q.addQueryItem("method", method);
    setRequestQuery(_q);
    setExpectedContentTypes({ "image/jpeg", "image/png" });
}

GetContentThumbnailJob::~GetContentThumbnailJob() = default;

const QString& GetContentThumbnailJob::contentType() const
{
    return d->contentType;
}

QByteArray GetContentThumbnailJob::content() const
{
    return d->content;
}

BaseJob::Status GetContentThumbnailJob::parseReply(QNetworkReply* reply)
{
    d->contentType = reply->rawHeader("Content-Type"); 
    d->content = reply->readAll();
    return Success;
}

class GetUrlPreviewJob::Private
{
    public:
        double matrixImageSize;
        QString ogImage;
};

GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, double ts)
    : BaseJob(HttpVerb::Get, "GetUrlPreviewJob",
        basePath % "/preview_url")
    , d(new Private)
{
    QUrlQuery _q;
    _q.addQueryItem("url", url);
    _q.addQueryItem("ts", QString("%1").arg(ts));
    setRequestQuery(_q);
}

GetUrlPreviewJob::~GetUrlPreviewJob() = default;

double GetUrlPreviewJob::matrixImageSize() const
{
    return d->matrixImageSize;
}

const QString& GetUrlPreviewJob::ogImage() const
{
    return d->ogImage;
}

BaseJob::Status GetUrlPreviewJob::parseJson(const QJsonDocument& data)
{
    auto json = data.object();
    d->matrixImageSize = fromJson<double>(json.value("matrix:image:size"));
    d->ogImage = fromJson<QString>(json.value("og:image"));
    return Success;
}