mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 11:04:25 -04:00
Separate v1 and v2 server api classes and execution path.
This commit is contained in:
124
YACReaderLibrary/server/controllers/v1/comiccontroller.cpp
Normal file
124
YACReaderLibrary/server/controllers/v1/comiccontroller.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include "comiccontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
ComicController::ComicController() {}
|
||||
|
||||
void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(2).toLongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
bool remoteComic = path.endsWith("remote");
|
||||
|
||||
//TODO
|
||||
//if(pathElements.size() == 6)
|
||||
//{
|
||||
// QString action = pathElements.at(5);
|
||||
// if(!action.isEmpty() && (action == "close"))
|
||||
// {
|
||||
// session.dismissCurrentComic();
|
||||
// response.write("",true);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
if(!remoteComic)
|
||||
ySession->setDownloadedComic(comic.info.hash);
|
||||
|
||||
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(comicFile != NULL)
|
||||
{
|
||||
QThread * thread = NULL;
|
||||
|
||||
thread = new QThread();
|
||||
|
||||
comicFile->moveToThread(thread);
|
||||
|
||||
connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
|
||||
connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
|
||||
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
comicFile->load(libraries.getPath(libraryId)+comic.path);
|
||||
|
||||
if(thread != NULL)
|
||||
thread->start();
|
||||
|
||||
if(remoteComic)
|
||||
{
|
||||
QLOG_TRACE() << "remote comic requested";
|
||||
ySession->setCurrentRemoteComic(comic.id, comicFile);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "comic requested";
|
||||
ySession->setCurrentComic(comic.id, comicFile);
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
//TODO this field is not used by the client!
|
||||
response.write(QString("library:%1\r\n").arg(libraryName).toUtf8());
|
||||
response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8());
|
||||
if(remoteComic) //send previous and next comics id
|
||||
{
|
||||
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryId, comic.parentId, true);
|
||||
bool found = false;
|
||||
int i;
|
||||
for(i = 0; i < siblings.length(); i++)
|
||||
{
|
||||
if (siblings.at(i)->id == comic.id)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
if(i>0)
|
||||
response.write(QString("previousComic:%1\r\n").arg(siblings.at(i-1)->id).toUtf8());
|
||||
if(i<siblings.length()-1)
|
||||
response.write(QString("nextComic:%1\r\n").arg(siblings.at(i+1)->id).toUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
//ERROR
|
||||
}
|
||||
qDeleteAll(siblings);
|
||||
}
|
||||
response.write(comic.toTXT().toUtf8(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//delete comicFile;
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
23
YACReaderLibrary/server/controllers/v1/comiccontroller.h
Normal file
23
YACReaderLibrary/server/controllers/v1/comiccontroller.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef COMICCONTROLLER_H
|
||||
#define COMICCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
#include <QThread>
|
||||
class Comic;
|
||||
class QString;
|
||||
|
||||
class ComicController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicController);
|
||||
public:
|
||||
/** Constructor */
|
||||
ComicController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICCONTROLLER_H
|
@ -0,0 +1,26 @@
|
||||
#include "comicdownloadinfocontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
|
||||
ComicDownloadInfoController::ComicDownloadInfoController() {}
|
||||
|
||||
|
||||
void ComicDownloadInfoController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
|
||||
qulonglong libraryId = pathElements.at(2).toLongLong();
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
//TODO: check if the comic wasn't found;
|
||||
response.write(QString("fileName:%1\r\n").arg(comic.getFileName()).toUtf8());
|
||||
response.write(QString("fileSize:%1\r\n").arg(comic.getFileSize()).toUtf8(),true);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#ifndef COMICDOWNLOADINFOCONTROLLER_H
|
||||
#define COMICDOWNLOADINFOCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class ComicDownloadInfoController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicDownloadInfoController);
|
||||
public:
|
||||
/** Constructor **/
|
||||
ComicDownloadInfoController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COMICDOWNLOADINFOCONTROLLER_H
|
89
YACReaderLibrary/server/controllers/v1/covercontroller.cpp
Normal file
89
YACReaderLibrary/server/controllers/v1/covercontroller.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "covercontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
CoverController::CoverController() {}
|
||||
|
||||
void CoverController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Connection","close");
|
||||
//response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
QString fileName = pathElements.at(4);
|
||||
|
||||
bool folderCover = request.getParameter("folderCover").length()>0;
|
||||
|
||||
//response.writeText(path+"<br/>");
|
||||
//response.writeText(libraryName+"<br/>");
|
||||
//response.writeText(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName+"<br/>");
|
||||
|
||||
//QFile file(libraries.value(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
//if (file.exists()) {
|
||||
// if (file.open(QIODevice::ReadOnly))
|
||||
// {
|
||||
// qDebug("StaticFileController: Open file %s",qPrintable(file.fileName()));
|
||||
// // Return the file content, do not store in cache
|
||||
// while (!file.atEnd() && !file.error()) {
|
||||
// response.write(file.read(131072));
|
||||
// }
|
||||
// }
|
||||
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
QImage img(libraries.getPath(libraryName)+"/.yacreaderlibrary/covers/"+fileName);
|
||||
if (!img.isNull()) {
|
||||
|
||||
int width = 80, height = 120;
|
||||
if(ySession->getDisplayType()=="@2x")
|
||||
{
|
||||
width = 160;
|
||||
height = 240;
|
||||
}
|
||||
|
||||
if(float(img.width())/img.height() < 0.66666)
|
||||
img = img.scaledToWidth(width,Qt::SmoothTransformation);
|
||||
else
|
||||
img = img.scaledToHeight(height,Qt::SmoothTransformation);
|
||||
|
||||
QImage destImg(width,height,QImage::Format_RGB32);
|
||||
destImg.fill(Qt::black);
|
||||
QPainter p(&destImg);
|
||||
|
||||
p.drawImage((width-img.width())/2,(height-img.height())/2,img);
|
||||
|
||||
if(folderCover)
|
||||
{
|
||||
if(ySession->getDisplayType()=="@2x")
|
||||
p.drawImage(0,0,QImage(":/images/f_overlayed_retina.png"));
|
||||
else
|
||||
p.drawImage(0,0,QImage(":/images/f_overlayed.png"));
|
||||
}
|
||||
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
destImg.save(&buffer, "JPG");
|
||||
response.write(ba,true);
|
||||
}
|
||||
//DONE else, hay que devolver un 404
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
|
20
YACReaderLibrary/server/controllers/v1/covercontroller.h
Normal file
20
YACReaderLibrary/server/controllers/v1/covercontroller.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef COVERCONTROLLER_H
|
||||
#define COVERCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class CoverController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(CoverController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
CoverController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // COVERCONTROLLER_H
|
26
YACReaderLibrary/server/controllers/v1/errorcontroller.cpp
Normal file
26
YACReaderLibrary/server/controllers/v1/errorcontroller.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "errorcontroller.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
ErrorController::ErrorController(int errorCode)
|
||||
:error(errorCode)
|
||||
{}
|
||||
|
||||
void ErrorController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
switch(error)
|
||||
{
|
||||
case 300:
|
||||
response.setStatus(300,"redirect");
|
||||
response.write("<html> <head> <meta http-equiv=\"refresh\" content=\"0; URL=/\"> </head> <body> </body> </html>", true);
|
||||
break;
|
||||
case 404:
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
22
YACReaderLibrary/server/controllers/v1/errorcontroller.h
Normal file
22
YACReaderLibrary/server/controllers/v1/errorcontroller.h
Normal file
@ -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
|
337
YACReaderLibrary/server/controllers/v1/foldercontroller.cpp
Normal file
337
YACReaderLibrary/server/controllers/v1/foldercontroller.cpp
Normal file
@ -0,0 +1,337 @@
|
||||
#include "foldercontroller.h"
|
||||
#include "controllers/v1/errorcontroller.h"
|
||||
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "folder.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
struct LibraryItemSorter
|
||||
{
|
||||
bool operator()(const LibraryItem * a,const LibraryItem * b) const
|
||||
{
|
||||
return naturalSortLessThanCI(a->name,b->name);
|
||||
}
|
||||
};
|
||||
|
||||
FolderController::FolderController() {}
|
||||
|
||||
void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creación del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
bool showlessInfoPerFolder = settings->value(REMOTE_BROWSE_PERFORMANCE_WORKAROUND,false).toBool();
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
response.setHeader("Connection","close");
|
||||
|
||||
//QString y = session.get("xxx").toString();
|
||||
//response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||
|
||||
Template t=Static::templateLoader->getTemplate("folder_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(2).toInt();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong folderId = pathElements.at(4).toULongLong();
|
||||
|
||||
folderId = qMax<qulonglong>(1,folderId);
|
||||
|
||||
QString folderName = DBHelper::getFolderName(libraryId,folderId);
|
||||
if(folderName.isEmpty())
|
||||
{
|
||||
ErrorController(300).service(request,response);
|
||||
return;
|
||||
}
|
||||
|
||||
if(folderId!=1)
|
||||
t.setVariable("folder.name",folderName);
|
||||
else
|
||||
t.setVariable("folder.name",libraryName);
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(libraryId,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryId,folderId);
|
||||
|
||||
//response.writeText(libraryName);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
folderComics.clear();
|
||||
|
||||
//qulonglong backId = DBHelper::getParentFromComicFolderId(libraryName,folderId);
|
||||
|
||||
int page = 0;
|
||||
QByteArray p = request.getParameter("page");
|
||||
if(p.length() != 0)
|
||||
page = p.toInt();
|
||||
|
||||
// /comicIdi/pagei/comicIdj/pagej/....../comicIdn/pagen
|
||||
//QString currentPath = session.get("currentPath").toString();
|
||||
//QStringList pathSize = currentPath.split("/").last().toInt;
|
||||
|
||||
bool fromUp = false;
|
||||
|
||||
QMultiMap<QByteArray,QByteArray> map = request.getParameterMap();
|
||||
if(map.contains("up"))
|
||||
fromUp = true;
|
||||
|
||||
//int upPage = 0;
|
||||
|
||||
if(folderId == 1)
|
||||
{
|
||||
ySession->clearNavigationPath();
|
||||
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
||||
t.setVariable(QString("upurl"),"/");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fromUp)
|
||||
ySession->popNavigationItem();
|
||||
else //drill down or direct access
|
||||
{
|
||||
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
|
||||
bool found=false;
|
||||
for(QStack<QPair<qulonglong, quint32> >::const_iterator itr = path.begin(); itr!=path.end(); itr++)
|
||||
if(itr->first == folderId)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(found)
|
||||
{
|
||||
while(ySession->topNavigationItem().first != folderId)
|
||||
ySession->popNavigationItem();
|
||||
|
||||
ySession->updateTopItem(QPair<qulonglong,quint32>(folderId,page));
|
||||
}
|
||||
else
|
||||
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
|
||||
}
|
||||
|
||||
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
|
||||
if(path.count()>1)
|
||||
{
|
||||
QPair<qulonglong, quint32> parentItem = path.at(path.count()-2);
|
||||
qulonglong upParent = parentItem.first;
|
||||
quint32 upPage = parentItem.second;
|
||||
t.setVariable(QString("upurl"),"/library/" + QString::number(libraryId) + "/folder/" +QString("%1?page=%2&up=true").arg(upParent).arg(upPage));
|
||||
} else
|
||||
t.setVariable(QString("upurl"),"/");
|
||||
}
|
||||
|
||||
int elementsPerPage = 24;
|
||||
|
||||
int numFolders = folderContent.length();
|
||||
//int numComics = folderComics.length();
|
||||
int totalLength = folderContent.length() + folderComics.length();
|
||||
|
||||
// int numFolderPages = numFolders / elementsPerPage + ((numFolders%elementsPerPage)>0?1:0);
|
||||
int numPages = totalLength / elementsPerPage + ((totalLength%elementsPerPage)>0?1:0);
|
||||
|
||||
//response.writeText(QString("Number of pages : %1 <br/>").arg(numPages));
|
||||
|
||||
if(page < 0)
|
||||
page = 0;
|
||||
else if(page >= numPages)
|
||||
page = numPages-1;
|
||||
|
||||
int indexCurrentPage = page*elementsPerPage;
|
||||
int numFoldersAtCurrentPage = qMax(0,qMin(numFolders - indexCurrentPage, elementsPerPage));
|
||||
|
||||
//PATH
|
||||
QStack<QPair<qulonglong,quint32> > foldersPath = ySession->getNavigationPath();
|
||||
t.setVariable(QString("library.name"),libraryName);
|
||||
t.setVariable(QString("library.url"),QString("/library/%1/folder/1").arg(libraryId));
|
||||
t.loop("path",foldersPath.count()-1);
|
||||
for(int i = 1; i < foldersPath.count(); i++){
|
||||
t.setVariable(QString("path%1.url").arg(i-1),QString("/library/%1/folder/%2").arg(libraryId).arg(foldersPath[i].first));
|
||||
t.setVariable(QString("path%1.name").arg(i-1),DBHelper::getFolderName(libraryId,foldersPath[i].first));
|
||||
}
|
||||
|
||||
if(folderContent.length() > 0)
|
||||
{
|
||||
t.loop("element",numFoldersAtCurrentPage);
|
||||
int i = 0;
|
||||
while(i<numFoldersAtCurrentPage)
|
||||
{
|
||||
LibraryItem * item = folderContent.at(i + (page*elementsPerPage));
|
||||
t.setVariable(QString("element%1.name").arg(i),folderContent.at(i + (page*elementsPerPage))->name);
|
||||
if(item->isDir())
|
||||
{
|
||||
t.setVariable(QString("element%1.class").arg(i),"folder");
|
||||
|
||||
if(showlessInfoPerFolder)
|
||||
{
|
||||
t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<LibraryItem *> children = DBHelper::getFolderComicsFromLibrary(libraryId, item->id);
|
||||
if(children.length()>0)
|
||||
{
|
||||
const ComicDB * comic = static_cast<ComicDB*>(children.at(0));
|
||||
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg?folderCover=true").arg(libraryId).arg(comic->info.hash));
|
||||
}
|
||||
else
|
||||
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(libraryId).arg(item->id)));
|
||||
t.setVariable(QString("element%1.cover.browse").arg(i),QString("<a href=\"%1\">").arg(QString("/library/%1/folder/%2").arg(libraryId).arg(item->id)));
|
||||
t.setVariable(QString("element%1.cover.browse.end").arg(i),"</a>");
|
||||
//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.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)));
|
||||
t.setVariable(QString("element%1.read").arg(i),"");
|
||||
|
||||
t.setVariable(QString("element%1.size").arg(i),"");
|
||||
t.setVariable(QString("element%1.pages").arg(i),"");
|
||||
t.setVariable(QString("element%1.status").arg(i),"");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.setVariable(QString("element%1.class").arg(i),"cover");
|
||||
const ComicDB * comic = (ComicDB *)item;
|
||||
t.setVariable(QString("element%1.browse").arg(i),"");
|
||||
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
|
||||
if(!ySession->isComicOnDevice(comic->info.hash) && !ySession->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)));
|
||||
else if (ySession->isComicOnDevice(comic->info.hash))
|
||||
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTED</div>"));
|
||||
else
|
||||
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTING</div>"));
|
||||
|
||||
//t.setVariable(QString("element%1.image.url").arg(i),"/images/f.png");
|
||||
|
||||
t.setVariable(QString("element%1.read").arg(i),QString("<a class =\"readButton\" href=\"%1\">READ</a>").arg("/library/"+QString::number(libraryId)+"/comic/"+QString("%1").arg(comic->id)+"/remote"));
|
||||
|
||||
t.setVariable(QString("element%1.image.url").arg(i),QString("/library/%1/cover/%2.jpg").arg(libraryId).arg(comic->info.hash));
|
||||
|
||||
t.setVariable(QString("element%1.size").arg(i),"<span class=\"comicSize\">" + QString::number(comic->info.hash.right(comic->info.hash.length()-40).toInt()/1024.0/1024.0,'f',2)+"Mb</span>");
|
||||
if(comic->info.hasBeenOpened)
|
||||
t.setVariable(QString("element%1.pages").arg(i),QString("<span class=\"numPages\">%1/%2 pages</span>").arg(comic->info.currentPage).arg(comic->info.numPages.toInt()));
|
||||
else
|
||||
t.setVariable(QString("element%1.pages").arg(i),QString("<span class=\"numPages\">%1 pages</span>").arg(comic->info.numPages.toInt()));
|
||||
|
||||
if(comic->info.read)
|
||||
t.setVariable(QString("element%1.status").arg(i), QString("<div class=\"mark\"><img src=\"/images/readMark.png\" style = \"width: 15px\"/> </div>"));
|
||||
else if(comic->info.hasBeenOpened)
|
||||
t.setVariable(QString("element%1.status").arg(i), QString("<div class=\"mark\"><img src=\"/images/readingMark.png\" style = \"width: 15px\"/> </div>"));
|
||||
else
|
||||
t.setVariable(QString("element%1.status").arg(i),"");
|
||||
|
||||
t.setVariable(QString("element%1.cover.browse").arg(i),"");
|
||||
t.setVariable(QString("element%1.cover.browse.end").arg(i),"");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
t.loop("element",0);
|
||||
}
|
||||
|
||||
if(numPages > 1)
|
||||
{
|
||||
t.setCondition("pageIndex",true);
|
||||
|
||||
QMap<QString,int> indexCount;
|
||||
|
||||
QString firstChar;
|
||||
int xyz = 1;
|
||||
for(QList<LibraryItem *>::const_iterator itr=folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
firstChar = QString((*itr)->name[0]).toUpper();
|
||||
firstChar = firstChar.normalized(QString::NormalizationForm_D).at(0);//TODO _D or _KD??
|
||||
bool ok;
|
||||
/*int dec = */firstChar.toInt(&ok, 10);
|
||||
if(ok)
|
||||
firstChar = "#";
|
||||
//response.writeText(QString("%1 - %2 <br />").arg((*itr)->name).arg(xyz));
|
||||
if(indexCount.contains(firstChar))
|
||||
indexCount.insert(firstChar, indexCount.value(firstChar)+1);
|
||||
else
|
||||
indexCount.insert(firstChar, 1);
|
||||
|
||||
xyz++;
|
||||
}
|
||||
|
||||
QList<QString> index = indexCount.keys();
|
||||
if(index.length()>1)
|
||||
{
|
||||
t.setCondition("alphaIndex",true);
|
||||
|
||||
qSort(index.begin(),index.end(),naturalSortLessThanCI);
|
||||
t.loop("index",index.length());
|
||||
int i=0;
|
||||
int count=0;
|
||||
int indexPage=0;
|
||||
for(QList<QString>::const_iterator itr=index.constBegin();itr!=index.constEnd();itr++)
|
||||
{
|
||||
//response.writeText(QString("%1 - %2 <br />").arg(*itr).arg(count));
|
||||
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(libraryId).arg(folderId).arg(indexPage));
|
||||
i++;
|
||||
count += indexCount.value(*itr);
|
||||
indexPage = count/elementsPerPage;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
t.loop("index",0);
|
||||
t.setCondition("alphaIndex",false);
|
||||
|
||||
}
|
||||
|
||||
t.loop("page",numPages);
|
||||
int z = 0;
|
||||
while(z < numPages)
|
||||
{
|
||||
|
||||
t.setVariable(QString("page%1.url").arg(z),QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(z));
|
||||
t.setVariable(QString("page%1.number").arg(z),QString("%1").arg(z+1));
|
||||
if(page == z)
|
||||
t.setVariable(QString("page%1.current").arg(z),"current");
|
||||
else
|
||||
t.setVariable(QString("page%1.current").arg(z),"");
|
||||
z++;
|
||||
}
|
||||
|
||||
t.setVariable("page.first",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(0));
|
||||
t.setVariable("page.previous",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page==0)?page:page-1));
|
||||
t.setVariable("page.next",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg((page==numPages-1)?page:page+1));
|
||||
t.setVariable("page.last",QString("/library/%1/folder/%2?page=%3").arg(libraryId).arg(folderId).arg(numPages-1));
|
||||
t.setCondition("index", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
t.loop("page",0);
|
||||
t.loop("index",0);
|
||||
t.setCondition("index", false);
|
||||
t.setCondition("pageIndex",false);
|
||||
t.setCondition("alphaIndex",false);
|
||||
}
|
||||
|
||||
t.setVariable("page",QString("%1").arg(page+1));
|
||||
t.setVariable("pages",QString("%1").arg(numPages));
|
||||
|
||||
response.write(t.toUtf8(), true);
|
||||
|
||||
}
|
20
YACReaderLibrary/server/controllers/v1/foldercontroller.h
Normal file
20
YACReaderLibrary/server/controllers/v1/foldercontroller.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef FOLDERCONTROLLER_H
|
||||
#define FOLDERCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
FolderController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // FOLDERCONTROLLER_H
|
@ -0,0 +1,48 @@
|
||||
#include "folderinfocontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
|
||||
FolderInfoController::FolderInfoController() {}
|
||||
|
||||
void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(2).toInt();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||
|
||||
serviceComics(libraryId, parentId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderInfoController::serviceComics(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
{
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
ComicDB * currentComic;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
response.write(QString("/library/%1/comic/%2:%3:%4\r\n").arg(library).arg(currentComic->id).arg(currentComic->getFileName()).arg(currentComic->getFileSize()).toUtf8());
|
||||
delete currentComic;
|
||||
}
|
||||
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
serviceComics(library, currentFolder->id, response);
|
||||
delete currentFolder;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
#ifndef FOLDERINFOCONTROLLER_H
|
||||
#define FOLDERINFOCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderInfoController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderInfoController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
FolderInfoController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
|
||||
private:
|
||||
void serviceComics(const int &library, const qulonglong & folderId, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // FOLDERINFOCONTROLLER_H
|
@ -0,0 +1,42 @@
|
||||
#include "librariescontroller.h"
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
LibrariesController::LibrariesController() {}
|
||||
|
||||
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
response.setHeader("Connection","close");
|
||||
|
||||
ySession->clearNavigationPath();
|
||||
|
||||
Template t=Static::templateLoader->getTemplate("libraries_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
|
||||
t.enableWarnings();
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
|
||||
t.loop("library",names.length());
|
||||
|
||||
int currentId = 0;
|
||||
int i = 0;
|
||||
foreach (QString name,names) {
|
||||
currentId = libraries.getId(name);
|
||||
t.setVariable(QString("library%1.name").arg(i),QString::number(currentId));
|
||||
t.setVariable(QString("library%1.label").arg(i),name);
|
||||
i++;
|
||||
}
|
||||
|
||||
response.setStatus(200,"OK");
|
||||
response.write(t.toUtf8(),true);
|
||||
}
|
25
YACReaderLibrary/server/controllers/v1/librariescontroller.h
Normal file
25
YACReaderLibrary/server/controllers/v1/librariescontroller.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef LIBRARIESCONTROLLER_H
|
||||
#define LIBRARIESCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
/**
|
||||
This controller displays a HTML form and dumps the submitted input.
|
||||
*/
|
||||
|
||||
|
||||
class LibrariesController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(LibrariesController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
LibrariesController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // LIBRARIESCONTROLLER_H
|
99
YACReaderLibrary/server/controllers/v1/pagecontroller.cpp
Normal file
99
YACReaderLibrary/server/controllers/v1/pagecontroller.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "pagecontroller.h"
|
||||
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include "yacreader_http_session.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
#include "db_helper.h"
|
||||
|
||||
PageController::PageController() {}
|
||||
|
||||
void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(session.getId());
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
bool remote = path.endsWith("remote");
|
||||
|
||||
//QByteArray path2=request.getPath();
|
||||
//qDebug("PageController: request to -> %s ",path2.data());
|
||||
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
unsigned int page = pathElements.at(6).toUInt();
|
||||
|
||||
//qDebug("lib name : %s",pathElements.at(2).data());
|
||||
|
||||
Comic * comicFile;
|
||||
qulonglong currentComicId;
|
||||
if(remote)
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
|
||||
comicFile = ySession->getCurrentRemoteComic();
|
||||
currentComicId = ySession->getCurrentRemoteComicId();
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_TRACE() << "se recupera comic para servir páginas";
|
||||
comicFile = ySession->getCurrentComic();
|
||||
currentComicId = ySession->getCurrentComicId();
|
||||
}
|
||||
|
||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||
{
|
||||
if(comicId == currentComicId && page < comicFile->numPages())
|
||||
{
|
||||
if(comicFile->pageIsLoaded(page))
|
||||
{
|
||||
//qDebug("PageController: La página estaba cargada -> %s ",path.data());
|
||||
response.setHeader("Content-Type", "image/jpeg");
|
||||
response.setHeader("Transfer-Encoding","chunked");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
QDataStream data(pageData);
|
||||
char buffer[4096];
|
||||
while (!data.atEnd()) {
|
||||
int len = data.readRawData(buffer,4096);
|
||||
response.write(QByteArray(buffer,len));
|
||||
}
|
||||
//response.write(pageData,true);
|
||||
response.write(QByteArray(),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//qDebug("PageController: La página NO estaba cargada 404 -> %s ",path.data());
|
||||
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(comicId != currentComicId)
|
||||
{
|
||||
//delete comicFile;
|
||||
if(remote)
|
||||
ySession->dismissCurrentRemoteComic();
|
||||
else
|
||||
ySession->dismissCurrentComic();
|
||||
}
|
||||
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
20
YACReaderLibrary/server/controllers/v1/pagecontroller.h
Normal file
20
YACReaderLibrary/server/controllers/v1/pagecontroller.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef PAGECONTROLLER_H
|
||||
#define PAGECONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class PageController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PageController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
PageController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
31
YACReaderLibrary/server/controllers/v1/sessioncontroller.cpp
Normal file
31
YACReaderLibrary/server/controllers/v1/sessioncontroller.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
@file
|
||||
@author Stefan Frings
|
||||
*/
|
||||
|
||||
#include "sessioncontroller.h"
|
||||
#include "../static.h"
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
|
||||
SessionController::SessionController(){}
|
||||
|
||||
void SessionController::service(HttpRequest& request, HttpResponse& response) {
|
||||
|
||||
response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
|
||||
|
||||
// Get current session, or create a new one
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
if (!session.contains("startTime")) {
|
||||
response.write("<html><body>New session started. Reload this page now.</body></html>");
|
||||
session.set("startTime",QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
else {
|
||||
QDateTime startTime=session.get("startTime").toDateTime();
|
||||
response.write("<html><body>Your session started ");
|
||||
response.write(startTime.toString().toLatin1());
|
||||
response.write("</body></html>");
|
||||
}
|
||||
|
||||
}
|
64
YACReaderLibrary/server/controllers/v1/synccontroller.cpp
Normal file
64
YACReaderLibrary/server/controllers/v1/synccontroller.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "synccontroller.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
#include <QUrl>
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
SyncController::SyncController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SyncController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
|
||||
qulonglong libraryId;
|
||||
qulonglong comicId;
|
||||
int currentPage;
|
||||
int currentRating;
|
||||
QString hash;
|
||||
foreach(QString comicInfo, data)
|
||||
{
|
||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
||||
|
||||
if(comicInfoProgress.length() == 4 || comicInfoProgress.length() == 5)
|
||||
{
|
||||
libraryId = comicInfoProgress.at(0).toULongLong();
|
||||
comicId = comicInfoProgress.at(1).toULongLong();
|
||||
hash = comicInfoProgress.at(2);
|
||||
currentPage = comicInfoProgress.at(3).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash; //TODO remove the hash check and add UUIDs for libraries
|
||||
info.id = comicId;
|
||||
|
||||
//Client 2.1+ version
|
||||
if(comicInfoProgress.length() > 4)
|
||||
{
|
||||
currentRating = comicInfoProgress.at(4).toInt();
|
||||
info.rating = currentRating;
|
||||
}
|
||||
|
||||
DBHelper::updateFromRemoteClient(libraryId,info);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
||||
|
21
YACReaderLibrary/server/controllers/v1/synccontroller.h
Normal file
21
YACReaderLibrary/server/controllers/v1/synccontroller.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef SYNCCONTROLLER_H
|
||||
#define SYNCCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class SyncController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SyncController)
|
||||
public:
|
||||
/** Constructor */
|
||||
SyncController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // SYNCCONTROLLER_H
|
@ -0,0 +1,46 @@
|
||||
#include "updatecomiccontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
UpdateComicController::UpdateComicController(){}
|
||||
|
||||
void UpdateComicController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
HttpSession session=Static::sessionStore->getSession(request,response,false);
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
qulonglong libraryId = pathElements.at(2).toULongLong();
|
||||
QString libraryName = DBHelper::getLibraryName(libraryId);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
QString postData = QString::fromUtf8(request.getBody());
|
||||
|
||||
QLOG_TRACE() << "POST DATA: " << postData;
|
||||
|
||||
if(postData.length()>0) {
|
||||
QList<QString> data = postData.split("\n");
|
||||
int currentPage = data.at(0).split(":").at(1).toInt();
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.id = comicId;
|
||||
DBHelper::updateProgress(libraryId,info);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(412,"No comic info received");
|
||||
response.write("",true);
|
||||
return;
|
||||
}
|
||||
|
||||
response.write("OK",true);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef UPDATECOMICCONTROLLER_H
|
||||
#define UPDATECOMICCONTROLLER_H
|
||||
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
class UpdateComicController : public HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(UpdateComicController);
|
||||
|
||||
public:
|
||||
UpdateComicController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // UPDATECOMICCONTROLLER_H
|
Reference in New Issue
Block a user