mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-17 11:42:32 +08:00
Add web documentation
- '/documentation': home page with all links - '/documentation/handbook': html version of the gm handbook - '/documentation/gachamapping': json document with the gacha mappings
This commit is contained in:
committed by
Melledy
Unverified
parent
827044b3da
commit
e3ed396889
@@ -0,0 +1,42 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import static emu.grasscutter.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.Utils;
|
||||
import express.http.Request;
|
||||
import express.http.Response;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
final class RootRequestHandler implements DocumentationHandler {
|
||||
|
||||
private final String template;
|
||||
|
||||
public RootRequestHandler() {
|
||||
ResourceLoader.loadResources();
|
||||
final File templateFile = new File(Utils.toFilePath(DATA("documentation/index.html")));
|
||||
if (templateFile.exists()) {
|
||||
template = new String(FileUtils.read(templateFile), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
Grasscutter.getLogger().warn("File does not exist: " + templateFile);
|
||||
template = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Request request, Response response) {
|
||||
if (template == null) {
|
||||
response.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user