🐛 Fix Url error

This commit is contained in:
xtaodada 2022-05-14 13:14:28 +08:00
parent 7cbbd770a5
commit c0ede83066
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 11 additions and 3 deletions

View File

@ -38,12 +38,15 @@ public class GCAuth_OAuth extends Plugin {
public void loadTwitterLogin() { public void loadTwitterLogin() {
String folder_name = PLUGINS_FOLDER + "/GCAuth/OAuth/"; String folder_name = PLUGINS_FOLDER + "/GCAuth/OAuth/";
String Login_Url = ("http" + (DISPATCH_ENCRYPTION.useEncryption ? "s" : "") + "://"
+ lr(DISPATCH_INFO.accessAddress, DISPATCH_INFO.bindAddress) + ":"
+ lr(DISPATCH_INFO.accessPort, DISPATCH_INFO.bindPort) + "/gcauth_oauth/login.html");
Express app = Grasscutter.getDispatchServer().getServer(); Express app = Grasscutter.getDispatchServer().getServer();
app.get("/Api/twitter_login", new JsonHandler()); app.get("/Api/twitter_login", new JsonHandler());
app.get("/sdkTwitterLogin.html", new DispatchHttpJsonHandler( app.get("/sdkTwitterLogin.html", new DispatchHttpJsonHandler(
"<meta http-equiv=\"refresh\" content=\"0;url=https://account.mihoyo.com/gcauth_oauth/login.html\">" String.format("<meta http-equiv=\"refresh\" content=\"0;url=%s\">", Login_Url)
)); ));
app.post("/gcauth_oauth/login", new RequestHandler()); app.post("/gcauth_oauth/login", new RequestHandler());

View File

@ -6,16 +6,21 @@ import express.http.HttpContextHandler;
import express.http.Request; import express.http.Request;
import express.http.Response; import express.http.Response;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.Configuration.DISPATCH_INFO;
public final class JsonHandler implements HttpContextHandler { public final class JsonHandler implements HttpContextHandler {
@Override @Override
public void handle(Request req, Response res) throws IOException { public void handle(Request req, Response res) throws IOException {
String Login_Html_Url = "https://account.mihoyo.com/gcauth_oauth/login.html"; String Login_Url = ("http" + (DISPATCH_ENCRYPTION.useEncryption ? "s" : "") + "://"
+ lr(DISPATCH_INFO.accessAddress, DISPATCH_INFO.bindAddress) + ":"
+ lr(DISPATCH_INFO.accessPort, DISPATCH_INFO.bindPort) + "/gcauth_oauth/login.html");
res.set("server", "tsa_m"); res.set("server", "tsa_m");
res.set("Content-Type", "application/json; charset=utf-8"); res.set("Content-Type", "application/json; charset=utf-8");
res.set("access-control-allow-credentials", "true"); res.set("access-control-allow-credentials", "true");
res.set("access-control-allow-origin", "https://account.hoyoverse.com"); res.set("access-control-allow-origin", "https://account.hoyoverse.com");
res.send(String.format("{\"code\":200,\"data\":{\"auth_url\":\"%s\",\"info\":\"\",\"msg\":\"Success\",\"status\":1}}", res.send(String.format("{\"code\":200,\"data\":{\"auth_url\":\"%s\",\"info\":\"\",\"msg\":\"Success\",\"status\":1}}",
Login_Html_Url)); Login_Url));
} }
} }