mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
bug fixed, the library name is no longer used in the urls of the web library
This commit is contained in:
parent
9fcf7366b1
commit
8a50379d30
@ -17,6 +17,8 @@
|
|||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "folder.h"
|
#include "folder.h"
|
||||||
|
|
||||||
|
#include "qnaturalsorting.h"
|
||||||
|
|
||||||
//server
|
//server
|
||||||
|
|
||||||
//TODO optimizar, evitar que se tenga que leer en cada petición el archivo
|
//TODO optimizar, evitar que se tenga que leer en cada petición el archivo
|
||||||
@ -127,7 +129,22 @@ QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
|||||||
QSqlDatabase::removeDatabase(libraryPath);
|
QSqlDatabase::removeDatabase(libraryPath);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
QList<QString> DBHelper::getLibrariesNames()
|
||||||
|
{
|
||||||
|
QStringList names = getLibraries().keys();
|
||||||
|
qSort(names.begin(),names.end(),naturalSortLessThanCI);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
QString DBHelper::getLibraryName(int id)
|
||||||
|
{
|
||||||
|
QStringList names = getLibrariesNames();
|
||||||
|
if(names.isEmpty())
|
||||||
|
return "";
|
||||||
|
if(id>=0 && id<names.count())
|
||||||
|
return names.at(id);
|
||||||
|
else
|
||||||
|
return names.at(0);
|
||||||
|
}
|
||||||
//objects management
|
//objects management
|
||||||
//deletes
|
//deletes
|
||||||
void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db)
|
void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db)
|
||||||
|
@ -23,6 +23,8 @@ public:
|
|||||||
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
||||||
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
|
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
|
||||||
static QString getFolderName(const QString & libraryName, qulonglong id);
|
static QString getFolderName(const QString & libraryName, qulonglong id);
|
||||||
|
static QList<QString> getLibrariesNames();
|
||||||
|
static QString getLibraryName(int id);
|
||||||
|
|
||||||
//objects management
|
//objects management
|
||||||
//deletes
|
//deletes
|
||||||
|
@ -18,7 +18,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = pathElements.at(2);
|
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
@ -69,7 +69,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
session.setCurrentComic(comic.id, comicFile);
|
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!
|
||||||
response.writeText(QString("library:%1\r\n").arg(libraryName));
|
response.writeText(QString("library:%1\r\n").arg(libraryName));
|
||||||
response.writeText(comic.toTXT(),true);
|
response.writeText(comic.toTXT(),true);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = pathElements.at(2);
|
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||||
QString fileName = pathElements.at(4);
|
QString fileName = pathElements.at(4);
|
||||||
|
|
||||||
//response.writeText(path+"<br/>");
|
//response.writeText(path+"<br/>");
|
||||||
|
@ -33,7 +33,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
t.enableWarnings();
|
t.enableWarnings();
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = pathElements.at(2);
|
int libraryId = pathElements.at(2).toInt();
|
||||||
|
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||||
QString folderName = DBHelper::getFolderName(libraryName,parentId);
|
QString folderName = DBHelper::getFolderName(libraryName,parentId);
|
||||||
if(parentId!=1)
|
if(parentId!=1)
|
||||||
@ -97,7 +98,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
upPage = session.topPage();
|
upPage = session.topPage();
|
||||||
session.pushPage(page);
|
session.pushPage(page);
|
||||||
}
|
}
|
||||||
t.setVariable(QString("upurl"),"/library/" + QUrl::toPercentEncoding(libraryName) + "/folder/" +QString("%1?page=%2&up=true").arg(backId).arg(upPage));
|
t.setVariable(QString("upurl"),"/library/" + QString::number(libraryId) + "/folder/" +QString("%1?page=%2&up=true").arg(backId).arg(upPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if(currentPath.length()>0)
|
/*if(currentPath.length()>0)
|
||||||
@ -150,12 +151,12 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
t.setVariable(QString("element%1.image.width").arg(i),"89px");
|
t.setVariable(QString("element%1.image.width").arg(i),"89px");
|
||||||
t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||||
|
|
||||||
t.setVariable(QString("element%1.browse").arg(i),QString("<a class =\"browseButton\" href=\"%1\">browse</a>").arg(QString("/library/%1/folder/%2").arg(libraryName).arg(item->id)));
|
t.setVariable(QString("element%1.browse").arg(i),QString("<a class =\"browseButton\" href=\"%1\">browse</a>").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id)));
|
||||||
|
|
||||||
//t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
//t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
||||||
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->id));
|
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->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/"+QUrl::toPercentEncoding(libraryName)+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->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)+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*elementsPerPage))->id)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -165,7 +166,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
t.setVariable(QString("element%1.image.width").arg(i),"80px");
|
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.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/"+QUrl::toPercentEncoding(libraryName)+"/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.isComicDownloaded(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
|
||||||
@ -173,7 +174,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
//t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
//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(QString(QUrl::toPercentEncoding(libraryName))).arg(comic->info.hash));
|
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryId).arg(comic->info.hash));
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -262,7 +263,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
{
|
{
|
||||||
//response.writeText(QString("%1 - %2 <br />").arg(*itr).arg(count));
|
//response.writeText(QString("%1 - %2 <br />").arg(*itr).arg(count));
|
||||||
t.setVariable(QString("index%1.indexname").arg(i), *itr);
|
t.setVariable(QString("index%1.indexname").arg(i), *itr);
|
||||||
t.setVariable(QString("index%1.url").arg(i),QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg(indexPage));
|
t.setVariable(QString("index%1.url").arg(i),QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg(indexPage));
|
||||||
i++;
|
i++;
|
||||||
count += indexCount.value(*itr);
|
count += indexCount.value(*itr);
|
||||||
indexPage = count/elementsPerPage;
|
indexPage = count/elementsPerPage;
|
||||||
@ -281,8 +282,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
while(z < numPages)
|
while(z < numPages)
|
||||||
{
|
{
|
||||||
|
|
||||||
t.setVariable(QString("page%1.url").arg(z),QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg(z));
|
t.setVariable(QString("page%1.url").arg(z),QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg(z));
|
||||||
t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z));
|
t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z+1));
|
||||||
if(page == z)
|
if(page == z)
|
||||||
t.setVariable(QString("page%1.current").arg(z),"current");
|
t.setVariable(QString("page%1.current").arg(z),"current");
|
||||||
else
|
else
|
||||||
@ -290,10 +291,10 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
z++;
|
z++;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.setVariable("page.first",QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg(0));
|
t.setVariable("page.first",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg(0));
|
||||||
t.setVariable("page.previous",QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg((page==0)?page:page-1));
|
t.setVariable("page.previous",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg((page==0)?page:page-1));
|
||||||
t.setVariable("page.next",QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg((page==numPages-1)?page:page+1));
|
t.setVariable("page.next",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg((page==numPages-1)?page:page+1));
|
||||||
t.setVariable("page.last",QString("/library/%1/folder/%2?page=%3").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(parentId).arg(numPages-1));
|
t.setVariable("page.last",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(parentId).arg(numPages-1));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -16,7 +16,8 @@ void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = pathElements.at(2);
|
int libraryId = pathElements.at(2).toInt();
|
||||||
|
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||||
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,parentId);
|
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,parentId);
|
||||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryName,parentId);
|
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryName,parentId);
|
||||||
@ -25,14 +26,14 @@ void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||||
{
|
{
|
||||||
currentFolder = (Folder *)(*itr);
|
currentFolder = (Folder *)(*itr);
|
||||||
response.writeText(QString("/library/%1/folder/%2/info\n").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(currentFolder->id));
|
response.writeText(QString("/library/%1/folder/%2/info\n").arg(libraryId).arg(currentFolder->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
ComicDB * currentComic;
|
ComicDB * currentComic;
|
||||||
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
||||||
{
|
{
|
||||||
currentComic = (ComicDB *)(*itr);
|
currentComic = (ComicDB *)(*itr);
|
||||||
response.writeText(QString("/library/%1/comic/%2\n").arg(QString(QUrl::toPercentEncoding(libraryName))).arg(currentComic->id));
|
response.writeText(QString("/library/%1/comic/%2\n").arg(libraryId).arg(currentComic->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include "template.h"
|
#include "template.h"
|
||||||
#include "../static.h"
|
#include "../static.h"
|
||||||
|
|
||||||
|
|
||||||
LibrariesController::LibrariesController() {}
|
LibrariesController::LibrariesController() {}
|
||||||
|
|
||||||
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||||
@ -38,13 +39,12 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
|
||||||
t.enableWarnings();
|
t.enableWarnings();
|
||||||
|
|
||||||
QMap<QString,QString> libraries = DBHelper::getLibraries();
|
QList<QString> names = DBHelper::getLibrariesNames();
|
||||||
QList<QString> names = libraries.keys();
|
|
||||||
|
|
||||||
t.loop("library",names.length());
|
t.loop("library",names.length());
|
||||||
int i=0;
|
int i=0;
|
||||||
while (i<names.length()) {
|
while (i<names.length()) {
|
||||||
t.setVariable(QString("library%1.name").arg(i),QUrl::toPercentEncoding(names.at(i)));
|
t.setVariable(QString("library%1.name").arg(i),QString::number(i));
|
||||||
t.setVariable(QString("library%1.label").arg(i),names.at(i));
|
t.setVariable(QString("library%1.label").arg(i),names.at(i));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
|
#include "db_helper.h"
|
||||||
|
|
||||||
PageController::PageController() {}
|
PageController::PageController() {}
|
||||||
|
|
||||||
void PageController::service(HttpRequest& request, HttpResponse& response)
|
void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||||
@ -19,7 +21,7 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
|
|||||||
//qDebug("PageController: request to -> %s ",path2.data());
|
//qDebug("PageController: request to -> %s ",path2.data());
|
||||||
|
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = pathElements.at(2);
|
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||||
unsigned int page = pathElements.at(6).toUInt();
|
unsigned int page = pathElements.at(6).toUInt();
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ void HttpSession::clearNavigationPath()
|
|||||||
|
|
||||||
int HttpSession::popPage()
|
int HttpSession::popPage()
|
||||||
{
|
{
|
||||||
if(dataPtr)
|
if(dataPtr && !(dataPtr->yacreaderSessionData.navigationPath.isEmpty()))
|
||||||
return dataPtr->yacreaderSessionData.navigationPath.pop();
|
return dataPtr->yacreaderSessionData.navigationPath.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
|||||||
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 library("/library/([^/]+)/.+"); //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();
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ 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)) )
|
if(library.indexIn(path)!=-1 && DBHelper::getLibraries().count() > library.cap(1).toInt() )
|
||||||
{
|
{
|
||||||
//listar el contenido del folder
|
//listar el contenido del folder
|
||||||
if(folder.exactMatch(path))
|
if(folder.exactMatch(path))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user