mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-22 11:54:39 +01:00
Update HttpServer & AuthenticationSystem to use Javalin
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import express.http.Request;
|
||||
import express.http.Response;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
interface DocumentationHandler {
|
||||
|
||||
void handle(Request request, Response response);
|
||||
void handle(Context ctx);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import emu.grasscutter.server.http.Router;
|
||||
import express.Express;
|
||||
import io.javalin.Javalin;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
public final class DocumentationServerHandler implements Router {
|
||||
|
||||
@Override
|
||||
public void applyRoutes(Express express, Javalin handle) {
|
||||
public void applyRoutes(Javalin javalin) {
|
||||
final RootRequestHandler root = new RootRequestHandler();
|
||||
final HandbookRequestHandler handbook = new HandbookRequestHandler();
|
||||
final GachaMappingRequestHandler gachaMapping = new GachaMappingRequestHandler();
|
||||
|
||||
express.get("/documentation/handbook", handbook::handle);
|
||||
express.get("/documentation/gachamapping", gachaMapping::handle);
|
||||
express.get("/documentation", root::handle);
|
||||
// TODO: Removal
|
||||
// TODO: Forward /documentation requests to https://grasscutter.io/wiki
|
||||
javalin.get("/documentation/handbook", handbook::handle);
|
||||
javalin.get("/documentation/gachamapping", gachaMapping::handle);
|
||||
javalin.get("/documentation", root::handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import emu.grasscutter.tools.Tools;
|
||||
import emu.grasscutter.utils.HttpUtils;
|
||||
import emu.grasscutter.utils.Language;
|
||||
import express.http.Request;
|
||||
import express.http.Response;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.DOCUMENT_LANGUAGE;
|
||||
|
||||
@@ -17,10 +17,8 @@ final class GachaMappingRequestHandler implements DocumentationHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Request request, Response response) {
|
||||
public void handle(Context ctx) {
|
||||
final int langIdx = Language.TextStrings.MAP_LANGUAGES.getOrDefault(DOCUMENT_LANGUAGE, 0); // TODO: This should really be based off the client language somehow
|
||||
response.set("Content-Type", "application/json")
|
||||
.ctx()
|
||||
.result(gachaJsons.get(langIdx));
|
||||
ctx.contentType(HttpUtils.MediaType._json.getMIME()).result(gachaJsons.get(langIdx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import emu.grasscutter.data.excels.ItemData;
|
||||
import emu.grasscutter.data.excels.MonsterData;
|
||||
import emu.grasscutter.data.excels.SceneData;
|
||||
import emu.grasscutter.utils.FileUtils;
|
||||
import emu.grasscutter.utils.HttpUtils;
|
||||
import emu.grasscutter.utils.Language;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import express.http.Request;
|
||||
import express.http.Response;
|
||||
import io.javalin.http.Context;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -36,12 +36,13 @@ final class HandbookRequestHandler implements DocumentationHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Request request, Response response) {
|
||||
public void handle(Context ctx) {
|
||||
final int langIdx = Language.TextStrings.MAP_LANGUAGES.getOrDefault(DOCUMENT_LANGUAGE, 0); // TODO: This should really be based off the client language somehow
|
||||
if (template == null) {
|
||||
response.status(500);
|
||||
ctx.status(500);
|
||||
} else {
|
||||
response.send(handbookHtmls.get(langIdx));
|
||||
ctx.contentType(HttpUtils.MediaType._html.getMIME());
|
||||
ctx.result(handbookHtmls.get(langIdx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import static emu.grasscutter.config.Configuration.DATA;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.ResourceLoader;
|
||||
import emu.grasscutter.utils.FileUtils;
|
||||
import emu.grasscutter.utils.HttpUtils;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import express.http.Request;
|
||||
import express.http.Response;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -27,15 +27,16 @@ final class RootRequestHandler implements DocumentationHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Request request, Response response) {
|
||||
public void handle(Context ctx) {
|
||||
if (template == null) {
|
||||
response.status(500);
|
||||
ctx.status(500);
|
||||
return;
|
||||
}
|
||||
|
||||
String content = template.replace("{{TITLE}}", translate("documentation.index.title"))
|
||||
.replace("{{ITEM_HANDBOOK}}", translate("documentation.index.handbook"))
|
||||
.replace("{{ITEM_GACHA_MAPPING}}", translate("documentation.index.gacha_mapping"));
|
||||
response.send(content);
|
||||
ctx.contentType(HttpUtils.MediaType._html.getMIME());
|
||||
ctx.result(content);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user