mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 17:18:23 -04:00
Use the new session object in the all the controllers that need yacreader session information.
This commit is contained in:
parent
b3aca9b542
commit
d2e3b51089
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
#include "yacreader_libraries.h"
|
#include "yacreader_libraries.h"
|
||||||
|
#include "yacreader_http_session.h"
|
||||||
|
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "../static.h"
|
#include "../static.h"
|
||||||
@ -18,6 +19,7 @@ ComicController::ComicController() {}
|
|||||||
void ComicController::service(HttpRequest& request, HttpResponse& response)
|
void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
|
||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
@ -44,7 +46,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||||
|
|
||||||
if(!remoteComic)
|
if(!remoteComic)
|
||||||
session.setDownloadedComic(comic.info.hash);
|
ySession->setDownloadedComic(comic.info.hash);
|
||||||
|
|
||||||
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
|
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
|
||||||
|
|
||||||
@ -70,13 +72,13 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
if(remoteComic)
|
if(remoteComic)
|
||||||
{
|
{
|
||||||
QLOG_TRACE() << "remote comic requested";
|
QLOG_TRACE() << "remote comic requested";
|
||||||
session.setCurrentRemoteComic(comic.id, comicFile);
|
ySession->setCurrentRemoteComic(comic.id, comicFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QLOG_TRACE() << "comic requested";
|
QLOG_TRACE() << "comic requested";
|
||||||
session.setCurrentComic(comic.id, comicFile);
|
ySession->setCurrentComic(comic.id, comicFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "covercontroller.h"
|
#include "covercontroller.h"
|
||||||
#include "db_helper.h" //get libraries
|
#include "db_helper.h" //get libraries
|
||||||
#include "yacreader_libraries.h"
|
#include "yacreader_libraries.h"
|
||||||
|
#include "yacreader_http_session.h"
|
||||||
|
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "../static.h"
|
#include "../static.h"
|
||||||
@ -9,8 +10,8 @@ CoverController::CoverController() {}
|
|||||||
|
|
||||||
void CoverController::service(HttpRequest& request, HttpResponse& response)
|
void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
|
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
|
||||||
|
|
||||||
response.setHeader("Content-Type", "image/jpeg");
|
response.setHeader("Content-Type", "image/jpeg");
|
||||||
response.setHeader("Connection","close");
|
response.setHeader("Connection","close");
|
||||||
@ -47,7 +48,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
if (!img.isNull()) {
|
if (!img.isNull()) {
|
||||||
|
|
||||||
int width = 80, height = 120;
|
int width = 80, height = 120;
|
||||||
if(session.getDisplayType()=="@2x")
|
if(ySession->getDisplayType()=="@2x")
|
||||||
{
|
{
|
||||||
width = 160;
|
width = 160;
|
||||||
height = 240;
|
height = 240;
|
||||||
@ -66,7 +67,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
if(folderCover)
|
if(folderCover)
|
||||||
{
|
{
|
||||||
if(session.getDisplayType()=="@2x")
|
if(ySession->getDisplayType()=="@2x")
|
||||||
p.drawImage(0,0,QImage(":/images/f_overlayed_retina.png"));
|
p.drawImage(0,0,QImage(":/images/f_overlayed_retina.png"));
|
||||||
else
|
else
|
||||||
p.drawImage(0,0,QImage(":/images/f_overlayed.png"));
|
p.drawImage(0,0,QImage(":/images/f_overlayed.png"));
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "qnaturalsorting.h"
|
#include "qnaturalsorting.h"
|
||||||
|
|
||||||
|
#include "yacreader_http_session.h"
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
struct LibraryItemSorter
|
struct LibraryItemSorter
|
||||||
@ -26,6 +28,7 @@ FolderController::FolderController() {}
|
|||||||
void FolderController::service(HttpRequest& request, HttpResponse& response)
|
void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
|
||||||
|
|
||||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||||
response.setHeader("Connection","close");
|
response.setHeader("Connection","close");
|
||||||
@ -33,7 +36,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
//QString y = session.get("xxx").toString();
|
//QString y = session.get("xxx").toString();
|
||||||
//response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
//response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||||
|
|
||||||
Template t=Static::templateLoader->getTemplate("folder_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
Template t = Static::templateLoader->getTemplate("folder_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
|
||||||
t.enableWarnings();
|
t.enableWarnings();
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
@ -85,17 +88,17 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
if(folderId == 1)
|
if(folderId == 1)
|
||||||
{
|
{
|
||||||
session.clearNavigationPath();
|
ySession->clearNavigationPath();
|
||||||
session.pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
||||||
t.setVariable(QString("upurl"),"/");
|
t.setVariable(QString("upurl"),"/");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(fromUp)
|
if(fromUp)
|
||||||
session.popNavigationItem();
|
ySession->popNavigationItem();
|
||||||
else //drill down or direct access
|
else //drill down or direct access
|
||||||
{
|
{
|
||||||
QStack<QPair<qulonglong, quint32> > path = session.getNavigationPath();
|
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
|
||||||
bool found=false;
|
bool found=false;
|
||||||
for(QStack<QPair<qulonglong, quint32> >::const_iterator itr = path.begin(); itr!=path.end(); itr++)
|
for(QStack<QPair<qulonglong, quint32> >::const_iterator itr = path.begin(); itr!=path.end(); itr++)
|
||||||
if(itr->first == folderId)
|
if(itr->first == folderId)
|
||||||
@ -106,16 +109,16 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
if(found)
|
if(found)
|
||||||
{
|
{
|
||||||
while(session.topNavigationItem().first != folderId)
|
while(ySession->topNavigationItem().first != folderId)
|
||||||
session.popNavigationItem();
|
ySession->popNavigationItem();
|
||||||
|
|
||||||
session.updateTopItem(QPair<qulonglong,quint32>(folderId,page));
|
ySession->updateTopItem(QPair<qulonglong,quint32>(folderId,page));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
session.pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStack<QPair<qulonglong, quint32> > path = session.getNavigationPath();
|
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
|
||||||
if(path.count()>1)
|
if(path.count()>1)
|
||||||
{
|
{
|
||||||
QPair<qulonglong, quint32> parentItem = path.at(path.count()-2);
|
QPair<qulonglong, quint32> parentItem = path.at(path.count()-2);
|
||||||
@ -146,7 +149,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
int numFoldersAtCurrentPage = qMax(0,qMin(numFolders - indexCurrentPage, elementsPerPage));
|
int numFoldersAtCurrentPage = qMax(0,qMin(numFolders - indexCurrentPage, elementsPerPage));
|
||||||
|
|
||||||
//PATH
|
//PATH
|
||||||
QStack<QPair<qulonglong,quint32> > foldersPath = session.getNavigationPath();
|
QStack<QPair<qulonglong,quint32> > foldersPath = ySession->getNavigationPath();
|
||||||
t.setVariable(QString("library.name"),libraryName);
|
t.setVariable(QString("library.name"),libraryName);
|
||||||
t.setVariable(QString("library.url"),QString("/library/%1/folder/1").arg(libraryId));
|
t.setVariable(QString("library.url"),QString("/library/%1/folder/1").arg(libraryId));
|
||||||
t.loop("path",foldersPath.count()-1);
|
t.loop("path",foldersPath.count()-1);
|
||||||
@ -195,9 +198,9 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
const ComicDB * comic = (ComicDB *)item;
|
const ComicDB * comic = (ComicDB *)item;
|
||||||
t.setVariable(QString("element%1.browse").arg(i),"");
|
t.setVariable(QString("element%1.browse").arg(i),"");
|
||||||
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
||||||
if(!session.isComicOnDevice(comic->info.hash) && !session.isComicDownloaded(comic->info.hash))
|
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)));
|
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 (session.isComicOnDevice(comic->info.hash))
|
else if (ySession->isComicOnDevice(comic->info.hash))
|
||||||
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTED</div>"));
|
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTED</div>"));
|
||||||
else
|
else
|
||||||
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTING</div>"));
|
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTING</div>"));
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "librariescontroller.h"
|
#include "librariescontroller.h"
|
||||||
#include "db_helper.h" //get libraries
|
#include "db_helper.h" //get libraries
|
||||||
#include "yacreader_libraries.h"
|
#include "yacreader_libraries.h"
|
||||||
|
#include "yacreader_http_session.h"
|
||||||
|
|
||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "../static.h"
|
#include "../static.h"
|
||||||
@ -12,13 +13,14 @@ LibrariesController::LibrariesController() {}
|
|||||||
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
|
||||||
|
|
||||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||||
response.setHeader("Connection","close");
|
response.setHeader("Connection","close");
|
||||||
|
|
||||||
session.clearNavigationPath();
|
ySession->clearNavigationPath();
|
||||||
|
|
||||||
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
Template t=Static::templateLoader->getTemplate("libraries_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
|
||||||
t.enableWarnings();
|
t.enableWarnings();
|
||||||
|
|
||||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "comic.h"
|
#include "comic.h"
|
||||||
#include "comiccontroller.h"
|
#include "comiccontroller.h"
|
||||||
|
#include "yacreader_http_session.h"
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
@ -16,6 +18,7 @@ PageController::PageController() {}
|
|||||||
void PageController::service(HttpRequest& request, HttpResponse& response)
|
void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
|
||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||||
bool remote = path.endsWith("remote");
|
bool remote = path.endsWith("remote");
|
||||||
@ -35,14 +38,14 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
if(remote)
|
if(remote)
|
||||||
{
|
{
|
||||||
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
|
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
|
||||||
comicFile = session.getCurrentRemoteComic();
|
comicFile = ySession->getCurrentRemoteComic();
|
||||||
currentComicId = session.getCurrentRemoteComicId();
|
currentComicId = ySession->getCurrentRemoteComicId();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QLOG_TRACE() << "se recupera comic para servir páginas";
|
QLOG_TRACE() << "se recupera comic para servir páginas";
|
||||||
comicFile = session.getCurrentComic();
|
comicFile = ySession->getCurrentComic();
|
||||||
currentComicId = session.getCurrentComicId();
|
currentComicId = ySession->getCurrentComicId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||||
@ -77,9 +80,9 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
{
|
{
|
||||||
//delete comicFile;
|
//delete comicFile;
|
||||||
if(remote)
|
if(remote)
|
||||||
session.dismissCurrentRemoteComic();
|
ySession->dismissCurrentRemoteComic();
|
||||||
else
|
else
|
||||||
session.dismissCurrentComic();
|
ySession->dismissCurrentComic();
|
||||||
}
|
}
|
||||||
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
||||||
response.write("404 not found",true);
|
response.write("404 not found",true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user