Commit 20e3b8ff authored by ShiroSaki's avatar ShiroSaki Committed by Melledy
Browse files

add support for announcement page

parent 82698d56
......@@ -73,3 +73,4 @@ BuildConfig.java
# macOS
.DS_Store
data/hk4e/announcement/
......@@ -57,5 +57,13 @@
"mi18n_name": "Activity"
}
],
"timezone": -5
"timezone": -5,
"alert": false,
"alert_id": 0,
"pic_list": [],
"pic_total": 0,
"pic_type_list": [],
"pic_alert": false,
"pic_alert_id": 0,
"static_sign": ""
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo;
import emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo;
import emu.grasscutter.server.dispatch.authentication.AuthenticationHandler;
import emu.grasscutter.server.dispatch.authentication.DefaultAuthenticationHandler;
import emu.grasscutter.server.dispatch.http.AnnouncementIndexHandler;
import emu.grasscutter.server.dispatch.http.GachaDetailsHandler;
import emu.grasscutter.server.dispatch.http.GachaRecordHandler;
import emu.grasscutter.server.dispatch.json.*;
......@@ -443,6 +444,11 @@ public final class DispatchServer {
// gacha details
httpServer.get("/gacha/details", new GachaDetailsHandler());
// announcement index
httpServer.get("/hk4e/announcement/*", new AnnouncementIndexHandler());
httpServer.get("/sw.js", new AnnouncementIndexHandler());
httpServer.get("/dora/lib/vue/2.6.11/vue.min.js", new AnnouncementIndexHandler());
// static file support for plugins
httpServer.raw().config.precompressStaticFiles = false; // If this isn't set to false, files such as images may appear corrupted when serving static files
......
package emu.grasscutter.server.dispatch.http;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import static emu.grasscutter.Configuration.DATA;
public class AnnouncementIndexHandler implements HttpContextHandler {
private final String render_template;
private final String render_swjs;
private final String render_vueminjs;
public AnnouncementIndexHandler() {
File template = new File(Utils.toFilePath(DATA("/hk4e/announcement/index.html")));
File swjs = new File(Utils.toFilePath(DATA("/hk4e/announcement/sw.js")));
File vueminjs = new File(Utils.toFilePath(DATA("/hk4e/announcement/vue.min.js")));
this.render_template = template.exists() ? new String(FileUtils.read(template)) : null;
this.render_swjs = swjs.exists() ? new String(FileUtils.read(swjs)) : null;
this.render_vueminjs = vueminjs.exists() ? new String(FileUtils.read(vueminjs)) : null;
}
@Override
public void handle(Request req, Response res) throws IOException {
if (Objects.equals(req.path(), "/sw.js")) {
res.send(render_swjs);
}else if(Objects.equals(req.path(), "/hk4e/announcement/index.html")) {
res.send(render_template);
}else if(Objects.equals(req.path(), "/dora/lib/vue/2.6.11/vue.min.js")){
res.send(render_vueminjs);
}else{
File renderFile = new File(Utils.toFilePath(DATA(req.path())));
if(renderFile.exists()){
String ext = req.path().substring(req.path().lastIndexOf(".") + 1);
switch(ext){
case "css":
res.type("text/css");
res.send(FileUtils.read(renderFile));
break;
case "js":
default:
res.send(FileUtils.read(renderFile));
break;
}
}else{
Grasscutter.getLogger().info( "File not exist: " + req.path());
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment