Add controllers to provide comics information from reading lists and labels

This commit is contained in:
Luis Ángel San Martín 2018-05-01 11:54:00 +02:00
parent 0e45767e67
commit d3bb598a7d
6 changed files with 173 additions and 29 deletions

View File

@ -0,0 +1,43 @@
#include "readinglistinfocontroller_v2.h"
#include "db_helper.h"
#include "folder.h"
#include "comic_db.h"
#include "template.h"
#include "../static.h"
ReadingListInfoControllerV2::ReadingListInfoControllerV2(){}
void ReadingListInfoControllerV2::service(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Content-Type", "text/plain; charset=utf-8");
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
int libraryId = pathElements.at(3).toInt();
QString libraryName = DBHelper::getLibraryName(libraryId);
qulonglong listId = pathElements.at(5).toULongLong();
serviceComics(libraryId, listId, response);
response.write("",true);
}
void ReadingListInfoControllerV2::serviceComics(const int &library, const qulonglong &readingListId, HttpResponse &response)
{
QList<ComicDB> comics = DBHelper::getReadingListFullContent(library, readingListId);
for(const ComicDB &comic : comics)
{
response.write(QString("/v2/library/%1/comic/%2:%3:%4:%5:%6\r\n")
.arg(library)
.arg(comic.id)
.arg(comic.getFileName())
.arg(comic.getFileSize())
.arg(comic.info.read ? 1 : 0)
.arg(comic.info.hash)
.toUtf8());
}
}

View File

@ -0,0 +1,22 @@
#ifndef READINGLISTINFOCONTROLLER_V2_H
#define READINGLISTINFOCONTROLLER_V2_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class ReadingListInfoControllerV2 : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(ReadingListInfoControllerV2)
public:
ReadingListInfoControllerV2();
void service(HttpRequest& request, HttpResponse& response);
private:
void serviceComics(const int &library, const qulonglong & readingListId, HttpResponse& response);
};
#endif // READINGLISTINFOCONTROLLER_V2_H

View File

@ -0,0 +1,43 @@
#include "taginfocontroller_v2.h"
#include "db_helper.h"
#include "folder.h"
#include "comic_db.h"
#include "template.h"
#include "../static.h"
TagInfoControllerV2::TagInfoControllerV2() {}
void TagInfoControllerV2::service(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Content-Type", "text/plain; charset=utf-8");
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
int libraryId = pathElements.at(3).toInt();
QString libraryName = DBHelper::getLibraryName(libraryId);
qulonglong listId = pathElements.at(5).toULongLong();
serviceComics(libraryId, listId, response);
response.write("",true);
}
void TagInfoControllerV2::serviceComics(const int &library, const qulonglong &tagId, HttpResponse &response)
{
QList<ComicDB> comics = DBHelper::getLabelComics(library, tagId);
for(const ComicDB &comic : comics)
{
response.write(QString("/v2/library/%1/comic/%2:%3:%4:%5:%6\r\n")
.arg(library)
.arg(comic.id)
.arg(comic.getFileName())
.arg(comic.getFileSize())
.arg(comic.info.read ? 1 : 0)
.arg(comic.info.hash)
.toUtf8());
}
}

View File

@ -0,0 +1,20 @@
#ifndef TAGINFOCONTROLLER_V2_H
#define TAGINFOCONTROLLER_V2_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class TagInfoControllerV2 : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(TagInfoControllerV2)
public:
TagInfoControllerV2();
void service(HttpRequest& request, HttpResponse& response);
private:
void serviceComics(const int &library, const qulonglong & tagId, HttpResponse& response);
};
#endif // TAGINFOCONTROLLER_V2_H

View File

@ -32,10 +32,12 @@
#include "controllers/v2/foldercontentcontroller_v2.h"
#include "controllers/v2/tagscontroller_v2.h"
#include "controllers/v2/tagcontentcontroller_v2.h"
#include "controllers/v2/taginfocontroller_v2.h"
#include "controllers/v2/favoritescontroller_v2.h"
#include "controllers/v2/readingcomicscontroller_v2.h"
#include "controllers/v2/readinglistscontroller_v2.h"
#include "controllers/v2/readinglistcontentcontroller_v2.h"
#include "controllers/v2/readinglistinfocontroller_v2.h"
#include "controllers/v2/comicfullinfocontroller_v2.h"
#include "db_helper.h"
@ -44,16 +46,16 @@
#include "yacreader_http_session.h"
#include "QsLog.h"
QMutex RequestMapper::mutex;
QMutex RequestMapper::mutex;
RequestMapper::RequestMapper(QObject* parent)
:HttpRequestHandler(parent) {}
void RequestMapper::loadSessionV1(HttpRequest & request, HttpResponse& response)
{
QMutexLocker locker(&mutex);
{
QMutexLocker locker(&mutex);
HttpSession session=Static::sessionStore->getSession(request,response);
if(session.contains("ySession")) //session is already alive check if it is needed to update comics
@ -117,31 +119,31 @@ void RequestMapper::loadSessionV1(HttpRequest & request, HttpResponse& response)
}
}
}
void RequestMapper::loadSessionV2(HttpRequest & request, HttpResponse& response)
{
QMutexLocker locker(&mutex);
QByteArray token = request.getHeader("x-request-id");
if (token.isEmpty()) {
return;
}
YACReaderHttpSession *yRecoveredSession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
if(yRecoveredSession == nullptr) //session is already alive check if it is needed to update comics
{
YACReaderHttpSession *ySession = new YACReaderHttpSession(this);
Static::yacreaderSessionStore->addYACReaderHttpSession(token, ySession);
}
}
void RequestMapper::loadSessionV2(HttpRequest & request, HttpResponse& response)
{
QMutexLocker locker(&mutex);
QByteArray token = request.getHeader("x-request-id");
if (token.isEmpty()) {
return;
}
YACReaderHttpSession *yRecoveredSession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
if(yRecoveredSession == nullptr) //session is already alive check if it is needed to update comics
{
YACReaderHttpSession *ySession = new YACReaderHttpSession(this);
Static::yacreaderSessionStore->addYACReaderHttpSession(token, ySession);
}
}
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
QByteArray path=request.getPath();
QByteArray path=request.getPath();
QLOG_TRACE() << "RequestMapper: path=" << path.data();
QLOG_TRACE() << "X-Request-Id: " << request.getHeader("x-request-id");
@ -260,8 +262,10 @@ void RequestMapper::serviceV2(HttpRequest& request, HttpResponse& response)
QRegExp reading("/v2/library/.+/reading/?");
QRegExp tags("/v2/library/.+/tags/?");
QRegExp tagContent("/v2/library/.+/tag/[0-9]+/content/?");
QRegExp tagInfo("/v2/library/.+/tag/[0-9]+/info/?");
QRegExp readingLists("/v2/library/.+/reading_lists/?");
QRegExp readingListContent("/v2/library/.+/reading_list/[0-9]+/content/?");
QRegExp readingListInfo("/v2/library/.+/reading_list/[0-9]+/info/?");
QRegExp sync("/v2/sync");
@ -345,6 +349,14 @@ void RequestMapper::serviceV2(HttpRequest& request, HttpResponse& response)
{
ReadingListContentControllerV2().service(request, response);
}
else if(readingListInfo.exactMatch(path))
{
ReadingListInfoControllerV2().service(request, response);
}
else if(tagInfo.exactMatch(path))
{
TagInfoControllerV2().service(request, response);
}
}
else
{

View File

@ -44,7 +44,9 @@ HEADERS += \
$$PWD/controllers/v2/readingcomicscontroller_v2.h \
$$PWD/controllers/v2/readinglistscontroller_v2.h \
$$PWD/controllers/v2/readinglistcontentcontroller_v2.h \
$$PWD/controllers/v2/comicfullinfocontroller_v2.h
$$PWD/controllers/v2/comicfullinfocontroller_v2.h \
$$PWD/controllers/v2/readinglistinfocontroller_v2.h \
$$PWD/controllers/v2/taginfocontroller_v2.h
SOURCES += \
@ -83,7 +85,9 @@ SOURCES += \
$$PWD/controllers/v2/readingcomicscontroller_v2.cpp \
$$PWD/controllers/v2/readinglistscontroller_v2.cpp \
$$PWD/controllers/v2/readinglistcontentcontroller_v2.cpp \
$$PWD/controllers/v2/comicfullinfocontroller_v2.cpp
$$PWD/controllers/v2/comicfullinfocontroller_v2.cpp \
$$PWD/controllers/v2/readinglistinfocontroller_v2.cpp \
$$PWD/controllers/v2/taginfocontroller_v2.cpp
include(lib/logging/logging.pri)