mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 13:15:39 +00:00
Move the remaining HttpUtils
function over to Router
This commit is contained in:
parent
fee34c515d
commit
4eaedae0b7
@ -3,7 +3,6 @@ package emu.grasscutter.server.http;
|
|||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import io.javalin.core.util.JavalinLogger;
|
import io.javalin.core.util.JavalinLogger;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package emu.grasscutter.server.http;
|
package emu.grasscutter.server.http;
|
||||||
|
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
|
import io.javalin.http.Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines routes for an {@link Javalin} instance.
|
* Defines routes for an {@link Javalin} instance.
|
||||||
@ -12,4 +13,21 @@ public interface Router {
|
|||||||
* @param javalin A Javalin instance.
|
* @param javalin A Javalin instance.
|
||||||
*/
|
*/
|
||||||
void applyRoutes(Javalin javalin);
|
void applyRoutes(Javalin javalin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies this handler to all endpoint types
|
||||||
|
* @param javalin A Javalin instance.
|
||||||
|
* @param path
|
||||||
|
* @param ctx
|
||||||
|
* @return The Javalin instance.
|
||||||
|
*/
|
||||||
|
public default Javalin allRoutes(Javalin javalin, String path, Handler ctx) {
|
||||||
|
javalin.get(path, ctx);
|
||||||
|
javalin.post(path, ctx);
|
||||||
|
javalin.put(path, ctx);
|
||||||
|
javalin.patch(path, ctx);
|
||||||
|
javalin.delete(path, ctx);
|
||||||
|
|
||||||
|
return javalin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package emu.grasscutter.server.http.documentation;
|
package emu.grasscutter.server.http.documentation;
|
||||||
|
|
||||||
import emu.grasscutter.tools.Tools;
|
import emu.grasscutter.tools.Tools;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import emu.grasscutter.utils.Language;
|
import emu.grasscutter.utils.Language;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
|
@ -10,7 +10,6 @@ import emu.grasscutter.data.excels.ItemData;
|
|||||||
import emu.grasscutter.data.excels.MonsterData;
|
import emu.grasscutter.data.excels.MonsterData;
|
||||||
import emu.grasscutter.data.excels.SceneData;
|
import emu.grasscutter.data.excels.SceneData;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import emu.grasscutter.utils.Language;
|
import emu.grasscutter.utils.Language;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
|
@ -5,7 +5,6 @@ import static emu.grasscutter.utils.Language.translate;
|
|||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
|
@ -5,7 +5,6 @@ import emu.grasscutter.data.DataLoader;
|
|||||||
import emu.grasscutter.server.http.objects.HttpJsonResponse;
|
import emu.grasscutter.server.http.objects.HttpJsonResponse;
|
||||||
import emu.grasscutter.server.http.Router;
|
import emu.grasscutter.server.http.Router;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
@ -23,15 +22,15 @@ import java.util.Objects;
|
|||||||
public final class AnnouncementsHandler implements Router {
|
public final class AnnouncementsHandler implements Router {
|
||||||
@Override public void applyRoutes(Javalin javalin) {
|
@Override public void applyRoutes(Javalin javalin) {
|
||||||
// hk4e-api-os.hoyoverse.com
|
// hk4e-api-os.hoyoverse.com
|
||||||
HttpUtils.allRoutes(javalin, "/common/hk4e_global/announcement/api/getAlertPic", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}"));
|
this.allRoutes(javalin, "/common/hk4e_global/announcement/api/getAlertPic", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}"));
|
||||||
// hk4e-api-os.hoyoverse.com
|
// hk4e-api-os.hoyoverse.com
|
||||||
HttpUtils.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAlertAnn", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}"));
|
this.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAlertAnn", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}"));
|
||||||
// hk4e-api-os.hoyoverse.com
|
// hk4e-api-os.hoyoverse.com
|
||||||
HttpUtils.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAnnList", AnnouncementsHandler::getAnnouncement);
|
this.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAnnList", AnnouncementsHandler::getAnnouncement);
|
||||||
// hk4e-api-os-static.hoyoverse.com
|
// hk4e-api-os-static.hoyoverse.com
|
||||||
HttpUtils.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAnnContent", AnnouncementsHandler::getAnnouncement);
|
this.allRoutes(javalin,"/common/hk4e_global/announcement/api/getAnnContent", AnnouncementsHandler::getAnnouncement);
|
||||||
// hk4e-sdk-os.hoyoverse.com
|
// hk4e-sdk-os.hoyoverse.com
|
||||||
HttpUtils.allRoutes(javalin,"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}"));
|
this.allRoutes(javalin,"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}"));
|
||||||
|
|
||||||
javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources);
|
javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import emu.grasscutter.game.gacha.GachaSystem;
|
|||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.server.http.Router;
|
import emu.grasscutter.server.http.Router;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
|
@ -7,7 +7,6 @@ import emu.grasscutter.Grasscutter;
|
|||||||
import emu.grasscutter.server.http.objects.HttpJsonResponse;
|
import emu.grasscutter.server.http.objects.HttpJsonResponse;
|
||||||
import emu.grasscutter.server.http.Router;
|
import emu.grasscutter.server.http.Router;
|
||||||
import emu.grasscutter.server.http.objects.WebStaticVersionResponse;
|
import emu.grasscutter.server.http.objects.WebStaticVersionResponse;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
|
|
||||||
@ -18,9 +17,8 @@ public final class GenericHandler implements Router {
|
|||||||
@Override public void applyRoutes(Javalin javalin) {
|
@Override public void applyRoutes(Javalin javalin) {
|
||||||
// hk4e-sdk-os.hoyoverse.com
|
// hk4e-sdk-os.hoyoverse.com
|
||||||
javalin.get("/hk4e_global/mdk/agreement/api/getAgreementInfos", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));
|
javalin.get("/hk4e_global/mdk/agreement/api/getAgreementInfos", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));
|
||||||
// hk4e-sdk-os.hoyoverse.com
|
// hk4e-sdk-os.hoyoverse.com (this could be either GET or POST based on the observation of different clients)
|
||||||
// this could be either GET or POST based on the observation of different clients
|
this.allRoutes(javalin, "/hk4e_global/combo/granter/api/compareProtocolVersion", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}"));
|
||||||
HttpUtils.allRoutes(javalin, "/hk4e_global/combo/granter/api/compareProtocolVersion", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}"));
|
|
||||||
|
|
||||||
// api-account-os.hoyoverse.com
|
// api-account-os.hoyoverse.com
|
||||||
javalin.post("/account/risky/api/check", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}"));
|
javalin.post("/account/risky/api/check", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}"));
|
||||||
@ -36,11 +34,11 @@ public final class GenericHandler implements Router {
|
|||||||
javalin.post("/data_abtest_api/config/experiment/list", new HttpJsonResponse("{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}"));
|
javalin.post("/data_abtest_api/config/experiment/list", new HttpJsonResponse("{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}"));
|
||||||
|
|
||||||
// log-upload-os.mihoyo.com
|
// log-upload-os.mihoyo.com
|
||||||
HttpUtils.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
|
this.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
|
||||||
HttpUtils.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
|
this.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
|
||||||
javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}"));
|
javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}"));
|
||||||
// /perf/config/verify?device_id=xxx&platform=x&name=xxx
|
// /perf/config/verify?device_id=xxx&platform=x&name=xxx
|
||||||
HttpUtils.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}"));
|
this.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}"));
|
||||||
|
|
||||||
// webstatic-sea.hoyoverse.com
|
// webstatic-sea.hoyoverse.com
|
||||||
javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse());
|
javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse());
|
||||||
|
@ -2,7 +2,6 @@ package emu.grasscutter.server.http.objects;
|
|||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.utils.FileUtils;
|
import emu.grasscutter.utils.FileUtils;
|
||||||
import emu.grasscutter.utils.HttpUtils;
|
|
||||||
import io.javalin.http.ContentType;
|
import io.javalin.http.ContentType;
|
||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
import io.javalin.http.Handler;
|
import io.javalin.http.Handler;
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package emu.grasscutter.utils;
|
|
||||||
|
|
||||||
import io.javalin.Javalin;
|
|
||||||
import io.javalin.http.Handler;
|
|
||||||
|
|
||||||
public final class HttpUtils {
|
|
||||||
|
|
||||||
public static Javalin allRoutes(Javalin javalin, String path, Handler ctx) {
|
|
||||||
javalin.get(path, ctx);
|
|
||||||
javalin.post(path, ctx);
|
|
||||||
javalin.put(path, ctx);
|
|
||||||
javalin.patch(path, ctx);
|
|
||||||
javalin.delete(path, ctx);
|
|
||||||
|
|
||||||
return javalin;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user