mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-19 11:09:53 +08:00
d912b59d93
* 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
32 lines
998 B
Java
32 lines
998 B
Java
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");
|
|
}
|
|
}
|
|
}
|