MCPcopy Create free account
hub / github.com/YACReader/yacreader / service

Method service

YACReaderLibrary/server/controllers/webui/webuicontroller.cpp:74–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72WebUIController::WebUIController() { }
73
74void WebUIController::service(HttpRequest &request, HttpResponse &response)
75{
76 const QByteArray path = request.getPath();
77 const QByteArray method = request.getMethod();
78
79 if (path == "/") {
80 response.redirect("/webui");
81 return;
82 }
83
84 if (path == "/webui" || path == "/webui/") {
85 if (method != "GET") {
86 methodNotAllowed(response, "GET");
87 return;
88 }
89
90 renderStatusPage(request, response);
91 return;
92 }
93
94 const QRegularExpression libraryBrowserPath(
95 QStringLiteral(R"(^/webui/library/([0-9]+)(?:/(folder|comic)/([0-9]+))?/?$)"));
96 const QRegularExpressionMatch libraryBrowserMatch = libraryBrowserPath.match(QString::fromUtf8(path));
97 if (libraryBrowserMatch.hasMatch()) {
98 if (method != "GET") {
99 methodNotAllowed(response, "GET");
100 return;
101 }
102
103 bool libraryIdIsValid = false;
104 const int libraryId = libraryBrowserMatch.captured(1).toInt(&libraryIdIsValid);
105 const YACReaderLibraries libraries = DBHelper::getLibraries();
106 if (!libraryIdIsValid || !libraries.contains(libraryId)) {
107 response.setStatus(404, "Not Found");
108 response.setHeader("Content-Type", "text/plain; charset=utf-8");
109 response.write("404 library not found", true);
110 return;
111 }
112
113 const QString initialView = libraryBrowserMatch.captured(2).isEmpty() ? QStringLiteral("folder") : libraryBrowserMatch.captured(2);
114 bool itemIdIsValid = false;
115 qulonglong initialItemId = libraryBrowserMatch.captured(3).toULongLong(&itemIdIsValid);
116 if (libraryBrowserMatch.captured(3).isEmpty()) {
117 initialItemId = 1;
118 itemIdIsValid = true;
119 }
120
121 if (!itemIdIsValid) {
122 response.setStatus(404, "Not Found");
123 response.setHeader("Content-Type", "text/plain; charset=utf-8");
124 response.write("404 item not found", true);
125 return;
126 }
127
128 renderLibraryBrowser(request, response, libraryId, libraries.getName(libraryId), initialView, initialItemId);
129 return;
130 }
131

Callers

nothing calls this directly

Calls 6

getPathMethod · 0.80
writeMethod · 0.80
isEmptyMethod · 0.80
methodNotAllowedFunction · 0.70
containsMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected