mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Merge pull request #511 from YACReader/remove-severv1
YACReader 10: Remove server v1
This commit is contained in:
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -9,6 +9,7 @@ on:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- yacreader10
|
||||
|
||||
env:
|
||||
IS_ORIGINAL_REPO: ${{ github.repository == 'YACReader/yacreader' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') }}
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
#include "comiccontroller.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>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
|
||||
ComicController::ComicController() { }
|
||||
|
||||
void ComicController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(2).toLongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(4).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);
|
||||
|
||||
if (!remoteComic)
|
||||
ySession->setDownloadedComic(comic.info.hash);
|
||||
|
||||
Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path);
|
||||
|
||||
if (comicFile != nullptr) {
|
||||
QThread *thread = nullptr;
|
||||
|
||||
thread = new QThread();
|
||||
|
||||
comicFile->moveToThread(thread);
|
||||
|
||||
connect(comicFile, QOverload<>::of(&Comic::errorOpening), thread, &QThread::quit);
|
||||
connect(comicFile, QOverload<QString>::of(&Comic::errorOpening), thread, &QThread::quit);
|
||||
connect(comicFile, &Comic::imagesLoaded, thread, &QThread::quit);
|
||||
connect(thread, &QThread::started, comicFile, &Comic::process);
|
||||
connect(thread, &QThread::finished, thread, &QObject::deleteLater);
|
||||
|
||||
comicFile->load(libraries.getPath(libraryId) + comic.path);
|
||||
|
||||
if (thread != nullptr)
|
||||
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,25 +0,0 @@
|
||||
#ifndef COMICCONTROLLER_H
|
||||
#define COMICCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
#include <QThread>
|
||||
class Comic;
|
||||
class QString;
|
||||
|
||||
class ComicController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
ComicController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // COMICCONTROLLER_H
|
||||
@ -1,28 +0,0 @@
|
||||
#include "comicdownloadinfocontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
ComicDownloadInfoController::ComicDownloadInfoController() { }
|
||||
|
||||
void ComicDownloadInfoController::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(2).toLongLong();
|
||||
qulonglong comicId = pathElements.at(4).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(), true);
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
#ifndef COMICDOWNLOADINFOCONTROLLER_H
|
||||
#define COMICDOWNLOADINFOCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ComicDownloadInfoController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicDownloadInfoController);
|
||||
|
||||
public:
|
||||
/** Constructor **/
|
||||
ComicDownloadInfoController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // COMICDOWNLOADINFOCONTROLLER_H
|
||||
@ -1,91 +0,0 @@
|
||||
#include <QPainter>
|
||||
|
||||
#include "covercontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
|
||||
CoverController::CoverController() { }
|
||||
|
||||
void CoverController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Connection", "close");
|
||||
// response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
QString fileName = pathElements.at(4);
|
||||
|
||||
bool folderCover = request.getParameter("folderCover").length() > 0;
|
||||
|
||||
// response.writeText(path+"<br/>");
|
||||
// response.writeText(libraryName+"<br/>");
|
||||
// response.writeText(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName+"<br/>");
|
||||
|
||||
// QFile file(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
// if (file.exists()) {
|
||||
// if (file.open(QIODevice::ReadOnly))
|
||||
// {
|
||||
// qDebug("StaticFileController: Open file %s",qPrintable(file.fileName()));
|
||||
// // Return the file content, do not store in cache
|
||||
// while (!file.atEnd() && !file.error()) {
|
||||
// response.write(file.read(131072));
|
||||
// }
|
||||
// }
|
||||
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
QImage img(libraries.getPath(libraryName) + "/.yacreaderlibrary/covers/" + fileName);
|
||||
if (!img.isNull()) {
|
||||
|
||||
int width = 80, height = 120;
|
||||
if (ySession->getDisplayType() == "@2x") {
|
||||
width = 160;
|
||||
height = 240;
|
||||
}
|
||||
|
||||
if (float(img.width()) / img.height() < 0.66666)
|
||||
img = img.scaledToWidth(width, Qt::SmoothTransformation);
|
||||
else
|
||||
img = img.scaledToHeight(height, Qt::SmoothTransformation);
|
||||
|
||||
QImage destImg(width, height, QImage::Format_RGB32);
|
||||
destImg.fill(Qt::black);
|
||||
QPainter p(&destImg);
|
||||
|
||||
p.drawImage((width - img.width()) / 2, (height - img.height()) / 2, img);
|
||||
|
||||
if (folderCover) {
|
||||
if (ySession->getDisplayType() == "@2x")
|
||||
p.drawImage(0, 0, QImage(":/images/f_overlayed_retina.png"));
|
||||
else
|
||||
p.drawImage(0, 0, QImage(":/images/f_overlayed.png"));
|
||||
}
|
||||
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
destImg.save(&buffer, "JPG");
|
||||
response.write(ba, true);
|
||||
}
|
||||
// DONE else, hay que devolver un 404
|
||||
else {
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
#ifndef COVERCONTROLLER_H
|
||||
#define COVERCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class CoverController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(CoverController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
CoverController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // COVERCONTROLLER_H
|
||||
@ -1,27 +0,0 @@
|
||||
#include "errorcontroller.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
ErrorController::ErrorController(int errorCode)
|
||||
: error(errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
void ErrorController::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,24 +0,0 @@
|
||||
#ifndef ERRORCONTROLLER_H
|
||||
#define ERRORCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ErrorController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ErrorController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
ErrorController(int errorCode);
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
|
||||
private:
|
||||
int error;
|
||||
};
|
||||
|
||||
#endif // ERRORCONTROLLER_H
|
||||
@ -1,308 +0,0 @@
|
||||
#include "foldercontroller.h"
|
||||
#include "controllers/v1/errorcontroller.h"
|
||||
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "folder.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
using stefanfrings::Template;
|
||||
|
||||
FolderController::FolderController() { }
|
||||
|
||||
void FolderController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QSettings *settings = new QSettings(YACReader::getSettingsPath() + "/YACReaderLibrary.ini", QSettings::IniFormat); // TODO unificar la creación del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
response.setHeader("Connection", "close");
|
||||
|
||||
// QString y = session.get("xxx").toString();
|
||||
// response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||
|
||||
Template t = Static::templateLoader->getTemplate("folder", request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
||||
// set device type for templates
|
||||
t.setVariable("device", ySession->getDeviceType());
|
||||
t.setVariable("display", ySession->getDisplayType());
|
||||
t.setCondition("device.ipad", ySession->getDeviceType() == "ipad");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(2).toInt();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong folderId = pathElements.at(4).toULongLong();
|
||||
|
||||
folderId = qMax<qulonglong>(1, folderId);
|
||||
|
||||
QString folderName = DBHelper::getFolderName(libraryId, folderId);
|
||||
if (folderName.isEmpty()) {
|
||||
ErrorController(300).service(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (folderId != 1)
|
||||
t.setVariable("folder.name", folderName);
|
||||
else
|
||||
t.setVariable("folder.name", libraryName);
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(libraryId, folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryId, folderId);
|
||||
|
||||
// response.writeText(libraryName);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
|
||||
std::sort(folderContent.begin(), folderContent.end(), LibraryItemSorter());
|
||||
folderComics.clear();
|
||||
|
||||
// qulonglong backId = DBHelper::getParentFromComicFolderId(libraryName,folderId);
|
||||
|
||||
int page = 0;
|
||||
QByteArray p = request.getParameter("page");
|
||||
if (p.length() != 0)
|
||||
page = p.toInt();
|
||||
|
||||
// /comicIdi/pagei/comicIdj/pagej/....../comicIdn/pagen
|
||||
// QString currentPath = session.get("currentPath").toString();
|
||||
// QStringList pathSize = currentPath.split("/").last().toInt;
|
||||
|
||||
bool fromUp = false;
|
||||
|
||||
QMultiMap<QByteArray, QByteArray> map = request.getParameterMap();
|
||||
if (map.contains("up"))
|
||||
fromUp = true;
|
||||
|
||||
// int upPage = 0;
|
||||
|
||||
if (folderId == 1) {
|
||||
ySession->clearNavigationPath();
|
||||
ySession->pushNavigationItem(QPair<qulonglong, quint32>(folderId, page));
|
||||
t.setVariable(QString("upurl"), "/");
|
||||
} else {
|
||||
if (fromUp)
|
||||
ySession->popNavigationItem();
|
||||
else // drill down or direct access
|
||||
{
|
||||
QStack<QPair<qulonglong, quint32>> path = ySession->getNavigationPath();
|
||||
bool found = false;
|
||||
for (QStack<QPair<qulonglong, quint32>>::const_iterator itr = path.begin(); itr != path.end(); itr++)
|
||||
if (itr->first == folderId) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
while (ySession->topNavigationItem().first != folderId)
|
||||
ySession->popNavigationItem();
|
||||
|
||||
ySession->updateTopItem(QPair<qulonglong, quint32>(folderId, page));
|
||||
} else
|
||||
ySession->pushNavigationItem(QPair<qulonglong, quint32>(folderId, page));
|
||||
}
|
||||
|
||||
QStack<QPair<qulonglong, quint32>> path = ySession->getNavigationPath();
|
||||
if (path.count() > 1) {
|
||||
QPair<qulonglong, quint32> parentItem = path.at(path.count() - 2);
|
||||
qulonglong upParent = parentItem.first;
|
||||
quint32 upPage = parentItem.second;
|
||||
t.setVariable(QString("upurl"), "/library/" + QString::number(libraryId) + "/folder/" + QString("%1?page=%2&up=true").arg(upParent).arg(upPage));
|
||||
} else
|
||||
t.setVariable(QString("upurl"), "/");
|
||||
}
|
||||
|
||||
int elementsPerPage = 24;
|
||||
|
||||
int numFolders = folderContent.length();
|
||||
// int numComics = folderComics.length();
|
||||
int totalLength = folderContent.length() + folderComics.length();
|
||||
|
||||
// int numFolderPages = numFolders / elementsPerPage + ((numFolders%elementsPerPage)>0?1:0);
|
||||
int numPages = totalLength / elementsPerPage + ((totalLength % elementsPerPage) > 0 ? 1 : 0);
|
||||
|
||||
// response.writeText(QString("Number of pages : %1 <br/>").arg(numPages));
|
||||
|
||||
if (page < 0)
|
||||
page = 0;
|
||||
else if (page >= numPages)
|
||||
page = numPages - 1;
|
||||
|
||||
int indexCurrentPage = page * elementsPerPage;
|
||||
int numFoldersAtCurrentPage = qMax(0, qMin(numFolders - indexCurrentPage, elementsPerPage));
|
||||
|
||||
// PATH
|
||||
QStack<QPair<qulonglong, quint32>> foldersPath = ySession->getNavigationPath();
|
||||
t.setVariable(QString("library.name"), libraryName);
|
||||
t.setVariable(QString("library.url"), QString("/library/%1/folder/1").arg(libraryId));
|
||||
t.loop("path", foldersPath.count() - 1);
|
||||
for (int i = 1; i < foldersPath.count(); i++) {
|
||||
t.setVariable(QString("path%1.url").arg(i - 1), QString("/library/%1/folder/%2").arg(libraryId).arg(foldersPath[i].first));
|
||||
t.setVariable(QString("path%1.name").arg(i - 1), DBHelper::getFolderName(libraryId, foldersPath[i].first));
|
||||
}
|
||||
|
||||
if (folderContent.length() > 0) {
|
||||
t.loop("element", numFoldersAtCurrentPage);
|
||||
int i = 0;
|
||||
while (i < numFoldersAtCurrentPage) {
|
||||
LibraryItem *item = folderContent.at(i + (page * elementsPerPage));
|
||||
t.setVariable(QString("element%1.name").arg(i), folderContent.at(i + (page * elementsPerPage))->name);
|
||||
if (item->isDir()) {
|
||||
t.setVariable(QString("element%1.class").arg(i), "folder");
|
||||
|
||||
QList<LibraryItem *> children = DBHelper::getFolderComicsFromLibrary(libraryId, item->id);
|
||||
if (children.length() > 0) {
|
||||
const ComicDB *comic = static_cast<ComicDB *>(children.at(0));
|
||||
t.setVariable(QString("element%1.image.url").arg(i), QString("/library/%1/cover/%2.jpg?folderCover=true").arg(libraryId).arg(comic->info.hash));
|
||||
} else
|
||||
t.setVariable(QString("element%1.image.url").arg(i), "/images/f.png");
|
||||
|
||||
t.setVariable(QString("element%1.browse").arg(i), QString("<a class =\"browseButton\" href=\"%1\">BROWSE</a>").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id)));
|
||||
t.setVariable(QString("element%1.cover.browse").arg(i), QString("<a href=\"%1\">").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id)));
|
||||
t.setVariable(QString("element%1.cover.browse.end").arg(i), "</a>");
|
||||
// t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
||||
// t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->id));
|
||||
|
||||
t.setVariable(QString("element%1.download").arg(i), QString("<a onclick=\"this.innerHTML='IMPORTING';this.className='importedButton';\" class =\"importButton\" href=\"%1\">IMPORT</a>").arg("/library/" + QString::number(libraryId) + "/folder/" + QString("%1/info").arg(folderContent.at(i + (page * elementsPerPage))->id)));
|
||||
t.setVariable(QString("element%1.read").arg(i), "");
|
||||
|
||||
t.setVariable(QString("element%1.size").arg(i), "");
|
||||
t.setVariable(QString("element%1.pages").arg(i), "");
|
||||
t.setVariable(QString("element%1.status").arg(i), "");
|
||||
} else {
|
||||
t.setVariable(QString("element%1.class").arg(i), "cover");
|
||||
const ComicDB *comic = (ComicDB *)item;
|
||||
t.setVariable(QString("element%1.browse").arg(i), "");
|
||||
// t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
||||
if (!ySession->isComicOnDevice(comic->info.hash) && !ySession->isComicDownloaded(comic->info.hash))
|
||||
t.setVariable(QString("element%1.download").arg(i), QString("<a onclick=\"this.innerHTML='IMPORTING';this.className='importedButton';\" class =\"importButton\" href=\"%1\">IMPORT</a>").arg("/library/" + QString::number(libraryId) + "/comic/" + QString("%1").arg(comic->id)));
|
||||
else if (ySession->isComicOnDevice(comic->info.hash))
|
||||
t.setVariable(QString("element%1.download").arg(i), QString("<div class=\"importedButton\">IMPORTED</div>"));
|
||||
else
|
||||
t.setVariable(QString("element%1.download").arg(i), QString("<div class=\"importedButton\">IMPORTING</div>"));
|
||||
|
||||
// t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
|
||||
t.setVariable(QString("element%1.read").arg(i), QString("<a class =\"readButton\" href=\"%1\">READ</a>").arg("/library/" + QString::number(libraryId) + "/comic/" + QString("%1").arg(comic->id) + "/remote"));
|
||||
|
||||
t.setVariable(QString("element%1.image.url").arg(i), QString("/library/%1/cover/%2.jpg").arg(libraryId).arg(comic->info.hash));
|
||||
|
||||
t.setVariable(QString("element%1.size").arg(i), "<span class=\"comicSize\">" + QString::number(comic->info.hash.right(comic->info.hash.length() - 40).toInt() / 1024.0 / 1024.0, 'f', 2) + "Mb</span>");
|
||||
if (comic->info.hasBeenOpened)
|
||||
t.setVariable(QString("element%1.pages").arg(i), QString("<span class=\"numPages\">%1/%2 pages</span>").arg(comic->info.currentPage).arg(comic->info.numPages.toInt()));
|
||||
else
|
||||
t.setVariable(QString("element%1.pages").arg(i), QString("<span class=\"numPages\">%1 pages</span>").arg(comic->info.numPages.toInt()));
|
||||
|
||||
if (comic->info.read)
|
||||
t.setVariable(QString("element%1.status").arg(i), QString("<div class=\"mark\"><img src=\"/images/readMark.png\" style = \"width: 15px\"/> </div>"));
|
||||
else if (comic->info.hasBeenOpened)
|
||||
t.setVariable(QString("element%1.status").arg(i), QString("<div class=\"mark\"><img src=\"/images/readingMark.png\" style = \"width: 15px\"/> </div>"));
|
||||
else
|
||||
t.setVariable(QString("element%1.status").arg(i), "");
|
||||
|
||||
t.setVariable(QString("element%1.cover.browse").arg(i), "");
|
||||
t.setVariable(QString("element%1.cover.browse.end").arg(i), "");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
t.loop("element", 0);
|
||||
}
|
||||
|
||||
if (numPages > 1) {
|
||||
t.setCondition("pageIndex", true);
|
||||
|
||||
QMap<QString, int> indexCount;
|
||||
|
||||
QString firstChar;
|
||||
int xyz = 1;
|
||||
for (QList<LibraryItem *>::const_iterator itr = folderContent.constBegin(); itr != folderContent.constEnd(); itr++) {
|
||||
firstChar = QString((*itr)->name[0]).toUpper();
|
||||
firstChar = firstChar.normalized(QString::NormalizationForm_D).at(0); // TODO _D or _KD??
|
||||
bool ok;
|
||||
/*int dec = */ firstChar.toInt(&ok, 10);
|
||||
if (ok)
|
||||
firstChar = "#";
|
||||
// response.writeText(QString("%1 - %2 <br />").arg((*itr)->name).arg(xyz));
|
||||
if (indexCount.contains(firstChar))
|
||||
indexCount.insert(firstChar, indexCount.value(firstChar) + 1);
|
||||
else
|
||||
indexCount.insert(firstChar, 1);
|
||||
|
||||
xyz++;
|
||||
}
|
||||
|
||||
QList<QString> index = indexCount.keys();
|
||||
if (index.length() > 1) {
|
||||
t.setCondition("alphaIndex", true);
|
||||
|
||||
std::sort(index.begin(), index.end(), naturalSortLessThanCI);
|
||||
t.loop("index", index.length());
|
||||
int i = 0;
|
||||
int count = 0;
|
||||
int indexPage = 0;
|
||||
for (QList<QString>::const_iterator itr = index.constBegin(); itr != index.constEnd(); itr++) {
|
||||
// response.writeText(QString("%1 - %2 <br />").arg(*itr).arg(count));
|
||||
t.setVariable(QString("index%1.indexname").arg(i), *itr);
|
||||
t.setVariable(QString("index%1.url").arg(i), QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(indexPage));
|
||||
i++;
|
||||
count += indexCount.value(*itr);
|
||||
indexPage = count / elementsPerPage;
|
||||
}
|
||||
} else {
|
||||
t.loop("index", 0);
|
||||
t.setCondition("alphaIndex", false);
|
||||
}
|
||||
|
||||
t.loop("page", numPages);
|
||||
int z = 0;
|
||||
while (z < numPages) {
|
||||
|
||||
t.setVariable(QString("page%1.url").arg(z), QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(z));
|
||||
t.setVariable(QString("page%1.number").arg(z), QString("%1").arg(z + 1));
|
||||
if (page == z)
|
||||
t.setVariable(QString("page%1.current").arg(z), "current");
|
||||
else
|
||||
t.setVariable(QString("page%1.current").arg(z), "");
|
||||
z++;
|
||||
}
|
||||
|
||||
t.setVariable("page.first", QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(0));
|
||||
t.setVariable("page.previous", QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page == 0) ? page : page - 1));
|
||||
t.setVariable("page.next", QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page == numPages - 1) ? page : page + 1));
|
||||
t.setVariable("page.last", QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(numPages - 1));
|
||||
t.setCondition("index", true);
|
||||
} else {
|
||||
|
||||
t.loop("page", 0);
|
||||
t.loop("index", 0);
|
||||
t.setCondition("index", false);
|
||||
t.setCondition("pageIndex", false);
|
||||
t.setCondition("alphaIndex", false);
|
||||
}
|
||||
|
||||
t.setVariable("page", QString("%1").arg(page + 1));
|
||||
t.setVariable("pages", QString("%1").arg(numPages));
|
||||
|
||||
qDeleteAll(folderContent);
|
||||
|
||||
response.write(t.toUtf8(), true);
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
#ifndef FOLDERCONTROLLER_H
|
||||
#define FOLDERCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // FOLDERCONTROLLER_H
|
||||
@ -1,47 +0,0 @@
|
||||
#include "folderinfocontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
FolderInfoController::FolderInfoController() { }
|
||||
|
||||
void FolderInfoController::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(2).toInt();
|
||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||
|
||||
serviceComics(libraryId, parentId, response);
|
||||
|
||||
response.write("", true);
|
||||
}
|
||||
|
||||
void FolderInfoController::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("/library/%1/comic/%2:%3:%4\r\n").arg(library).arg(currentComic->id).arg(currentComic->getFileName()).arg(currentComic->getFileSize()).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,24 +0,0 @@
|
||||
#ifndef FOLDERINFOCONTROLLER_H
|
||||
#define FOLDERINFOCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderInfoController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderInfoController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderInfoController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
|
||||
private:
|
||||
void serviceComics(const int &library, const qulonglong &folderId, stefanfrings::HttpResponse &response);
|
||||
};
|
||||
|
||||
#endif // FOLDERINFOCONTROLLER_H
|
||||
@ -1,51 +0,0 @@
|
||||
#include "librariescontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
using stefanfrings::Template;
|
||||
|
||||
LibrariesController::LibrariesController() { }
|
||||
|
||||
void LibrariesController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
response.setHeader("Connection", "close");
|
||||
|
||||
ySession->clearNavigationPath();
|
||||
|
||||
Template t = Static::templateLoader->getTemplate("libraries", request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
||||
// set device type and display
|
||||
t.setVariable("device", ySession->getDeviceType());
|
||||
t.setVariable("display", ySession->getDisplayType());
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
|
||||
t.loop("library", names.length());
|
||||
|
||||
int currentId = 0;
|
||||
int i = 0;
|
||||
foreach (QString name, names) {
|
||||
currentId = libraries.getId(name);
|
||||
t.setVariable(QString("library%1.name").arg(i), QString::number(currentId));
|
||||
t.setVariable(QString("library%1.label").arg(i), name);
|
||||
i++;
|
||||
}
|
||||
|
||||
response.setStatus(200, "OK");
|
||||
response.write(t.toUtf8(), true);
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
#ifndef LIBRARIESCONTROLLER_H
|
||||
#define LIBRARIESCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
/**
|
||||
This controller displays a HTML form and dumps the submitted input.
|
||||
*/
|
||||
|
||||
class LibrariesController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(LibrariesController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
LibrariesController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // LIBRARIESCONTROLLER_H
|
||||
@ -1,86 +0,0 @@
|
||||
#include "pagecontroller.h"
|
||||
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
|
||||
PageController::PageController() { }
|
||||
|
||||
void PageController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
bool remote = path.endsWith("remote");
|
||||
|
||||
// QByteArray path2=request.getPath();
|
||||
// qDebug("PageController: request to -> %s ",path2.data());
|
||||
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
unsigned int page = pathElements.at(6).toUInt();
|
||||
|
||||
// qDebug("lib name : %s",pathElements.at(2).data());
|
||||
|
||||
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 (currentComicId != 0 && !QPointer<Comic>(comicFile).isNull()) {
|
||||
if (comicId == currentComicId && page < comicFile->numPages()) {
|
||||
if (comicFile->pageIsLoaded(page)) {
|
||||
// qDebug("PageController: La página estaba cargada -> %s ",path.data());
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Transfer-Encoding", "chunked");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
QDataStream data(pageData);
|
||||
char buffer[4096];
|
||||
while (!data.atEnd()) {
|
||||
int len = data.readRawData(buffer, 4096);
|
||||
response.write(QByteArray(buffer, len));
|
||||
}
|
||||
// response.write(pageData,true);
|
||||
response.write(QByteArray(), true);
|
||||
} else {
|
||||
// qDebug("PageController: La página NO estaba cargada 404 -> %s ",path.data());
|
||||
response.setStatus(404, "not found"); // TODO qué mensaje enviar
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
} else {
|
||||
if (comicId != currentComicId) {
|
||||
// delete comicFile;
|
||||
if (remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
ySession->dismissCurrentComic();
|
||||
}
|
||||
response.setStatus(404, "not found"); // TODO qué mensaje enviar
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
} else {
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
|
||||
// response.write(t.toLatin1(),true);
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
#ifndef PAGECONTROLLER_H
|
||||
#define PAGECONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class PageController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PageController);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
PageController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
||||
@ -1,34 +0,0 @@
|
||||
/**
|
||||
@file
|
||||
@author Stefan Frings
|
||||
*/
|
||||
|
||||
#include "sessioncontroller.h"
|
||||
#include "../static.h"
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
SessionController::SessionController() { }
|
||||
|
||||
void SessionController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
|
||||
|
||||
// Get current session, or create a new one
|
||||
HttpSession session = Static::sessionStore->getSession(request, response);
|
||||
if (!session.contains("startTime")) {
|
||||
response.write("<html><body>New session started. Reload this page now.</body></html>");
|
||||
session.set("startTime", QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
else {
|
||||
QDateTime startTime = session.get("startTime").toDateTime();
|
||||
response.write("<html><body>Your session started ");
|
||||
response.write(startTime.toString().toLatin1());
|
||||
response.write("</body></html>");
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
#include "synccontroller.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
#include <QUrl>
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
SyncController::SyncController()
|
||||
{
|
||||
}
|
||||
|
||||
void SyncController::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;
|
||||
QString hash;
|
||||
foreach (QString comicInfo, data) {
|
||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
||||
|
||||
if (comicInfoProgress.length() == 4 || comicInfoProgress.length() == 5) {
|
||||
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;
|
||||
|
||||
// Client 2.1+ version
|
||||
if (comicInfoProgress.length() > 4) {
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
}
|
||||
|
||||
DBHelper::updateFromRemoteClient(libraryId, info);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.setStatus(412, "No comic info received");
|
||||
response.write("", true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK", true);
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
#ifndef SYNCCONTROLLER_H
|
||||
#define SYNCCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class SyncController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SyncController)
|
||||
public:
|
||||
/** Constructor */
|
||||
SyncController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // SYNCCONTROLLER_H
|
||||
@ -1,48 +0,0 @@
|
||||
#include "updatecomiccontroller.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"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
|
||||
UpdateComicController::UpdateComicController() { }
|
||||
|
||||
void UpdateComicController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(2).toULongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if (postData.length() > 0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
int currentPage = data.at(0).split(":").at(1).toInt();
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.id = comicId;
|
||||
DBHelper::updateProgress(libraryId, info);
|
||||
} else {
|
||||
response.setStatus(412, "No comic info received");
|
||||
response.write("", true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK", true);
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
#ifndef UPDATECOMICCONTROLLER_H
|
||||
#define UPDATECOMICCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class UpdateComicController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(UpdateComicController);
|
||||
|
||||
public:
|
||||
UpdateComicController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // UPDATECOMICCONTROLLER_H
|
||||
@ -3,7 +3,6 @@
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
@ -4,17 +4,6 @@
|
||||
|
||||
#include "controllers/versioncontroller.h"
|
||||
|
||||
#include "controllers/v1/librariescontroller.h"
|
||||
#include "controllers/v1/foldercontroller.h"
|
||||
#include "controllers/v1/covercontroller.h"
|
||||
#include "controllers/v1/comiccontroller.h"
|
||||
#include "controllers/v1/folderinfocontroller.h"
|
||||
#include "controllers/v1/pagecontroller.h"
|
||||
#include "controllers/v1/updatecomiccontroller.h"
|
||||
#include "controllers/v1/errorcontroller.h"
|
||||
#include "controllers/v1/comicdownloadinfocontroller.h"
|
||||
#include "controllers/v1/synccontroller.h"
|
||||
|
||||
#include "controllers/v2/librariescontroller_v2.h"
|
||||
#include "controllers/v2/covercontroller_v2.h"
|
||||
#include "controllers/v2/comiccontroller_v2.h"
|
||||
@ -51,83 +40,12 @@
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpRequestHandler;
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSession;
|
||||
|
||||
QMutex RequestMapper::mutex;
|
||||
|
||||
RequestMapper::RequestMapper(QObject *parent)
|
||||
: HttpRequestHandler(parent) { }
|
||||
|
||||
void RequestMapper::loadSessionV1(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
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
|
||||
{
|
||||
auto ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
if (postData.contains("currentPage"))
|
||||
return;
|
||||
|
||||
if (postData.length() > 0) {
|
||||
|
||||
QList<QString> data = postData.split("\n");
|
||||
if (data.length() > 2) {
|
||||
ySession->setDeviceType(data.at(0).split(":").at(1));
|
||||
ySession->setDisplayType(data.at(1).split(":").at(1));
|
||||
QList<QString> comics = data.at(2).split(":").at(1).split("\t");
|
||||
ySession->clearComics();
|
||||
foreach (QString hash, comics) {
|
||||
ySession->setComicOnDevice(hash);
|
||||
}
|
||||
} else {
|
||||
if (data.length() > 1) {
|
||||
ySession->setDeviceType(data.at(0).split(":").at(1));
|
||||
ySession->setDisplayType(data.at(1).split(":").at(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto ySession = new YACReaderHttpSession(this);
|
||||
|
||||
Static::yacreaderSessionStore->addYACReaderHttpSession(session.getId(), ySession);
|
||||
|
||||
session.set("ySession", "ok");
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
// response.writeText(postData);
|
||||
|
||||
QList<QString> data = postData.split("\n");
|
||||
|
||||
if (data.length() > 2) {
|
||||
auto deviceTypeData = data.at(0).split(":");
|
||||
if (deviceTypeData.length() == 2) {
|
||||
ySession->setDeviceType(deviceTypeData.at(1));
|
||||
}
|
||||
|
||||
auto displayTypeData = data.at(1).split(":");
|
||||
if (displayTypeData.length() == 2) {
|
||||
ySession->setDisplayType(displayTypeData.at(1));
|
||||
}
|
||||
|
||||
auto comicsData = data.at(2).split(":");
|
||||
if (comicsData.length() == 2) {
|
||||
QList<QString> comics = comicsData.at(1).split("\t");
|
||||
foreach (QString hash, comics) {
|
||||
ySession->setComicOnDevice(hash);
|
||||
}
|
||||
}
|
||||
} else // values by default, only for debug purposes.
|
||||
{
|
||||
ySession->setDeviceType("ipad");
|
||||
ySession->setDisplayType("@2x");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RequestMapper::loadSessionV2(HttpRequest &request, HttpResponse & /* response */)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
@ -160,7 +78,8 @@ void RequestMapper::service(HttpRequest &request, HttpResponse &response)
|
||||
} else if (path.startsWith("/webui")) {
|
||||
serviceWebUI(request, response);
|
||||
} else {
|
||||
serviceV1(request, response);
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,71 +88,6 @@ void RequestMapper::serviceWebUI(HttpRequest &request, HttpResponse &response)
|
||||
StatusPageController().service(request, response);
|
||||
}
|
||||
|
||||
void RequestMapper::serviceV1(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QByteArray path = request.getPath();
|
||||
|
||||
QRegExp folder("/library/.+/folder/[0-9]+/?"); // get comic content
|
||||
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); // get folder info
|
||||
QRegExp comicDownloadInfo("/library/.+/comic/[0-9]+/?"); // get comic info (basic/download info)
|
||||
QRegExp comicFullInfo("/library/.+/comic/[0-9]+/info/?"); // get comic info (full info)
|
||||
QRegExp comicOpen("/library/.+/comic/[0-9]+/remote/?"); // the server will open for reading the comic
|
||||
QRegExp comicUpdate("/library/.+/comic/[0-9]+/update/?"); // get comic info
|
||||
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); // the server will close the comic and free memory
|
||||
QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); // get comic cover (navigation)
|
||||
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); // get comic page
|
||||
QRegExp comicPageRemote("/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); // get comic page (remote reading)
|
||||
|
||||
QRegExp sync("/sync");
|
||||
|
||||
QRegExp library("/library/([0-9]+)/.+"); // permite verificar que la biblioteca solicitada existe
|
||||
|
||||
path = QUrl::fromPercentEncoding(path).toUtf8();
|
||||
|
||||
if (!sync.exactMatch(path)) // no session is needed for syncback info, until security will be added
|
||||
loadSessionV1(request, response);
|
||||
|
||||
// primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
|
||||
if (path == "/") // Don't send data to the server using '/' !!!!
|
||||
{
|
||||
LibrariesController().service(request, response);
|
||||
} else {
|
||||
if (sync.exactMatch(path))
|
||||
SyncController().service(request, response);
|
||||
else {
|
||||
// se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados
|
||||
HttpSession session = Static::sessionStore->getSession(request, response, false);
|
||||
if (!session.isNull() && session.contains("ySession")) {
|
||||
if (library.indexIn(path) != -1 && DBHelper::getLibraries().contains(library.cap(1).toInt())) {
|
||||
// listar el contenido del folder
|
||||
if (folder.exactMatch(path)) {
|
||||
FolderController().service(request, response);
|
||||
} else if (folderInfo.exactMatch(path)) {
|
||||
FolderInfoController().service(request, response);
|
||||
} else if (cover.exactMatch(path)) {
|
||||
CoverController().service(request, response);
|
||||
} else if (comicDownloadInfo.exactMatch(path)) {
|
||||
ComicDownloadInfoController().service(request, response);
|
||||
} else if (comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path)) // start download or start remote reading
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
} else if (comicPage.exactMatch(path) || comicPageRemote.exactMatch(path)) {
|
||||
PageController().service(request, response);
|
||||
} else if (comicUpdate.exactMatch(path)) {
|
||||
UpdateComicController().service(request, response);
|
||||
}
|
||||
} else {
|
||||
// response.writeText(library.cap(1));
|
||||
Static::staticFileController->service(request, response);
|
||||
}
|
||||
} else // acceso no autorizado, redirección
|
||||
{
|
||||
ErrorController(300).service(request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QByteArray path = request.getPath();
|
||||
|
||||
@ -12,7 +12,6 @@ public:
|
||||
RequestMapper(QObject *parent = nullptr);
|
||||
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
void loadSessionV1(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
void loadSessionV2(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
|
||||
signals:
|
||||
@ -20,7 +19,6 @@ signals:
|
||||
void comicUpdated(qulonglong libraryId, qulonglong comicId);
|
||||
|
||||
private:
|
||||
void serviceV1(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
void serviceV2(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
void serviceWebUI(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD/controllers
|
||||
INCLUDEPATH += $$PWD/controllers/v1
|
||||
INCLUDEPATH += $$PWD/controllers/v2
|
||||
DEPENDPATH += $$PWD
|
||||
DEPENDPATH += $$PWD/controllers
|
||||
DEPENDPATH += $$PWD/controllers/v1
|
||||
DEPENDPATH += $$PWD/controllers/v2
|
||||
|
||||
|
||||
@ -18,17 +16,6 @@ HEADERS += \
|
||||
$$PWD/yacreader_http_session_store.h \
|
||||
$$PWD/yacreader_server_data_helper.h \
|
||||
$$PWD/controllers/versioncontroller.h \
|
||||
#v1
|
||||
$$PWD/controllers/v1/comiccontroller.h \
|
||||
$$PWD/controllers/v1/errorcontroller.h \
|
||||
$$PWD/controllers/v1/foldercontroller.h \
|
||||
$$PWD/controllers/v1/folderinfocontroller.h \
|
||||
$$PWD/controllers/v1/librariescontroller.h \
|
||||
$$PWD/controllers/v1/pagecontroller.h \
|
||||
$$PWD/controllers/v1/covercontroller.h \
|
||||
$$PWD/controllers/v1/updatecomiccontroller.h \
|
||||
$$PWD/controllers/v1/comicdownloadinfocontroller.h \
|
||||
$$PWD/controllers/v1/synccontroller.h \
|
||||
#v2
|
||||
$$PWD/controllers/v2/comiccontroller_v2.h \
|
||||
$$PWD/controllers/v2/errorcontroller_v2.h \
|
||||
@ -64,17 +51,6 @@ SOURCES += \
|
||||
$$PWD/yacreader_http_session_store.cpp \
|
||||
$$PWD/yacreader_server_data_helper.cpp \
|
||||
$$PWD/controllers/versioncontroller.cpp \
|
||||
#v1
|
||||
$$PWD/controllers/v1/comiccontroller.cpp \
|
||||
$$PWD/controllers/v1/errorcontroller.cpp \
|
||||
$$PWD/controllers/v1/foldercontroller.cpp \
|
||||
$$PWD/controllers/v1/folderinfocontroller.cpp \
|
||||
$$PWD/controllers/v1/librariescontroller.cpp \
|
||||
$$PWD/controllers/v1/pagecontroller.cpp \
|
||||
$$PWD/controllers/v1/covercontroller.cpp \
|
||||
$$PWD/controllers/v1/updatecomiccontroller.cpp \
|
||||
$$PWD/controllers/v1/comicdownloadinfocontroller.cpp \
|
||||
$$PWD/controllers/v1/synccontroller.cpp \
|
||||
#v2
|
||||
$$PWD/controllers/v2/comiccontroller_v2.cpp \
|
||||
$$PWD/controllers/v2/errorcontroller_v2.cpp \
|
||||
|
||||
@ -9,17 +9,10 @@
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
using stefanfrings::HttpResponse;
|
||||
using stefanfrings::HttpSessionStore;
|
||||
using stefanfrings::StaticFileController;
|
||||
using stefanfrings::TemplateLoader;
|
||||
|
||||
QString Static::configDir = nullptr;
|
||||
|
||||
TemplateLoader *Static::templateLoader = nullptr;
|
||||
|
||||
HttpSessionStore *Static::sessionStore = nullptr;
|
||||
|
||||
StaticFileController *Static::staticFileController = 0;
|
||||
|
||||
YACReaderHttpSessionStore *Static::yacreaderSessionStore = nullptr;
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
#define STATIC_H
|
||||
|
||||
#include <QString>
|
||||
#include "templatecache.h"
|
||||
#include "httpsessionstore.h"
|
||||
#include "staticfilecontroller.h"
|
||||
|
||||
#include "yacreader_http_session_store.h"
|
||||
@ -46,12 +44,6 @@ public:
|
||||
*/
|
||||
static QString getConfigDir();
|
||||
|
||||
/** Cache for template files */
|
||||
static stefanfrings::TemplateLoader *templateLoader;
|
||||
|
||||
/** Storage for session cookies */
|
||||
static stefanfrings::HttpSessionStore *sessionStore;
|
||||
|
||||
static YACReaderHttpSessionStore *yacreaderSessionStore;
|
||||
|
||||
/** Controller for static files */
|
||||
|
||||
@ -25,12 +25,7 @@
|
||||
#define DESCRIPTION "Comic reader and organizer"
|
||||
|
||||
using stefanfrings::HttpListener;
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
using stefanfrings::HttpSessionStore;
|
||||
using stefanfrings::StaticFileController;
|
||||
using stefanfrings::TemplateCache;
|
||||
|
||||
void YACReaderHttpServer::start(quint16 port)
|
||||
{
|
||||
@ -38,36 +33,7 @@ void YACReaderHttpServer::start(quint16 port)
|
||||
QCoreApplication *app = QCoreApplication::instance();
|
||||
QString configFileName = YACReader::getSettingsPath() + "/" + QCoreApplication::applicationName() + ".ini";
|
||||
|
||||
// Configure template loader and cache
|
||||
auto templateSettings = new QSettings(configFileName, QSettings::IniFormat, app);
|
||||
templateSettings->beginGroup("templates");
|
||||
|
||||
if (templateSettings->value("cacheSize").isNull())
|
||||
templateSettings->setValue("cacheSize", "160000");
|
||||
|
||||
QString baseTemplatePath = QString("./server/templates");
|
||||
QString templatePath;
|
||||
|
||||
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
|
||||
templatePath = QFileInfo(QString(DATADIR) + "/yacreader", baseTemplatePath).absoluteFilePath();
|
||||
#else
|
||||
templatePath = QFileInfo(QCoreApplication::applicationDirPath(), baseTemplatePath).absoluteFilePath();
|
||||
#endif
|
||||
if (!templateSettings->contains("path"))
|
||||
templateSettings->setValue("path", templatePath);
|
||||
|
||||
Static::templateLoader = new TemplateCache(templateSettings, app);
|
||||
|
||||
// Configure session store
|
||||
auto sessionSettings = new QSettings(configFileName, QSettings::IniFormat, app);
|
||||
sessionSettings->beginGroup("sessions");
|
||||
|
||||
if (sessionSettings->value("expirationTime").isNull())
|
||||
sessionSettings->setValue("expirationTime", 864000000);
|
||||
|
||||
Static::sessionStore = new HttpSessionStore(sessionSettings, app);
|
||||
|
||||
Static::yacreaderSessionStore = new YACReaderHttpSessionStore(Static::sessionStore, app);
|
||||
Static::yacreaderSessionStore = new YACReaderHttpSessionStore(app);
|
||||
|
||||
// Configure static file controller
|
||||
auto fileSettings = new QSettings(configFileName, QSettings::IniFormat, app);
|
||||
|
||||
@ -2,17 +2,9 @@
|
||||
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "httpsessionstore.h"
|
||||
|
||||
using stefanfrings::HttpSessionStore;
|
||||
|
||||
YACReaderHttpSessionStore::YACReaderHttpSessionStore(HttpSessionStore *sessionStore, QObject *parent)
|
||||
: QObject(parent), sessionStore(sessionStore)
|
||||
YACReaderHttpSessionStore::YACReaderHttpSessionStore(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// sessions are no longer http sessions in v2, we need another mechanism for cleaning
|
||||
|
||||
// connect(&cleanupTimer,SIGNAL(timeout()),this,SLOT(sessionTimerEvent()));
|
||||
// cleanupTimer.start(60000);
|
||||
}
|
||||
|
||||
void YACReaderHttpSessionStore::addYACReaderHttpSession(const QByteArray &httpSessionId, YACReaderHttpSession *yacreaderHttpSession)
|
||||
@ -28,20 +20,3 @@ YACReaderHttpSession *YACReaderHttpSessionStore::getYACReaderSessionHttpSession(
|
||||
|
||||
return sessions.value(httpSessionId, nullptr);
|
||||
}
|
||||
|
||||
void YACReaderHttpSessionStore::sessionTimerEvent()
|
||||
{
|
||||
// sessions are no longer http sessions in v2, we are using a token, so sessionStore->getSession(id).isNull() is always true.
|
||||
/*QMutexLocker locker(&mutex);
|
||||
for(const QByteArray &id : sessions.keys())
|
||||
{
|
||||
if(sessionStore->getSession(id).isNull())
|
||||
{
|
||||
YACReaderHttpSession *session = sessions.value(id, nullptr);
|
||||
if(session != nullptr)
|
||||
delete session;
|
||||
|
||||
sessions.remove(id);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -4,34 +4,20 @@
|
||||
#include <QObject>
|
||||
#include <QtCore>
|
||||
|
||||
namespace stefanfrings {
|
||||
class HttpSessionStore;
|
||||
}
|
||||
class YACReaderHttpSession;
|
||||
|
||||
class YACReaderHttpSessionStore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderHttpSessionStore(stefanfrings::HttpSessionStore *sessionStore, QObject *parent = nullptr);
|
||||
explicit YACReaderHttpSessionStore(QObject *parent = nullptr);
|
||||
|
||||
void addYACReaderHttpSession(const QByteArray &httpSessionId, YACReaderHttpSession *yacreaderHttpSession);
|
||||
YACReaderHttpSession *getYACReaderSessionHttpSession(const QByteArray &httpSessionId);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QMap<QByteArray, YACReaderHttpSession *> sessions;
|
||||
stefanfrings::HttpSessionStore *sessionStore;
|
||||
QTimer cleanupTimer;
|
||||
|
||||
QMutex mutex;
|
||||
|
||||
private slots:
|
||||
|
||||
void sessionTimerEvent();
|
||||
};
|
||||
|
||||
#endif // YACREADERHTTPSESSIONSTORE_H
|
||||
|
||||
Reference in New Issue
Block a user