mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-19 21:40:40 +08:00
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:
committed by
Melledy
Unverified
parent
2661cc5ef3
commit
d912b59d93
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user