mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
fixed comics management on server sersion
This commit is contained in:
parent
b54264da06
commit
0e166fec4a
@ -211,7 +211,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
//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(!session.isComicOnDevice(comic->info.hash) && !session.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.isComicDownloaded(comic->info.hash))
|
else if (session.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>"));
|
||||||
|
@ -12,66 +12,11 @@ LibrariesController::LibrariesController() {}
|
|||||||
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||||
if(session.contains("ySession")) //session is already alive check if it is needed to update comics
|
|
||||||
{
|
|
||||||
QString postData = QString::fromUtf8(request.getBody());
|
|
||||||
if(postData.length()>0) {
|
|
||||||
QList<QString> data = postData.split("\n");
|
|
||||||
if(data.length() > 2) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(data.length()>1)
|
|
||||||
{
|
|
||||||
session.setDeviceType(data.at(0).split(":").at(1));
|
|
||||||
session.setDisplayType(data.at(1).split(":").at(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
session.set("ySession","ok");
|
|
||||||
|
|
||||||
session.clearNavigationPath();
|
response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
|
||||||
session.clearFoldersPath();
|
response.setHeader("Connection","close");
|
||||||
|
|
||||||
response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
|
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
||||||
response.setHeader("Connection","close");
|
|
||||||
|
|
||||||
|
|
||||||
QString postData = QString::fromUtf8(request.getBody());
|
|
||||||
//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));
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //values by default, only for debug purposes.
|
|
||||||
{
|
|
||||||
session.setDeviceType("ipad");
|
|
||||||
session.setDisplayType("@2x");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
|
||||||
t.enableWarnings();
|
t.enableWarnings();
|
||||||
|
|
||||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||||
|
@ -210,7 +210,16 @@ QSet<QString> HttpSession::getDownloadedComics()
|
|||||||
if(dataPtr)
|
if(dataPtr)
|
||||||
return dataPtr->yacreaderSessionData.downloadedComics ;
|
return dataPtr->yacreaderSessionData.downloadedComics ;
|
||||||
else
|
else
|
||||||
return QSet<QString>();
|
return QSet<QString>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpSession::clearComics()
|
||||||
|
{
|
||||||
|
if(dataPtr)
|
||||||
|
{
|
||||||
|
dataPtr->yacreaderSessionData.comicsOnDevice.clear();
|
||||||
|
dataPtr->yacreaderSessionData.downloadedComics.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//current comic (import)
|
//current comic (import)
|
||||||
qulonglong HttpSession::getCurrentComicId()
|
qulonglong HttpSession::getCurrentComicId()
|
||||||
|
@ -101,6 +101,7 @@ public:
|
|||||||
bool isComicDownloaded(const QString & hash);
|
bool isComicDownloaded(const QString & hash);
|
||||||
QSet<QString> getComicsOnDevice();
|
QSet<QString> getComicsOnDevice();
|
||||||
QSet<QString> getDownloadedComics();
|
QSet<QString> getDownloadedComics();
|
||||||
|
void clearComics();
|
||||||
|
|
||||||
//current comic (import)
|
//current comic (import)
|
||||||
qulonglong getCurrentComicId();
|
qulonglong getCurrentComicId();
|
||||||
|
@ -24,9 +24,71 @@
|
|||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
#include "yacreader_libraries.h"
|
#include "yacreader_libraries.h"
|
||||||
|
|
||||||
|
#include "QsLog.h"
|
||||||
|
|
||||||
RequestMapper::RequestMapper(QObject* parent)
|
RequestMapper::RequestMapper(QObject* parent)
|
||||||
:HttpRequestHandler(parent) {}
|
:HttpRequestHandler(parent) {}
|
||||||
|
|
||||||
|
void RequestMapper::loadSession(HttpRequest & request, HttpResponse& response)
|
||||||
|
{
|
||||||
|
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||||
|
if(session.contains("ySession")) //session is already alive check if it is needed to update comics
|
||||||
|
{
|
||||||
|
QString postData = QString::fromUtf8(request.getBody());
|
||||||
|
if(postData.length()>0) {
|
||||||
|
QList<QString> data = postData.split("\n");
|
||||||
|
if(data.length() > 2) {
|
||||||
|
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");
|
||||||
|
session.clearComics();
|
||||||
|
foreach(QString hash,comics) {
|
||||||
|
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
|
||||||
|
{
|
||||||
|
session.set("ySession","ok");
|
||||||
|
|
||||||
|
session.clearNavigationPath();
|
||||||
|
session.clearFoldersPath();
|
||||||
|
|
||||||
|
QString postData = QString::fromUtf8(request.getBody());
|
||||||
|
//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));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //values by default, only for debug purposes.
|
||||||
|
{
|
||||||
|
session.setDeviceType("ipad");
|
||||||
|
session.setDisplayType("@2x");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||||
QByteArray path=request.getPath();
|
QByteArray path=request.getPath();
|
||||||
qDebug("RequestMapper: path=%s",path.data());
|
qDebug("RequestMapper: path=%s",path.data());
|
||||||
@ -41,10 +103,12 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
|||||||
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 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
|
||||||
|
|
||||||
path = QUrl::fromPercentEncoding(path).toLatin1();
|
path = QUrl::fromPercentEncoding(path).toLatin1();
|
||||||
|
|
||||||
|
loadSession(request, response);
|
||||||
|
|
||||||
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
|
//primera petición, se ha hecho un post, se sirven las bibliotecas si la seguridad mediante login no está habilitada
|
||||||
if(path == "/")
|
if(path == "/")
|
||||||
{
|
{
|
||||||
@ -58,6 +122,8 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
|||||||
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"))
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
|
||||||
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) )
|
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().contains(library.cap(1).toInt()) )
|
||||||
{
|
{
|
||||||
//listar el contenido del folder
|
//listar el contenido del folder
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
@param response Must be used to return the response
|
@param response Must be used to return the response
|
||||||
*/
|
*/
|
||||||
void service(HttpRequest& request, HttpResponse& response);
|
void service(HttpRequest& request, HttpResponse& response);
|
||||||
|
void loadSession(HttpRequest & request, HttpResponse& response);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user