mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
fixed simultaneously importing and remote reading
This commit is contained in:
parent
848382cc6c
commit
3c6c237e5c
@ -9,6 +9,8 @@
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ComicController::ComicController() {}
|
||||
@ -22,7 +24,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
bool remoteComic = path.contains("remote");
|
||||
bool remoteComic = path.endsWith("remote");
|
||||
|
||||
//TODO
|
||||
//if(pathElements.size() == 6)
|
||||
@ -67,7 +69,17 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
|
||||
session.setCurrentComic(comic.id, comicFile);
|
||||
if(remoteComic)
|
||||
{
|
||||
QLOG_INFO() << "remote comic requested";
|
||||
session.setCurrentRemoteComic(comic.id, comicFile);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_INFO() << "comic requested";
|
||||
session.setCurrentComic(comic.id, comicFile);
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
//TODO this field is not used by the client!
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
LibrariesController::LibrariesController() {}
|
||||
|
||||
@ -24,6 +25,14 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
session.setComicOnDevice(hash);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(data.length()>1)
|
||||
{
|
||||
session.setDeviceType(data.at(0).split(":").at(1));
|
||||
session.setDisplayType(data.at(1).split(":").at(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -41,6 +50,9 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
//response.writeText(postData);
|
||||
|
||||
QList<QString> data = postData.split("\n");
|
||||
|
||||
QLOG_INFO() << "Data lenght : " << data.length();
|
||||
|
||||
if(data.length() > 2)
|
||||
{
|
||||
session.setDeviceType(data.at(0).split(":").at(1));
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
#include "db_helper.h"
|
||||
|
||||
PageController::PageController() {}
|
||||
@ -16,6 +18,7 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||
bool remote = path.endsWith("remote");
|
||||
|
||||
//QByteArray path2=request.getPath();
|
||||
//qDebug("PageController: request to -> %s ",path2.data());
|
||||
@ -27,10 +30,24 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
//qDebug("lib name : %s",pathElements.at(2).data());
|
||||
|
||||
Comic * comicFile = session.getCurrentComic();
|
||||
if(session.getCurrentComicId() != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||
Comic * comicFile;
|
||||
qulonglong currentComicId;
|
||||
if(remote)
|
||||
{
|
||||
QLOG_INFO() << "se recupera comic remoto para servir páginas";
|
||||
comicFile = session.getCurrentRemoteComic();
|
||||
currentComicId = session.getCurrentRemoteComicId();
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_INFO() << "se recupera comic para servir páginas";
|
||||
comicFile = session.getCurrentComic();
|
||||
currentComicId = session.getCurrentComicId();
|
||||
}
|
||||
|
||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||
{
|
||||
if(comicId == session.getCurrentComicId() && page < comicFile->numPages())
|
||||
if(comicId == currentComicId && page < comicFile->numPages())
|
||||
{
|
||||
if(comicFile->pageIsLoaded(page))
|
||||
{
|
||||
@ -56,11 +73,14 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(comicId != session.getCurrentComicId())
|
||||
if(comicId != currentComicId)
|
||||
{
|
||||
//delete comicFile;
|
||||
session.dismissCurrentComic();
|
||||
}
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
session.dismissCurrentRemoteComic();
|
||||
else
|
||||
session.dismissCurrentComic();
|
||||
}
|
||||
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
@ -73,4 +93,4 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ HttpSession::HttpSession(bool canStore) {
|
||||
dataPtr->id=QUuid::createUuid().toString().toLatin1();
|
||||
dataPtr->yacreaderSessionData.comic = 0;
|
||||
dataPtr->yacreaderSessionData.comicId = 0;
|
||||
dataPtr->yacreaderSessionData.remoteComic = 0;
|
||||
dataPtr->yacreaderSessionData.remoteComicId = 0;
|
||||
#ifdef SUPERVERBOSE
|
||||
qDebug("HttpSession: created new session data with id %s",dataPtr->id.data());
|
||||
#endif
|
||||
@ -210,7 +212,7 @@ QSet<QString> HttpSession::getDownloadedComics()
|
||||
else
|
||||
return QSet<QString>();
|
||||
}
|
||||
//current comic
|
||||
//current comic (import)
|
||||
qulonglong HttpSession::getCurrentComicId()
|
||||
{
|
||||
if(dataPtr)
|
||||
@ -249,6 +251,46 @@ void HttpSession::setCurrentComic(qulonglong id, Comic * comic)
|
||||
}
|
||||
}
|
||||
|
||||
//current comic (read)
|
||||
qulonglong HttpSession::getCurrentRemoteComicId()
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.remoteComicId ;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
Comic* HttpSession::getCurrentRemoteComic()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
return dataPtr->yacreaderSessionData.remoteComic ;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
void HttpSession::dismissCurrentRemoteComic()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
if(dataPtr->yacreaderSessionData.remoteComic != 0)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.remoteComic->deleteLater();
|
||||
dataPtr->yacreaderSessionData.remoteComic = 0;
|
||||
}
|
||||
dataPtr->yacreaderSessionData.remoteComicId = 0;
|
||||
}
|
||||
}
|
||||
void HttpSession::setCurrentRemoteComic(qulonglong id, Comic * comic)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dismissCurrentRemoteComic();
|
||||
dataPtr->yacreaderSessionData.remoteComicId = id;
|
||||
dataPtr->yacreaderSessionData.remoteComic = comic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString HttpSession::getDeviceType()
|
||||
{
|
||||
if(dataPtr)
|
||||
@ -269,8 +311,8 @@ void HttpSession::setDeviceType(const QString & device)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicsOnDevice.clear(); //TODO crear un método clear que limpie la sesión completamente
|
||||
dataPtr->yacreaderSessionData.downloadedComics.clear();
|
||||
//dataPtr->yacreaderSessionData.comicsOnDevice.clear(); //TODO crear un método clear que limpie la sesión completamente
|
||||
//dataPtr->yacreaderSessionData.downloadedComics.clear();
|
||||
dataPtr->yacreaderSessionData.device = device;
|
||||
}
|
||||
}
|
||||
|
@ -102,11 +102,17 @@ public:
|
||||
QSet<QString> getComicsOnDevice();
|
||||
QSet<QString> getDownloadedComics();
|
||||
|
||||
//current comic
|
||||
//current comic (import)
|
||||
qulonglong getCurrentComicId();
|
||||
Comic * getCurrentComic();
|
||||
void dismissCurrentComic();
|
||||
void setCurrentComic(qulonglong id, Comic * comic);
|
||||
|
||||
//current comic (read)
|
||||
qulonglong getCurrentRemoteComicId();
|
||||
Comic * getCurrentRemoteComic();
|
||||
void dismissCurrentRemoteComic();
|
||||
void setCurrentRemoteComic(qulonglong id, Comic * comic);
|
||||
|
||||
//device identification
|
||||
QString getDeviceType();
|
||||
@ -136,11 +142,13 @@ private:
|
||||
QString device;
|
||||
QString display;
|
||||
qulonglong comicId;
|
||||
qulonglong remoteComicId;
|
||||
|
||||
QStack<int> navigationPath;
|
||||
QStack<int> foldersPath;
|
||||
|
||||
Comic * comic;
|
||||
Comic * remoteComic;
|
||||
};
|
||||
|
||||
struct HttpSessionData {
|
||||
|
@ -39,6 +39,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
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 library("/library/([0-9]+)/.+"); //permite verificar que la biblioteca solicitada existe
|
||||
|
||||
@ -52,6 +53,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& 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"))
|
||||
@ -73,11 +75,11 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
}
|
||||
else if(comic.exactMatch(path) || comicOpen.exactMatch(path))
|
||||
{
|
||||
ComicController().service(request, response);
|
||||
ComicController().service(request, response);
|
||||
}
|
||||
else if(comicPage.exactMatch(path))
|
||||
else if(comicPage.exactMatch(path) || comicPageRemote.exactMatch(path))
|
||||
{
|
||||
PageController().service(request,response);
|
||||
PageController().service(request,response);
|
||||
}
|
||||
else if(comicUpdate.exactMatch(path))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user