mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Guardados en sesi?n los datos env?ados del cliente en el POST inicial.
Filtrado "de prueba" de los c?mics que ya estan en el dispositivo.
This commit is contained in:
parent
5c36afecea
commit
0487531bb6
@ -0,0 +1,17 @@
|
||||
#include "errorcontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
ErrorController::ErrorController(int errorCode)
|
||||
:error(errorCode)
|
||||
{}
|
||||
|
||||
void ErrorController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setStatus(300,"redirect");
|
||||
response.write("<html> <head> <meta http-equiv=\"refresh\" content=\"0; URL=/\"> </head> <body> </body> </html>", true);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef ERRORCONTROLLER_H
|
||||
#define ERRORCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ErrorController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ErrorController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
ErrorController(int errorCode);
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
private:
|
||||
int error;
|
||||
};
|
||||
|
||||
#endif // ERRORCONTROLLER_H
|
@ -124,7 +124,10 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
t.setVariable(QString("element%1.image.width").arg(i),"80px");
|
||||
t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
||||
//t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryName).arg(comic->info.hash));
|
||||
if(session.isComicOnDevice(comic->info.hash))
|
||||
t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
else
|
||||
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryName).arg(comic->info.hash));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -15,6 +15,17 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
session.set("xxx","yyy");
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
response.writeText(postData);
|
||||
|
||||
QList<QString> data = postData.split("\n");
|
||||
session.setDeviceType(data.at(0).split(":").at(1));
|
||||
session.setDisplayType(data.at(1).split(":").at(1));
|
||||
QList<QString> comics = data.at(2).split(":").at(1).split("\t");
|
||||
foreach(QString hash,comics)
|
||||
{
|
||||
session.setComicOnDevice(hash);
|
||||
}
|
||||
|
||||
Template t=Static::templateLoader->getTemplate("libraries",request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
@ -160,10 +160,11 @@ void HttpSession::setLastAccess() {
|
||||
}
|
||||
|
||||
//AÑADIDO
|
||||
//sets
|
||||
bool HttpSession::isComicOnDevice(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.downloadedComics.contains(hash);
|
||||
return dataPtr->yacreaderSessionData.comicsOnDevice.contains(hash);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -174,6 +175,42 @@ bool HttpSession::isComicDownloaded(const QString & hash)
|
||||
else
|
||||
return false;
|
||||
}
|
||||
void HttpSession::setComicOnDevice(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicsOnDevice.insert(hash);
|
||||
}
|
||||
}
|
||||
void HttpSession::setComicsOnDevice(const QSet<QString> & set)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicsOnDevice = set;
|
||||
}
|
||||
}
|
||||
void HttpSession::setDownloadedComic(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.downloadedComics.insert(hash);
|
||||
}
|
||||
}
|
||||
QSet<QString> HttpSession::getComicsOnDevice()
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.comicsOnDevice ;
|
||||
else
|
||||
return QSet<QString>();
|
||||
}
|
||||
QSet<QString> HttpSession::getDownloadedComics()
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.downloadedComics ;
|
||||
else
|
||||
return QSet<QString>();
|
||||
}
|
||||
//current comic
|
||||
qulonglong HttpSession::getCurrentComicId()
|
||||
{
|
||||
if(dataPtr)
|
||||
@ -202,21 +239,6 @@ void HttpSession::dismissCurrentComic()
|
||||
dataPtr->yacreaderSessionData.comicId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpSession::setComicsOnDevice(const QSet<QString> & set)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicsOnDevice = set;
|
||||
}
|
||||
}
|
||||
void HttpSession::setDownloadedComic(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.downloadedComics.insert(hash);
|
||||
}
|
||||
}
|
||||
void HttpSession::setCurrentComic(qulonglong id, Comic2 * comic)
|
||||
{
|
||||
if(dataPtr)
|
||||
@ -225,4 +247,35 @@ void HttpSession::setCurrentComic(qulonglong id, Comic2 * comic)
|
||||
dataPtr->yacreaderSessionData.comicId = id;
|
||||
dataPtr->yacreaderSessionData.comic = comic;
|
||||
}
|
||||
}
|
||||
|
||||
QString HttpSession::getDeviceType()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
return dataPtr->yacreaderSessionData.device;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
QString HttpSession::getDisplayType()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
return dataPtr->yacreaderSessionData.display;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void HttpSession::setDeviceType(const QString & device)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.device = device;
|
||||
}
|
||||
}
|
||||
void HttpSession::setDisplayType(const QString & display)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.display = display;
|
||||
}
|
||||
}
|
@ -93,15 +93,26 @@ public:
|
||||
void setLastAccess();
|
||||
|
||||
//AÑADIDO
|
||||
//sets
|
||||
void setComicsOnDevice(const QSet<QString> & set);
|
||||
void setComicOnDevice(const QString & hash);
|
||||
void setDownloadedComic(const QString & hash);
|
||||
bool isComicOnDevice(const QString & hash);
|
||||
bool isComicDownloaded(const QString & hash);
|
||||
QSet<QString> getComicsOnDevice();
|
||||
QSet<QString> getDownloadedComics();
|
||||
|
||||
//current comic
|
||||
qulonglong getCurrentComicId();
|
||||
Comic2 * getCurrentComic();
|
||||
void dismissCurrentComic();
|
||||
|
||||
void setComicsOnDevice(const QSet<QString> & set);
|
||||
void setDownloadedComic(const QString & hash);
|
||||
void setCurrentComic(qulonglong id, Comic2 * comic);
|
||||
|
||||
//device identification
|
||||
QString getDeviceType();
|
||||
QString getDisplayType();
|
||||
void setDeviceType(const QString & device);
|
||||
void setDisplayType(const QString & display);
|
||||
|
||||
private:
|
||||
|
||||
@ -111,6 +122,8 @@ private:
|
||||
//cómics que han sido descargados o están siendo descargados en esta sesión
|
||||
QSet<QString> downloadedComics;
|
||||
//cómic actual que está siendo descargado
|
||||
QString device;
|
||||
QString display;
|
||||
qulonglong comicId;
|
||||
Comic2 * comic;
|
||||
};
|
||||
|
@ -18,13 +18,14 @@
|
||||
#include "controllers/comiccontroller.h"
|
||||
#include "controllers/folderinfocontroller.h"
|
||||
#include "controllers/pagecontroller.h"
|
||||
#include "controllers/errorcontroller.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
|
||||
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
QByteArray path=request.getPath();
|
||||
qDebug("RequestMapper: path=%s",path.data());
|
||||
QByteArray path=request.getPath();
|
||||
qDebug("RequestMapper: path=%s",path.data());
|
||||
|
||||
QRegExp folder("/library/.+/folder/[0-9]+/?");//(?page=[0-9]+)?
|
||||
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?");
|
||||
@ -38,30 +39,45 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
{
|
||||
LibrariesController().service(request, response);
|
||||
}
|
||||
//listar el contenido del folder
|
||||
else if(folder.exactMatch(path))
|
||||
|
||||
else
|
||||
|
||||
{
|
||||
FolderController().service(request, response);
|
||||
//se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
if(session.contains("xxx"))
|
||||
{
|
||||
|
||||
//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(comic.exactMatch(path))
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
}
|
||||
else if(comicPage.exactMatch(path))
|
||||
{
|
||||
PageController().service(request,response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Static::staticFileController->service(request, response);
|
||||
}
|
||||
}
|
||||
else //acceso no autorizado
|
||||
{
|
||||
ErrorController(403).service(request,response);
|
||||
}
|
||||
}
|
||||
else if (folderInfo.exactMatch(path))
|
||||
{
|
||||
FolderInfoController().service(request, response);
|
||||
}
|
||||
else if(cover.exactMatch(path))
|
||||
{
|
||||
CoverController().service(request, response);
|
||||
}
|
||||
else if(comic.exactMatch(path))
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
}
|
||||
else if(comicPage.exactMatch(path))
|
||||
{
|
||||
PageController().service(request,response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Static::staticFileController->service(request, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user