Utils for gacha history record subsystem

* Auto generate mapping files with command `java -jar grasscutter.jar -gachamap`

* Static file provider
  * For gacha record webpage
  * All static files should be stored at `GRASSCUTTER_RESOURCE/gcstatic/`
  * Can benefit other subsystem in future when webpages involved
This commit is contained in:
mingjun97
2022-05-01 23:17:18 -07:00
committed by Melledy
Unverified
parent 2661cc5ef3
commit d912b59d93
7 changed files with 148 additions and 4 deletions
@@ -0,0 +1,31 @@
package emu.grasscutter.server.http.gcstatic;
import java.io.File;
import java.io.IOException;
import emu.grasscutter.Grasscutter;
import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
public final class StaticFileHandler implements HttpContextHandler {
String static_folder;
public StaticFileHandler() {
static_folder = Grasscutter.getConfig().RESOURCE_FOLDER + "/gcstatic";
}
@Override
public void handle(Request req, Response res) throws IOException {
// Grasscutter.getLogger().info( req.path());
String reqFilename = req.path().replace("/gcstatic", ""); // remove the leading path
reqFilename = reqFilename.replace("/../", "/./"); // security guard to prevent arbitrary read
File resFile = new File(static_folder + reqFilename);
if (resFile.exists()) {
res.sendFile(resFile.toPath());
} else {
res.status(404);
res.send("404");
}
}
}