mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Use better http status code to notify clientes about what is going on while loading comics.
This commit is contained in:
parent
30211233af
commit
e4b4f96369
@ -21,24 +21,24 @@ void PageControllerV2::service(HttpRequest& request, HttpResponse& response)
|
|||||||
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
|
YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
|
||||||
|
|
||||||
if (ySession == nullptr) {
|
if (ySession == nullptr) {
|
||||||
response.setStatus(404,"not found");
|
response.setStatus(424,"no session for this comic");
|
||||||
response.write("404 not found",true);
|
response.write("424 no session for this comic",true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||||
bool remote = path.endsWith("remote");
|
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());
|
||||||
|
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
|
||||||
qulonglong comicId = pathElements.at(5).toULongLong();
|
qulonglong comicId = pathElements.at(5).toULongLong();
|
||||||
unsigned int page = pathElements.at(7).toUInt();
|
unsigned int page = pathElements.at(7).toUInt();
|
||||||
|
|
||||||
//qDebug("lib name : %s",pathElements.at(2).data());
|
//qDebug("lib name : %s",pathElements.at(2).data());
|
||||||
|
|
||||||
Comic * comicFile;
|
Comic * comicFile;
|
||||||
qulonglong currentComicId;
|
qulonglong currentComicId;
|
||||||
if(remote)
|
if(remote)
|
||||||
@ -53,53 +53,58 @@ void PageControllerV2::service(HttpRequest& request, HttpResponse& response)
|
|||||||
comicFile = ySession->getCurrentComic();
|
comicFile = ySession->getCurrentComic();
|
||||||
currentComicId = ySession->getCurrentComicId();
|
currentComicId = ySession->getCurrentComicId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
|
||||||
{
|
{
|
||||||
if(comicId == currentComicId && page < comicFile->numPages())
|
if (comicFile->numPages() == 0) {
|
||||||
{
|
response.setStatus(412,"opening file");
|
||||||
if(comicFile->pageIsLoaded(page))
|
response.write("412 opening file",true);
|
||||||
{
|
} else {
|
||||||
//qDebug("PageController: La página estaba cargada -> %s ",path.data());
|
if(comicId == currentComicId && page < comicFile->numPages())
|
||||||
response.setHeader("Content-Type", "image/jpeg");
|
{
|
||||||
response.setHeader("Transfer-Encoding","chunked");
|
if(comicFile->pageIsLoaded(page))
|
||||||
QByteArray pageData = comicFile->getRawPage(page);
|
{
|
||||||
QDataStream data(pageData);
|
//qDebug("PageController: La página estaba cargada -> %s ",path.data());
|
||||||
char buffer[4096];
|
response.setHeader("Content-Type", "image/jpeg");
|
||||||
while (!data.atEnd()) {
|
response.setHeader("Transfer-Encoding","chunked");
|
||||||
int len = data.readRawData(buffer,4096);
|
QByteArray pageData = comicFile->getRawPage(page);
|
||||||
response.write(QByteArray(buffer,len));
|
QDataStream data(pageData);
|
||||||
}
|
char buffer[100000];
|
||||||
//response.write(pageData,true);
|
while (!data.atEnd()) {
|
||||||
response.write(QByteArray(),true);
|
int len = data.readRawData(buffer,100000);
|
||||||
}
|
response.write(QByteArray(buffer,len));
|
||||||
else
|
}
|
||||||
{
|
//response.write(pageData,true);
|
||||||
//qDebug("PageController: La página NO estaba cargada 404 -> %s ",path.data());
|
response.write(QByteArray(),true);
|
||||||
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
|
else
|
||||||
ySession->dismissCurrentComic();
|
{
|
||||||
|
//qDebug("PageController: La página NO estaba cargada 404 -> %s ",path.data());
|
||||||
|
response.setStatus(412,"loading page"); //TODO qué mensaje enviar
|
||||||
|
response.write("412 loading page",true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
response.setStatus(404,"not found"); //TODO qué mensaje enviar
|
else
|
||||||
response.write("404 not found",true);
|
{
|
||||||
}
|
if(comicId != currentComicId)
|
||||||
}
|
{
|
||||||
else
|
//delete comicFile;
|
||||||
{
|
if(remote)
|
||||||
response.setStatus(404,"not found");
|
ySession->dismissCurrentRemoteComic();
|
||||||
response.write("404 not found",true);
|
else
|
||||||
}
|
ySession->dismissCurrentComic();
|
||||||
|
}
|
||||||
//response.write(t.toLatin1(),true);
|
response.setStatus(412,"not found"); //TODO qué mensaje enviar
|
||||||
|
response.write("412 not found",true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.setStatus(404,"not found");
|
||||||
|
response.write("404 not found",true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//response.write(t.toLatin1(),true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user