Skip to content

Commit

Permalink
fix: add support for custom headers in tag type api
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Dec 14, 2022
1 parent 430a09f commit 7e058b5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/lib/src/tags/tag-api-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ TagApiBase::~TagApiBase()
}
}

void TagApiBase::setUrl(QUrl url)
void TagApiBase::setUrl(QUrl url, QMap<QString, QString> headers)
{
m_url = std::move(url);
m_headers = std::move(headers);
}

void TagApiBase::load(bool rateLimit)
Expand All @@ -34,7 +35,7 @@ void TagApiBase::load(bool rateLimit)
}

Site::QueryType type = rateLimit ? Site::QueryType::Retry : Site::QueryType::List;
m_reply = m_site->get(m_url, type);
m_reply = m_site->get(m_url, type, {}, "", nullptr, m_headers);
connect(m_reply, &NetworkReply::finished, this, &TagApiBase::parseInternal);
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/src/tags/tag-api-base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TAG_API_BASE_H
#define TAG_API_BASE_H

#include <QMap>
#include <QObject>
#include <QUrl>

Expand All @@ -27,7 +28,7 @@ class TagApiBase : public QObject
void load(bool rateLimit = false);

protected:
void setUrl(QUrl url);
void setUrl(QUrl url, QMap<QString, QString> headers = {});
virtual void parse(const QString &source, int statusCode, Site *site) = 0;

public slots:
Expand All @@ -46,6 +47,7 @@ class TagApiBase : public QObject

private:
QUrl m_url;
QMap<QString, QString> m_headers;
NetworkReply *m_reply;
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/tags/tag-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
TagApi::TagApi(Profile *profile, Site *site, Api *api, int page, int limit, const QString &order, QObject *parent)
: TagApiBase(profile, site, api, parent)
{
const QString url = api->tagsUrl(page, limit, order, site).url;
setUrl(site->fixUrl(url));
const auto ret = api->tagsUrl(page, limit, order, site);
setUrl(site->fixUrl(ret.url), ret.headers);
}

void TagApi::parse(const QString &source, int statusCode, Site *site)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/tags/tag-type-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
TagTypeApi::TagTypeApi(Profile *profile, Site *site, Api *api, QObject *parent)
: TagApiBase(profile, site, api, parent)
{
const QString url = api->tagTypesUrl(site).url;
setUrl(site->fixUrl(url));
const auto ret = api->tagTypesUrl(site);
setUrl(site->fixUrl(ret.url), ret.headers);
}

void TagTypeApi::parse(const QString &source, int statusCode, Site *site)
Expand Down

0 comments on commit 7e058b5

Please sign in to comment.