nosignal-shell/plugin/src/Caelestia/requests.cpp
八奈見 レイ ffe90bd077
dashboard: add synced lyrics to media tab (#1197)
* lyrics: rewrite model

* lyrics: cleanup code

* lyrics: some minor layouting

* lyrics: add fade shaders

* lyrics: use appearance values from config

* lyrics: formatting

* lyrics: update readme

* lyrics: fix jumping, redo netease backend (resused from another one of projects)

* lyrics: fix netease searches, remove credit lines

* lyrics: add RequestIds

* lyrics: formatting

* lyrics: lyricsDir path cleanup

* lyrics: make empty lines not take up much space

* lyrics: make empty lines not take up any space

* Lyrics: Use QNetworkAccessManager instead of XMLHttpRequest

also added ability to set request headers and ability to reset cookies for requests.cpp

* lyrics: cleanup old code

* lyrics: toggle lyrics by clicking the album art

* lyrics: sanitize non-breaking spaces

* lyrics: add a menu to select lyrics and manually search for them

* lyrics: remove LrcLib backend

* lyrics: change focus to when dashboard is opened instead of the lyricMenu

* lyrics: improve UI

* lyrics: improve UI more ig

* lyrics: extract LyricsView and LyricMenu into separate components

* lyrics: cleanup old files

* lyrics: refactor LyricsService

* lyrics: restore ComponentBehavior: Bound in lyrics components

* lyrics: change SongID to real to fix integer overflow

* lyrics: add animations to the lyricMenu

* lyrics: fix manual search fields not auto updating

* lyrics: fix jerks when switching tracks

* lyrics: create lyrics directory if it doesn't exist

* lyrics: silence logs, fix binding loops, fix index out of range errors

* lyrics: only request keyboard focus when lyric menu is open

* config: add option to enable/disable the lyrics

* format + silence fileview errors

* fix merge

* anim and lsp fixes + format

---------

Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
2026-03-19 22:38:36 +11:00

55 lines
1.7 KiB
C++

#include "requests.hpp"
#include <qnetworkaccessmanager.h>
#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qjsvalueiterator.h>
#include <qnetworkcookiejar.h>
namespace caelestia {
Requests::Requests(QObject* parent)
: QObject(parent)
, m_manager(new QNetworkAccessManager(this)) {}
void Requests::get(const QUrl& url, QJSValue onSuccess, QJSValue onError, QJSValue headers) const {
if (!onSuccess.isCallable()) {
qWarning() << "Requests::get: onSuccess is not callable";
return;
}
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
request.setAttribute(QNetworkRequest::CookieSaveControlAttribute, QNetworkRequest::Manual);
request.setRawHeader("Cache-Control", "no-cache, no-store");
request.setRawHeader("Pragma", "no-cache");
request.setRawHeader("Connection", "close");
if (headers.isObject()) {
QJSValueIterator it(headers);
while (it.hasNext()) {
it.next();
request.setRawHeader(it.name().toUtf8(), it.value().toString().toUtf8());
}
}
auto reply = m_manager->get(request);
QObject::connect(reply, &QNetworkReply::finished, [reply, onSuccess, onError]() {
if (reply->error() == QNetworkReply::NoError) {
onSuccess.call({ QString(reply->readAll()) });
} else if (onError.isCallable()) {
onError.call({ reply->errorString() });
} else {
qWarning() << "Requests::get: request failed with error" << reply->errorString();
}
reply->deleteLater();
});
}
void Requests::resetCookies() const {
m_manager->setCookieJar(new QNetworkCookieJar(m_manager));
}
} // namespace caelestia