mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Made player page transfer over HTTP instead of MySQL #531
This commit is contained in:
parent
26938f4aac
commit
5fde8f7cc5
@ -4,10 +4,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.info.request;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
@ -30,7 +28,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CacheInspectPageRequest implements CacheRequest {
|
||||
public class CacheInspectPageRequest extends InfoRequestWithVariables implements CacheRequest {
|
||||
|
||||
private final UUID player;
|
||||
private final String html;
|
||||
@ -42,6 +40,8 @@ public class CacheInspectPageRequest implements CacheRequest {
|
||||
|
||||
public CacheInspectPageRequest(UUID player, String html) {
|
||||
Verify.nullCheck(player, html);
|
||||
variables.put("player", player.toString());
|
||||
variables.put("html", Base64Util.encode(html));
|
||||
this.player = player;
|
||||
this.html = html;
|
||||
}
|
||||
@ -51,36 +51,25 @@ public class CacheInspectPageRequest implements CacheRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeDataToDatabase() throws WebException {
|
||||
Verify.nullCheck(player, html);
|
||||
|
||||
String encodedHtml = Base64Util.encode(html);
|
||||
try {
|
||||
Database.getActive().transfer().storePlayerHtml(player, encodedHtml);
|
||||
} catch (DBException e) {
|
||||
throw new TransferDatabaseException(e);
|
||||
}
|
||||
public void placeDataToDatabase() {
|
||||
/* Transferred over HTTP */
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response handleRequest(Map<String, String> variables) throws WebException {
|
||||
// Available variables: sender
|
||||
// Available variables: sender, player, html (Base64)
|
||||
|
||||
try {
|
||||
Map<UUID, String> pages = Database.getActive().transfer().getEncodedPlayerHtml();
|
||||
String player = variables.get("player");
|
||||
Verify.nullCheck(player, () -> new BadRequestException("Player UUID 'player' variable not supplied in the request."));
|
||||
UUID uuid = UUID.fromString(player);
|
||||
|
||||
boolean export = Settings.ANALYSIS_EXPORT.isTrue();
|
||||
for (Map.Entry<UUID, String> entry : pages.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
String html = Base64Util.decode(entry.getValue());
|
||||
String html = variables.get("html");
|
||||
Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request"));
|
||||
|
||||
Map<String, String> replace = Collections.singletonMap("networkName", ServerInfo.getServerName());
|
||||
Map<String, String> replace = Collections.singletonMap("networkName", ServerInfo.getServerName());
|
||||
boolean export = Settings.ANALYSIS_EXPORT.isTrue();
|
||||
cache(export, uuid, StrSubstitutor.replace(Base64Util.decode(html), replace));
|
||||
|
||||
cache(export, uuid, StrSubstitutor.replace(html, replace));
|
||||
}
|
||||
} catch (DBException e) {
|
||||
throw new TransferDatabaseException(e);
|
||||
}
|
||||
return DefaultResponses.SUCCESS.get();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Map;
|
||||
@ -25,17 +26,20 @@ import java.util.UUID;
|
||||
public class CacheInspectPluginsTabRequest extends InfoRequestWithVariables implements CacheRequest {
|
||||
|
||||
private final UUID player;
|
||||
private final String html;
|
||||
|
||||
private CacheInspectPluginsTabRequest() {
|
||||
player = null;
|
||||
html = null;
|
||||
}
|
||||
|
||||
public CacheInspectPluginsTabRequest(UUID player, String nav, String html) {
|
||||
Verify.nullCheck(player, nav);
|
||||
variables.put("player", player.toString());
|
||||
variables.put("nav", nav);
|
||||
variables.put("html", html);
|
||||
variables.put("html", Base64Util.encode(html));
|
||||
this.player = player;
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
public static CacheInspectPluginsTabRequest createHandler() {
|
||||
@ -63,7 +67,7 @@ public class CacheInspectPluginsTabRequest extends InfoRequestWithVariables impl
|
||||
|
||||
InspectPagePluginsContent pluginsTab = getPluginsTab(uuid);
|
||||
|
||||
pluginsTab.addTab(serverUUID, nav, html);
|
||||
pluginsTab.addTab(serverUUID, nav, Base64Util.decode(html));
|
||||
return DefaultResponses.SUCCESS.get();
|
||||
}
|
||||
|
||||
@ -73,6 +77,6 @@ public class CacheInspectPluginsTabRequest extends InfoRequestWithVariables impl
|
||||
|
||||
@Override
|
||||
public void runLocally() {
|
||||
getPluginsTab(player).addTab(ServerInfo.getServerUUID(), variables.get("nav"), variables.get("html"));
|
||||
getPluginsTab(player).addTab(ServerInfo.getServerUUID(), variables.get("nav"), html);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.parts.NetworkPageContent;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Map;
|
||||
@ -32,7 +33,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
|
||||
public CacheNetworkPageContentRequest(UUID serverUUID, String html) {
|
||||
Verify.nullCheck(serverUUID, html);
|
||||
variables.put("serverName", ServerInfo.getServerName());
|
||||
variables.put("html", html);
|
||||
variables.put("html", Base64Util.encode(html));
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
@ -47,7 +48,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
|
||||
|
||||
@Override
|
||||
public Response handleRequest(Map<String, String> variables) throws WebException {
|
||||
// Available variables: sender, serverName, html
|
||||
// Available variables: sender, serverName, html (Base64)
|
||||
|
||||
String serverName = variables.get("serverName");
|
||||
Verify.nullCheck(serverName, () -> new BadRequestException("Server name 'serverName' variable not supplied in the request"));
|
||||
@ -55,7 +56,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
|
||||
Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request"));
|
||||
|
||||
NetworkPageContent serversTab = getNetworkPageContent();
|
||||
serversTab.addElement(serverName, html);
|
||||
serversTab.addElement(serverName, Base64Util.decode(html));
|
||||
|
||||
InfoSystem.getInstance().updateNetworkPage();
|
||||
|
||||
@ -68,7 +69,7 @@ public class CacheNetworkPageContentRequest extends InfoRequestWithVariables imp
|
||||
|
||||
@Override
|
||||
public void runLocally() {
|
||||
getNetworkPageContent().addElement(ServerInfo.getServerName(), html);
|
||||
getNetworkPageContent().addElement(ServerInfo.getServerName(), variables.get("html"));
|
||||
}
|
||||
|
||||
public static CacheNetworkPageContentRequest createHandler() {
|
||||
|
Loading…
Reference in New Issue
Block a user