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
c67be23252
commit
61e7bbc5d1
@ -9,6 +9,8 @@
|
|||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
#include "comic.h"
|
#include "comic.h"
|
||||||
|
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
ComicController::ComicController() {}
|
ComicController::ComicController() {}
|
||||||
@ -22,7 +24,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||||
|
|
||||||
bool remoteComic = path.contains("remote");
|
bool remoteComic = path.endsWith("remote");
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
//if(pathElements.size() == 6)
|
//if(pathElements.size() == 6)
|
||||||
@ -67,7 +69,17 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
if(thread != NULL)
|
if(thread != NULL)
|
||||||
thread->start();
|
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");
|
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||||
//TODO this field is not used by the client!
|
//TODO this field is not used by the client!
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "../static.h"
|
#include "../static.h"
|
||||||
|
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
LibrariesController::LibrariesController() {}
|
LibrariesController::LibrariesController() {}
|
||||||
|
|
||||||
@ -24,6 +25,14 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
session.setComicOnDevice(hash);
|
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
|
else
|
||||||
@ -41,6 +50,9 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
//response.writeText(postData);
|
//response.writeText(postData);
|
||||||
|
|
||||||
QList<QString> data = postData.split("\n");
|
QList<QString> data = postData.split("\n");
|
||||||
|
|
||||||
|
QLOG_INFO() << "Data lenght : " << data.length();
|
||||||
|
|
||||||
if(data.length() > 2)
|
if(data.length() > 2)
|
||||||
{
|
{
|
||||||
session.setDeviceType(data.at(0).split(":").at(1));
|
session.setDeviceType(data.at(0).split(":").at(1));
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
|
#include <QsLog.h>
|
||||||
|
|
||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
|
|
||||||
PageController::PageController() {}
|
PageController::PageController() {}
|
||||||
@ -16,6 +18,7 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||||
|
bool remote = path.endsWith("remote");
|
||||||
|
|
||||||
//QByteArray path2=request.getPath();
|
//QByteArray path2=request.getPath();
|
||||||
//qDebug("PageController: request to -> %s ",path2.data());
|
//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());
|
//qDebug("lib name : %s",pathElements.at(2).data());
|
||||||
|
|
||||||
Comic * comicFile = session.getCurrentComic();
|
Comic * comicFile;
|
||||||
if(session.getCurrentComicId() != 0 && !QPointer<Comic>(comicFile).isNull())
|
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))
|
if(comicFile->pageIsLoaded(page))
|
||||||
{
|
{
|
||||||
@ -56,11 +73,14 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(comicId != session.getCurrentComicId())
|
if(comicId != currentComicId)
|
||||||
{
|
{
|
||||||
//delete comicFile;
|
//delete comicFile;
|
||||||
session.dismissCurrentComic();
|
if(remote)
|
||||||
}
|
session.dismissCurrentRemoteComic();
|
||||||
|
else
|
||||||
|
session.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);
|
||||||
}
|
}
|
||||||
@ -73,4 +93,4 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
//response.write(t.toLatin1(),true);
|
//response.write(t.toLatin1(),true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ HttpSession::HttpSession(bool canStore) {
|
|||||||
dataPtr->id=QUuid::createUuid().toString().toLatin1();
|
dataPtr->id=QUuid::createUuid().toString().toLatin1();
|
||||||
dataPtr->yacreaderSessionData.comic = 0;
|
dataPtr->yacreaderSessionData.comic = 0;
|
||||||
dataPtr->yacreaderSessionData.comicId = 0;
|
dataPtr->yacreaderSessionData.comicId = 0;
|
||||||
|
dataPtr->yacreaderSessionData.remoteComic = 0;
|
||||||
|
dataPtr->yacreaderSessionData.remoteComicId = 0;
|
||||||
#ifdef SUPERVERBOSE
|
#ifdef SUPERVERBOSE
|
||||||
qDebug("HttpSession: created new session data with id %s",dataPtr->id.data());
|
qDebug("HttpSession: created new session data with id %s",dataPtr->id.data());
|
||||||
#endif
|
#endif
|
||||||
@ -210,7 +212,7 @@ QSet<QString> HttpSession::getDownloadedComics()
|
|||||||
else
|
else
|
||||||
return QSet<QString>();
|
return QSet<QString>();
|
||||||
}
|
}
|
||||||
//current comic
|
//current comic (import)
|
||||||
qulonglong HttpSession::getCurrentComicId()
|
qulonglong HttpSession::getCurrentComicId()
|
||||||
{
|
{
|
||||||
if(dataPtr)
|
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()
|
QString HttpSession::getDeviceType()
|
||||||
{
|
{
|
||||||
if(dataPtr)
|
if(dataPtr)
|
||||||
@ -269,8 +311,8 @@ void HttpSession::setDeviceType(const QString & device)
|
|||||||
{
|
{
|
||||||
if(dataPtr)
|
if(dataPtr)
|
||||||
{
|
{
|
||||||
dataPtr->yacreaderSessionData.comicsOnDevice.clear(); //TODO crear un método clear que limpie la sesión completamente
|
//dataPtr->yacreaderSessionData.comicsOnDevice.clear(); //TODO crear un método clear que limpie la sesión completamente
|
||||||
dataPtr->yacreaderSessionData.downloadedComics.clear();
|
//dataPtr->yacreaderSessionData.downloadedComics.clear();
|
||||||
dataPtr->yacreaderSessionData.device = device;
|
dataPtr->yacreaderSessionData.device = device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,11 +102,17 @@ public:
|
|||||||
QSet<QString> getComicsOnDevice();
|
QSet<QString> getComicsOnDevice();
|
||||||
QSet<QString> getDownloadedComics();
|
QSet<QString> getDownloadedComics();
|
||||||
|
|
||||||
//current comic
|
//current comic (import)
|
||||||
qulonglong getCurrentComicId();
|
qulonglong getCurrentComicId();
|
||||||
Comic * getCurrentComic();
|
Comic * getCurrentComic();
|
||||||
void dismissCurrentComic();
|
void dismissCurrentComic();
|
||||||
void setCurrentComic(qulonglong id, Comic * comic);
|
void setCurrentComic(qulonglong id, Comic * comic);
|
||||||
|
|
||||||
|
//current comic (read)
|
||||||
|
qulonglong getCurrentRemoteComicId();
|
||||||
|
Comic * getCurrentRemoteComic();
|
||||||
|
void dismissCurrentRemoteComic();
|
||||||
|
void setCurrentRemoteComic(qulonglong id, Comic * comic);
|
||||||
|
|
||||||
//device identification
|
//device identification
|
||||||
QString getDeviceType();
|
QString getDeviceType();
|
||||||
@ -136,11 +142,13 @@ private:
|
|||||||
QString device;
|
QString device;
|
||||||
QString display;
|
QString display;
|
||||||
qulonglong comicId;
|
qulonglong comicId;
|
||||||
|
qulonglong remoteComicId;
|
||||||
|
|
||||||
QStack<int> navigationPath;
|
QStack<int> navigationPath;
|
||||||
QStack<int> foldersPath;
|
QStack<int> foldersPath;
|
||||||
|
|
||||||
Comic * comic;
|
Comic * comic;
|
||||||
|
Comic * remoteComic;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HttpSessionData {
|
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 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 cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation)
|
||||||
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page
|
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
|
QRegExp library("/library/([0-9]+)/.+"); //permite verificar que la biblioteca solicitada existe
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
//se comprueba que la sesión sea la correcta con el fin de evitar accesos no autorizados
|
//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);
|
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||||
if(!session.isNull() && session.contains("ySession"))
|
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))
|
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))
|
else if(comicUpdate.exactMatch(path))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user