mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 04:54:29 -04:00
Add .gitattributes rules for text and binary handling
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
#include "comiccontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ComicControllerV2::ComicControllerV2() {}
|
||||
|
||||
void ComicControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
#include "comiccontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ComicControllerV2::ComicControllerV2() {}
|
||||
|
||||
void ComicControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
QByteArray token = request.getHeader("x-request-id");
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
|
||||
@ -26,102 +26,102 @@ void ComicControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
response.write("404 not found",true);
|
||||
return;
|
||||
}
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(3).toLongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
bool remoteComic = path.endsWith("remote");
|
||||
|
||||
//TODO
|
||||
//if(pathElements.size() == 6)
|
||||
//{
|
||||
// QString action = pathElements.at(5);
|
||||
// if(!action.isEmpty() && (action == "close"))
|
||||
// {
|
||||
// session.dismissCurrentComic();
|
||||
// response.write("",true);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(comicFile != NULL)
|
||||
{
|
||||
QThread * thread = NULL;
|
||||
|
||||
thread = new QThread();
|
||||
|
||||
comicFile->moveToThread(thread);
|
||||
|
||||
connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
|
||||
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
comicFile->load(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
|
||||
if(remoteComic)
|
||||
{
|
||||
QLOG_TRACE() << "remote comic requested";
|
||||
ySession->setCurrentRemoteComic(comic.id, comicFile);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "comic requested";
|
||||
ySession->setCurrentComic(comic.id, comicFile);
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
//TODO this field is not used by the client!
|
||||
response.write(QString("library:%1\r\n").arg(libraryName).toUtf8());
|
||||
response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8());
|
||||
if(remoteComic) //send previous and next comics id
|
||||
{
|
||||
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryId, comic.parentId, true);
|
||||
bool found = false;
|
||||
int i;
|
||||
for(i = 0; i < siblings.length(); i++)
|
||||
{
|
||||
if (siblings.at(i)->id == comic.id)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
if(i>0)
|
||||
response.write(QString("previousComic:%1\r\n").arg(siblings.at(i-1)->id).toUtf8());
|
||||
if(i<siblings.length()-1)
|
||||
response.write(QString("nextComic:%1\r\n").arg(siblings.at(i+1)->id).toUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR
|
||||
}
|
||||
qDeleteAll(siblings);
|
||||
}
|
||||
response.write(comic.toTXT().toUtf8(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//delete comicFile;
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(3).toLongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
bool remoteComic = path.endsWith("remote");
|
||||
|
||||
//TODO
|
||||
//if(pathElements.size() == 6)
|
||||
//{
|
||||
// QString action = pathElements.at(5);
|
||||
// if(!action.isEmpty() && (action == "close"))
|
||||
// {
|
||||
// session.dismissCurrentComic();
|
||||
// response.write("",true);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(comicFile != NULL)
|
||||
{
|
||||
QThread * thread = NULL;
|
||||
|
||||
thread = new QThread();
|
||||
|
||||
comicFile->moveToThread(thread);
|
||||
|
||||
connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
|
||||
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
comicFile->load(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
|
||||
if(remoteComic)
|
||||
{
|
||||
QLOG_TRACE() << "remote comic requested";
|
||||
ySession->setCurrentRemoteComic(comic.id, comicFile);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "comic requested";
|
||||
ySession->setCurrentComic(comic.id, comicFile);
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
//TODO this field is not used by the client!
|
||||
response.write(QString("library:%1\r\n").arg(libraryName).toUtf8());
|
||||
response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8());
|
||||
if(remoteComic) //send previous and next comics id
|
||||
{
|
||||
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryId, comic.parentId, true);
|
||||
bool found = false;
|
||||
int i;
|
||||
for(i = 0; i < siblings.length(); i++)
|
||||
{
|
||||
if (siblings.at(i)->id == comic.id)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
if(i>0)
|
||||
response.write(QString("previousComic:%1\r\n").arg(siblings.at(i-1)->id).toUtf8());
|
||||
if(i<siblings.length()-1)
|
||||
response.write(QString("nextComic:%1\r\n").arg(siblings.at(i+1)->id).toUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR
|
||||
}
|
||||
qDeleteAll(siblings);
|
||||
}
|
||||
response.write(comic.toTXT().toUtf8(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//delete comicFile;
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
#ifndef COMICCONTROLLER_V2_H
|
||||
#define COMICCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
#include <QThread>
|
||||
class Comic;
|
||||
class QString;
|
||||
|
||||
class ComicControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
ComicControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICCONTROLLER_H
|
||||
#ifndef COMICCONTROLLER_V2_H
|
||||
#define COMICCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
#include <QThread>
|
||||
class Comic;
|
||||
class QString;
|
||||
|
||||
class ComicControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
ComicControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICCONTROLLER_H
|
||||
|
@ -1,28 +1,28 @@
|
||||
#include "comicdownloadinfocontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
|
||||
ComicDownloadInfoControllerV2::ComicDownloadInfoControllerV2() {}
|
||||
|
||||
|
||||
void ComicDownloadInfoControllerV2::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('/');
|
||||
|
||||
qulonglong libraryId = pathElements.at(3).toLongLong();
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
//TODO: check if the comic wasn't found;
|
||||
response.write(QString("fileName:%1\r\n").arg(comic.getFileName()).toUtf8());
|
||||
response.write(QString("fileSize:%1\r\n").arg(comic.getFileSize()).toUtf8());
|
||||
response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8());
|
||||
response.write(comic.toTXT().toUtf8(),true);
|
||||
}
|
||||
#include "comicdownloadinfocontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
|
||||
ComicDownloadInfoControllerV2::ComicDownloadInfoControllerV2() {}
|
||||
|
||||
|
||||
void ComicDownloadInfoControllerV2::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('/');
|
||||
|
||||
qulonglong libraryId = pathElements.at(3).toLongLong();
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
//TODO: check if the comic wasn't found;
|
||||
response.write(QString("fileName:%1\r\n").arg(comic.getFileName()).toUtf8());
|
||||
response.write(QString("fileSize:%1\r\n").arg(comic.getFileSize()).toUtf8());
|
||||
response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8());
|
||||
response.write(comic.toTXT().toUtf8(),true);
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
#ifndef COMICDOWNLOADINFOCONTROLLER_V2_H
|
||||
#define COMICDOWNLOADINFOCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ComicDownloadInfoControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicDownloadInfoControllerV2)
|
||||
public:
|
||||
/** Constructor **/
|
||||
ComicDownloadInfoControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICDOWNLOADINFOCONTROLLER_H
|
||||
#ifndef COMICDOWNLOADINFOCONTROLLER_V2_H
|
||||
#define COMICDOWNLOADINFOCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ComicDownloadInfoControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicDownloadInfoControllerV2)
|
||||
public:
|
||||
/** Constructor **/
|
||||
ComicDownloadInfoControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICDOWNLOADINFOCONTROLLER_H
|
||||
|
@ -1,46 +1,46 @@
|
||||
#include "comicfullinfocontroller_v2.h"
|
||||
|
||||
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
ComicFullinfoController_v2::ComicFullinfoController_v2() {}
|
||||
|
||||
void ComicFullinfoController_v2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, comicId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulonglong &comicId, HttpResponse &response)
|
||||
{
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, comic);
|
||||
|
||||
QJsonDocument output(json);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
#include "comicfullinfocontroller_v2.h"
|
||||
|
||||
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
ComicFullinfoController_v2::ComicFullinfoController_v2() {}
|
||||
|
||||
void ComicFullinfoController_v2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, comicId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulonglong &comicId, HttpResponse &response)
|
||||
{
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, comic);
|
||||
|
||||
QJsonDocument output(json);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
#ifndef COMICFULLINFOCONTROLLER_V2_H
|
||||
#define COMICFULLINFOCONTROLLER_V2_H
|
||||
|
||||
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
|
||||
class ComicFullinfoController_v2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicFullinfoController_v2)
|
||||
public:
|
||||
ComicFullinfoController_v2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &comicId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // COMICFULLINFOCONTROLLER_V2_H
|
||||
#ifndef COMICFULLINFOCONTROLLER_V2_H
|
||||
#define COMICFULLINFOCONTROLLER_V2_H
|
||||
|
||||
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
|
||||
class ComicFullinfoController_v2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicFullinfoController_v2)
|
||||
public:
|
||||
ComicFullinfoController_v2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &comicId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // COMICFULLINFOCONTROLLER_V2_H
|
||||
|
@ -1,36 +1,36 @@
|
||||
#include "covercontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
CoverControllerV2::CoverControllerV2() {}
|
||||
|
||||
void CoverControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(3).toInt());
|
||||
QString fileName = pathElements.at(5);
|
||||
|
||||
QImage img(libraries.getPath(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
if (!img.isNull()) {
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
img.save(&buffer, "JPG");
|
||||
response.write(ba,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
|
||||
#include "covercontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
CoverControllerV2::CoverControllerV2() {}
|
||||
|
||||
void CoverControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(3).toInt());
|
||||
QString fileName = pathElements.at(5);
|
||||
|
||||
QImage img(libraries.getPath(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
if (!img.isNull()) {
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
img.save(&buffer, "JPG");
|
||||
response.write(ba,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
#ifndef COVERCONTROLLER_V2_H
|
||||
#define COVERCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class CoverControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(CoverControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
CoverControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COVERCONTROLLER_H
|
||||
#ifndef COVERCONTROLLER_V2_H
|
||||
#define COVERCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class CoverControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(CoverControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
CoverControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COVERCONTROLLER_H
|
||||
|
@ -1,26 +1,26 @@
|
||||
#include "errorcontroller_v2.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
ErrorControllerV2::ErrorControllerV2(int errorCode)
|
||||
:error(errorCode)
|
||||
{}
|
||||
|
||||
void ErrorControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
switch(error)
|
||||
{
|
||||
case 300:
|
||||
response.setStatus(300,"redirect");
|
||||
response.write("<html> <head> <meta http-equiv=\"refresh\" content=\"0; URL=/\"> </head> <body> </body> </html>", true);
|
||||
break;
|
||||
case 404:
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#include "errorcontroller_v2.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
ErrorControllerV2::ErrorControllerV2(int errorCode)
|
||||
:error(errorCode)
|
||||
{}
|
||||
|
||||
void ErrorControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
switch(error)
|
||||
{
|
||||
case 300:
|
||||
response.setStatus(300,"redirect");
|
||||
response.write("<html> <head> <meta http-equiv=\"refresh\" content=\"0; URL=/\"> </head> <body> </body> </html>", true);
|
||||
break;
|
||||
case 404:
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef ERRORCONTROLLER_V2_H
|
||||
#define ERRORCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ErrorControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ErrorControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
ErrorControllerV2(int errorCode);
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
private:
|
||||
int error;
|
||||
};
|
||||
|
||||
#endif // ERRORCONTROLLER_H
|
||||
#ifndef ERRORCONTROLLER_V2_H
|
||||
#define ERRORCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ErrorControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ErrorControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
ErrorControllerV2(int errorCode);
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
private:
|
||||
int error;
|
||||
};
|
||||
|
||||
#endif // ERRORCONTROLLER_H
|
||||
|
@ -1,29 +1,29 @@
|
||||
#include "favoritescontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
FavoritesControllerV2::FavoritesControllerV2() {}
|
||||
|
||||
void FavoritesControllerV2::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();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FavoritesControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
QList<ComicDB> comics = DBHelper::getFavorites(library);
|
||||
|
||||
#include "favoritescontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
FavoritesControllerV2::FavoritesControllerV2() {}
|
||||
|
||||
void FavoritesControllerV2::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();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FavoritesControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
QList<ComicDB> comics = DBHelper::getFavorites(library);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for(const ComicDB &comic : comics)
|
||||
@ -33,7 +33,7 @@ void FavoritesControllerV2::serviceContent(const int library, HttpResponse &resp
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
#ifndef FAVORITESCONTROLLER_V2_H
|
||||
#define FAVORITESCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FavoritesControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FavoritesControllerV2)
|
||||
public:
|
||||
FavoritesControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int library, HttpResponse &response);
|
||||
};
|
||||
|
||||
|
||||
#endif // FAVORITESCONTROLLER_H
|
||||
#ifndef FAVORITESCONTROLLER_V2_H
|
||||
#define FAVORITESCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FavoritesControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FavoritesControllerV2)
|
||||
public:
|
||||
FavoritesControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int library, HttpResponse &response);
|
||||
};
|
||||
|
||||
|
||||
#endif // FAVORITESCONTROLLER_H
|
||||
|
@ -1,84 +1,84 @@
|
||||
#include "foldercontentcontroller_v2.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "foldercontentcontroller_v2.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
struct LibraryItemSorter
|
||||
{
|
||||
bool operator()(const LibraryItem * a,const LibraryItem * b) const
|
||||
{
|
||||
return naturalSortLessThanCI(a->name,b->name);
|
||||
}
|
||||
};
|
||||
|
||||
FolderContentControllerV2::FolderContentControllerV2() {}
|
||||
|
||||
void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong parentId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, parentId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderContentControllerV2::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
struct LibraryItemSorter
|
||||
{
|
||||
bool operator()(const LibraryItem * a,const LibraryItem * b) const
|
||||
{
|
||||
return naturalSortLessThanCI(a->name,b->name);
|
||||
}
|
||||
};
|
||||
|
||||
FolderContentControllerV2::FolderContentControllerV2() {}
|
||||
|
||||
void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong parentId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, parentId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderContentControllerV2::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
{
|
||||
#ifdef QT_DEBUG
|
||||
auto started = std::chrono::high_resolution_clock::now();
|
||||
#endif
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
|
||||
folderComics.clear();
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
ComicDB * currentComic;
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
if((*itr)->isDir())
|
||||
#endif
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
|
||||
folderComics.clear();
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
ComicDB * currentComic;
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
if((*itr)->isDir())
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::folderToJSON(library, *currentFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, *currentComic));
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
currentFolder = (Folder *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::folderToJSON(library, *currentFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, *currentComic));
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
#ifdef QT_DEBUG
|
||||
auto done = std::chrono::high_resolution_clock::now();
|
||||
|
||||
QLOG_TRACE() << "num items = " << items.count();
|
||||
QLOG_TRACE() << std::chrono::duration_cast<std::chrono::milliseconds>(done-started).count();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef FOLDERCONTENTCONTROLLER_V2_H
|
||||
#define FOLDERCONTENTCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderContentControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderContentControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderContentControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // FOLDERCONTENTCONTROLLER_H
|
||||
#ifndef FOLDERCONTENTCONTROLLER_V2_H
|
||||
#define FOLDERCONTENTCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderContentControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderContentControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderContentControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // FOLDERCONTENTCONTROLLER_H
|
||||
|
@ -1,55 +1,55 @@
|
||||
#include "folderinfocontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
FolderInfoControllerV2::FolderInfoControllerV2() {}
|
||||
|
||||
void FolderInfoControllerV2::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 parentId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceComics(libraryId, parentId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderInfoControllerV2::serviceComics(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
{
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
ComicDB * currentComic;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
response.write(QString("/v2/library/%1/comic/%2:%3:%4:%5:%6\r\n")
|
||||
.arg(library)
|
||||
.arg(currentComic->id)
|
||||
.arg(currentComic->getFileName())
|
||||
.arg(currentComic->getFileSize())
|
||||
.arg(currentComic->info.read ? 1 : 0)
|
||||
.arg(currentComic->info.hash)
|
||||
.toUtf8());
|
||||
delete currentComic;
|
||||
}
|
||||
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
serviceComics(library, currentFolder->id, response);
|
||||
delete currentFolder;
|
||||
}
|
||||
}
|
||||
#include "folderinfocontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
FolderInfoControllerV2::FolderInfoControllerV2() {}
|
||||
|
||||
void FolderInfoControllerV2::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 parentId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceComics(libraryId, parentId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderInfoControllerV2::serviceComics(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
{
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
ComicDB * currentComic;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
response.write(QString("/v2/library/%1/comic/%2:%3:%4:%5:%6\r\n")
|
||||
.arg(library)
|
||||
.arg(currentComic->id)
|
||||
.arg(currentComic->getFileName())
|
||||
.arg(currentComic->getFileSize())
|
||||
.arg(currentComic->info.read ? 1 : 0)
|
||||
.arg(currentComic->info.hash)
|
||||
.toUtf8());
|
||||
delete currentComic;
|
||||
}
|
||||
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
serviceComics(library, currentFolder->id, response);
|
||||
delete currentFolder;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
#ifndef FOLDERINFOCONTROLLER_V2_H
|
||||
#define FOLDERINFOCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderInfoControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderInfoControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
FolderInfoControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceComics(const int &library, const qulonglong & folderId, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // FOLDERINFOCONTROLLER_H
|
||||
#ifndef FOLDERINFOCONTROLLER_V2_H
|
||||
#define FOLDERINFOCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderInfoControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderInfoControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
FolderInfoControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceComics(const int &library, const qulonglong & folderId, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // FOLDERINFOCONTROLLER_H
|
||||
|
@ -1,36 +1,36 @@
|
||||
#include "librariescontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
LibrariesControllerV2::LibrariesControllerV2() {}
|
||||
|
||||
void LibrariesControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
|
||||
QJsonArray librariesJson;
|
||||
|
||||
int currentId = 0;
|
||||
foreach (QString name,names) {
|
||||
currentId = libraries.getId(name);
|
||||
QJsonObject library;
|
||||
|
||||
library["name"] = name;
|
||||
library["id"] = currentId;
|
||||
|
||||
librariesJson.append(library);
|
||||
}
|
||||
|
||||
QJsonDocument output(librariesJson);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write(output.toJson(QJsonDocument::Compact),true);
|
||||
}
|
||||
#include "librariescontroller_v2.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
LibrariesControllerV2::LibrariesControllerV2() {}
|
||||
|
||||
void LibrariesControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
|
||||
QJsonArray librariesJson;
|
||||
|
||||
int currentId = 0;
|
||||
foreach (QString name,names) {
|
||||
currentId = libraries.getId(name);
|
||||
QJsonObject library;
|
||||
|
||||
library["name"] = name;
|
||||
library["id"] = currentId;
|
||||
|
||||
librariesJson.append(library);
|
||||
}
|
||||
|
||||
QJsonDocument output(librariesJson);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write(output.toJson(QJsonDocument::Compact),true);
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
#ifndef LIBRARIESCONTROLLER_V2_H
|
||||
#define LIBRARIESCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
/**
|
||||
This controller displays a HTML form and dumps the submitted input.
|
||||
*/
|
||||
|
||||
|
||||
class LibrariesControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(LibrariesControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
LibrariesControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // LIBRARIESCONTROLLER_H
|
||||
#ifndef LIBRARIESCONTROLLER_V2_H
|
||||
#define LIBRARIESCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
/**
|
||||
This controller displays a HTML form and dumps the submitted input.
|
||||
*/
|
||||
|
||||
|
||||
class LibrariesControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(LibrariesControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
LibrariesControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // LIBRARIESCONTROLLER_H
|
||||
|
@ -1,21 +1,21 @@
|
||||
#include "pagecontroller_v2.h"
|
||||
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
#include "db_helper.h"
|
||||
|
||||
PageControllerV2::PageControllerV2() {}
|
||||
|
||||
void PageControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
#include "pagecontroller_v2.h"
|
||||
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
#include "db_helper.h"
|
||||
|
||||
PageControllerV2::PageControllerV2() {}
|
||||
|
||||
void PageControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
QByteArray token = request.getHeader("x-request-id");
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
|
||||
@ -25,87 +25,87 @@ void PageControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
response.write("424 no session for this comic",true);
|
||||
return;
|
||||
}
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
bool remote = path.endsWith("remote");
|
||||
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
unsigned int page = pathElements.at(7).toUInt();
|
||||
|
||||
Comic * comicFile;
|
||||
qulonglong currentComicId;
|
||||
if(remote)
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
|
||||
comicFile = ySession->getCurrentRemoteComic();
|
||||
currentComicId = ySession->getCurrentRemoteComicId();
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic para servir páginas";
|
||||
comicFile = ySession->getCurrentComic();
|
||||
currentComicId = ySession->getCurrentComicId();
|
||||
}
|
||||
|
||||
if (comicFile->hasBeenAnErrorOpening()) {
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
ySession->dismissCurrentComic();
|
||||
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
bool remote = path.endsWith("remote");
|
||||
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
unsigned int page = pathElements.at(7).toUInt();
|
||||
|
||||
Comic * comicFile;
|
||||
qulonglong currentComicId;
|
||||
if(remote)
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
|
||||
comicFile = ySession->getCurrentRemoteComic();
|
||||
currentComicId = ySession->getCurrentRemoteComicId();
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic para servir páginas";
|
||||
comicFile = ySession->getCurrentComic();
|
||||
currentComicId = ySession->getCurrentComicId();
|
||||
}
|
||||
|
||||
if (comicFile->hasBeenAnErrorOpening()) {
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
ySession->dismissCurrentComic();
|
||||
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||
{
|
||||
if (comicFile->numPages() == 0) {
|
||||
response.setStatus(412,"opening file");
|
||||
response.write("412 opening file",true);
|
||||
} else {
|
||||
if(comicId == currentComicId && page < comicFile->numPages())
|
||||
{
|
||||
if(comicFile->pageIsLoaded(page))
|
||||
{
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Transfer-Encoding","chunked");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
QDataStream data(pageData);
|
||||
char buffer[100000];
|
||||
while (!data.atEnd()) {
|
||||
int len = data.readRawData(buffer,100000);
|
||||
response.write(QByteArray(buffer,len));
|
||||
}
|
||||
response.write(QByteArray(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"loading page");
|
||||
response.write("412 loading page",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else {
|
||||
if(comicId == currentComicId && page < comicFile->numPages())
|
||||
{
|
||||
if(comicFile->pageIsLoaded(page))
|
||||
{
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Transfer-Encoding","chunked");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
QDataStream data(pageData);
|
||||
char buffer[100000];
|
||||
while (!data.atEnd()) {
|
||||
int len = data.readRawData(buffer,100000);
|
||||
response.write(QByteArray(buffer,len));
|
||||
}
|
||||
response.write(QByteArray(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"loading page");
|
||||
response.write("412 loading page",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(comicId != currentComicId)
|
||||
{
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
{
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
ySession->dismissCurrentComic();
|
||||
}
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
}
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#ifndef PAGECONTROLLER_V2_H
|
||||
#define PAGECONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class PageControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PageControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
PageControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
||||
#ifndef PAGECONTROLLER_V2_H
|
||||
#define PAGECONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class PageControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PageControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
PageControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
||||
|
@ -1,41 +1,41 @@
|
||||
#include "readingcomicscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
ReadingComicsControllerV2::ReadingComicsControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ReadingComicsControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ReadingComicsControllerV2::serviceContent(const int &library, HttpResponse &response)
|
||||
{
|
||||
QList<ComicDB> readingComics = DBHelper::getReading(library);
|
||||
|
||||
QJsonArray comics;
|
||||
|
||||
for(const ComicDB &comic : readingComics)
|
||||
{
|
||||
comics.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(comics);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
#include "readingcomicscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
ReadingComicsControllerV2::ReadingComicsControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ReadingComicsControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ReadingComicsControllerV2::serviceContent(const int &library, HttpResponse &response)
|
||||
{
|
||||
QList<ComicDB> readingComics = DBHelper::getReading(library);
|
||||
|
||||
QJsonArray comics;
|
||||
|
||||
for(const ComicDB &comic : readingComics)
|
||||
{
|
||||
comics.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(comics);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#ifndef READINGCOMICSCONTROLLER_V2_H
|
||||
#define READINGCOMICSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ReadingComicsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ReadingComicsControllerV2)
|
||||
public:
|
||||
ReadingComicsControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // READINGCOMICSCONTROLLER_H
|
||||
#ifndef READINGCOMICSCONTROLLER_V2_H
|
||||
#define READINGCOMICSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ReadingComicsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ReadingComicsControllerV2)
|
||||
public:
|
||||
ReadingComicsControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // READINGCOMICSCONTROLLER_H
|
||||
|
@ -1,41 +1,41 @@
|
||||
#include "readinglistscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "reading_list.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
|
||||
|
||||
ReadingListsControllerV2::ReadingListsControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ReadingListsControllerV2::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();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ReadingListsControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
QList<ReadingList> readingLists = DBHelper::getReadingLists(library);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for(QList<ReadingList>::const_iterator itr = readingLists.constBegin();itr!=readingLists.constEnd();itr++)
|
||||
{
|
||||
items.append(YACReaderServerDataHelper::readingListToJSON(library, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
#include "readinglistscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "reading_list.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
|
||||
|
||||
ReadingListsControllerV2::ReadingListsControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ReadingListsControllerV2::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();
|
||||
|
||||
serviceContent(libraryId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void ReadingListsControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
QList<ReadingList> readingLists = DBHelper::getReadingLists(library);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for(QList<ReadingList>::const_iterator itr = readingLists.constBegin();itr!=readingLists.constEnd();itr++)
|
||||
{
|
||||
items.append(YACReaderServerDataHelper::readingListToJSON(library, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#ifndef READINGLISTSCONTROLLER_V2_H
|
||||
#define READINGLISTSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ReadingListsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ReadingListsControllerV2)
|
||||
public:
|
||||
ReadingListsControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int library, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // READINGLISTSCONTROLLER_H
|
||||
#ifndef READINGLISTSCONTROLLER_V2_H
|
||||
#define READINGLISTSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ReadingListsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ReadingListsControllerV2)
|
||||
public:
|
||||
ReadingListsControllerV2();
|
||||
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int library, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // READINGLISTSCONTROLLER_H
|
||||
|
@ -1,84 +1,84 @@
|
||||
#include "synccontroller_v2.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
#include <QUrl>
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
SyncControllerV2::SyncControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
|
||||
qulonglong libraryId;
|
||||
qulonglong comicId;
|
||||
int currentPage;
|
||||
int currentRating;
|
||||
unsigned long long lastTimeOpened;
|
||||
QString hash;
|
||||
foreach(QString comicInfo, data)
|
||||
{
|
||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
||||
|
||||
if(comicInfoProgress.length() == 6)
|
||||
{
|
||||
if (comicInfoProgress.at(0) != "unknown")
|
||||
{
|
||||
libraryId = comicInfoProgress.at(0).toULongLong();
|
||||
comicId = comicInfoProgress.at(1).toULongLong();
|
||||
hash = comicInfoProgress.at(2);
|
||||
currentPage = comicInfoProgress.at(3).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash; //TODO remove the hash check and add UUIDs for libraries
|
||||
info.id = comicId;
|
||||
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
|
||||
lastTimeOpened = comicInfoProgress.at(5).toULong();
|
||||
info.lastTimeOpened = lastTimeOpened;
|
||||
|
||||
DBHelper::updateFromRemoteClient(libraryId,info);
|
||||
}
|
||||
else
|
||||
{
|
||||
hash = comicInfoProgress.at(2);
|
||||
currentPage = comicInfoProgress.at(3).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash;
|
||||
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
|
||||
lastTimeOpened = comicInfoProgress.at(5).toULong();
|
||||
info.lastTimeOpened = lastTimeOpened;
|
||||
|
||||
DBHelper::updateFromRemoteClientWithHash(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
||||
|
||||
#include "synccontroller_v2.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
#include <QUrl>
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
SyncControllerV2::SyncControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
|
||||
qulonglong libraryId;
|
||||
qulonglong comicId;
|
||||
int currentPage;
|
||||
int currentRating;
|
||||
unsigned long long lastTimeOpened;
|
||||
QString hash;
|
||||
foreach(QString comicInfo, data)
|
||||
{
|
||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
||||
|
||||
if(comicInfoProgress.length() == 6)
|
||||
{
|
||||
if (comicInfoProgress.at(0) != "unknown")
|
||||
{
|
||||
libraryId = comicInfoProgress.at(0).toULongLong();
|
||||
comicId = comicInfoProgress.at(1).toULongLong();
|
||||
hash = comicInfoProgress.at(2);
|
||||
currentPage = comicInfoProgress.at(3).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash; //TODO remove the hash check and add UUIDs for libraries
|
||||
info.id = comicId;
|
||||
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
|
||||
lastTimeOpened = comicInfoProgress.at(5).toULong();
|
||||
info.lastTimeOpened = lastTimeOpened;
|
||||
|
||||
DBHelper::updateFromRemoteClient(libraryId,info);
|
||||
}
|
||||
else
|
||||
{
|
||||
hash = comicInfoProgress.at(2);
|
||||
currentPage = comicInfoProgress.at(3).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash;
|
||||
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
|
||||
lastTimeOpened = comicInfoProgress.at(5).toULong();
|
||||
info.lastTimeOpened = lastTimeOpened;
|
||||
|
||||
DBHelper::updateFromRemoteClientWithHash(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
#ifndef SYNCCONTROLLER_V2_H
|
||||
#define SYNCCONTROLLER_V2_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class SyncControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SyncControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
SyncControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // SYNCCONTROLLER_H
|
||||
#ifndef SYNCCONTROLLER_V2_H
|
||||
#define SYNCCONTROLLER_V2_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class SyncControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SyncControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
SyncControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // SYNCCONTROLLER_H
|
||||
|
@ -1,33 +1,33 @@
|
||||
#include "tagcontentcontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
TagContentControllerV2::TagContentControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TagContentControllerV2::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();
|
||||
qulonglong tagId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, tagId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void TagContentControllerV2::serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response)
|
||||
{
|
||||
#include "tagcontentcontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
TagContentControllerV2::TagContentControllerV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TagContentControllerV2::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();
|
||||
qulonglong tagId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, tagId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void TagContentControllerV2::serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response)
|
||||
{
|
||||
QList<ComicDB> comics = DBHelper::getLabelComics(library, tagId);
|
||||
|
||||
QJsonArray items;
|
||||
@ -39,5 +39,5 @@ void TagContentControllerV2::serviceContent(const int &library, const qulonglong
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef TAGCONTENTCONTROLLER_V2_H
|
||||
#define TAGCONTENTCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class TagContentControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TagContentControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
TagContentControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // TAGCONTENTCONTROLLER_H
|
||||
#ifndef TAGCONTENTCONTROLLER_V2_H
|
||||
#define TAGCONTENTCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class TagContentControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TagContentControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
TagContentControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // TAGCONTENTCONTROLLER_H
|
||||
|
@ -1,36 +1,36 @@
|
||||
#include "tagscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "reading_list.h"
|
||||
#include "../static.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
TagsControllerV2::TagsControllerV2() {}
|
||||
|
||||
void TagsControllerV2::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();
|
||||
|
||||
QList<Label> labels = DBHelper::getLabels(libraryId);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for(QList<Label>::const_iterator itr = labels.constBegin();itr!=labels.constEnd();itr++)
|
||||
{
|
||||
items.append(YACReaderServerDataHelper::labelToJSON(libraryId, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));;
|
||||
}
|
||||
#include "tagscontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "reading_list.h"
|
||||
#include "../static.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
TagsControllerV2::TagsControllerV2() {}
|
||||
|
||||
void TagsControllerV2::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();
|
||||
|
||||
QList<Label> labels = DBHelper::getLabels(libraryId);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for(QList<Label>::const_iterator itr = labels.constBegin();itr!=labels.constEnd();itr++)
|
||||
{
|
||||
items.append(YACReaderServerDataHelper::labelToJSON(libraryId, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));;
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef TAGSCONTROLLER_V2_H
|
||||
#define TAGSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
|
||||
class TagsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TagsControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
TagsControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // TAGSCONTROLLER_H
|
||||
#ifndef TAGSCONTROLLER_V2_H
|
||||
#define TAGSCONTROLLER_V2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
|
||||
class TagsControllerV2 : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TagsControllerV2)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
TagsControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // TAGSCONTROLLER_H
|
||||
|
@ -1,54 +1,54 @@
|
||||
#include "updatecomiccontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
UpdateComicControllerV2::UpdateComicControllerV2(){}
|
||||
|
||||
void UpdateComicControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(3).toULongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
QString currentComicData = data.at(0);
|
||||
int currentPage = currentComicData.split(":").at(1).toInt();
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.id = comicId;
|
||||
DBHelper::updateProgress(libraryId,info);
|
||||
|
||||
if (data.length() > 1) {
|
||||
if (data.at(1).isEmpty() == false) {
|
||||
QString nextComicId = data.at(1);
|
||||
ComicInfo info;
|
||||
info.id = nextComicId.toULongLong();
|
||||
DBHelper::setComicAsReading(libraryId,info);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
||||
#include "updatecomiccontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
UpdateComicControllerV2::UpdateComicControllerV2(){}
|
||||
|
||||
void UpdateComicControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(3).toULongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
QString currentComicData = data.at(0);
|
||||
int currentPage = currentComicData.split(":").at(1).toInt();
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.id = comicId;
|
||||
DBHelper::updateProgress(libraryId,info);
|
||||
|
||||
if (data.length() > 1) {
|
||||
if (data.at(1).isEmpty() == false) {
|
||||
QString nextComicId = data.at(1);
|
||||
ComicInfo info;
|
||||
info.id = nextComicId.toULongLong();
|
||||
DBHelper::setComicAsReading(libraryId,info);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef UPDATECOMICCONTROLLER_V2_H
|
||||
#define UPDATECOMICCONTROLLER_V2_H
|
||||
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
class UpdateComicControllerV2 : public HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(UpdateComicControllerV2)
|
||||
|
||||
public:
|
||||
UpdateComicControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // UPDATECOMICCONTROLLER_H
|
||||
#ifndef UPDATECOMICCONTROLLER_V2_H
|
||||
#define UPDATECOMICCONTROLLER_V2_H
|
||||
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
class UpdateComicControllerV2 : public HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(UpdateComicControllerV2)
|
||||
|
||||
public:
|
||||
UpdateComicControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // UPDATECOMICCONTROLLER_H
|
||||
|
Reference in New Issue
Block a user