Made server page transfer over HTTP instead of MySQL #531 Fix #542 #552

This commit is contained in:
Rsl1122 2018-04-02 09:46:36 +03:00
parent 5fde8f7cc5
commit abcf2e877a

View File

@ -4,10 +4,8 @@
*/ */
package com.djrapitops.plan.system.info.request; 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.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.response.DefaultResponses; import com.djrapitops.plan.system.webserver.response.DefaultResponses;
@ -27,7 +25,7 @@ import java.util.UUID;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class CacheAnalysisPageRequest implements CacheRequest { public class CacheAnalysisPageRequest extends InfoRequestWithVariables implements CacheRequest {
private final UUID serverUUID; private final UUID serverUUID;
private final String html; private final String html;
@ -40,6 +38,7 @@ public class CacheAnalysisPageRequest implements CacheRequest {
public CacheAnalysisPageRequest(UUID serverUUID, String html) { public CacheAnalysisPageRequest(UUID serverUUID, String html) {
Verify.nullCheck(serverUUID, html); Verify.nullCheck(serverUUID, html);
this.serverUUID = serverUUID; this.serverUUID = serverUUID;
variables.put("html", Base64Util.encode(html));
this.html = html; this.html = html;
} }
@ -48,34 +47,21 @@ public class CacheAnalysisPageRequest implements CacheRequest {
} }
@Override @Override
public void placeDataToDatabase() throws WebException { public void placeDataToDatabase() {
Verify.nullCheck(serverUUID, html); /* Transferred over HTTP */
String encodedHtml = Base64Util.encode(html);
try {
Database.getActive().transfer().storeServerHtml(serverUUID, encodedHtml);
} catch (DBException e) {
throw new TransferDatabaseException(e);
}
} }
@Override @Override
public Response handleRequest(Map<String, String> variables) throws WebException { public Response handleRequest(Map<String, String> variables) throws WebException {
// Available variables: sender // Available variables: sender, html (Base64)
try { UUID serverUUID = UUID.fromString(variables.get("sender"));
Map<UUID, String> pages = Database.getActive().transfer().getEncodedServerHtml();
boolean export = Settings.ANALYSIS_EXPORT.isTrue(); String html = variables.get("html");
for (Map.Entry<UUID, String> entry : pages.entrySet()) { Verify.nullCheck(html, () -> new BadRequestException("HTML 'html' variable not supplied in the request"));
UUID serverUUID = entry.getKey();
String html = Base64Util.decode(entry.getValue());
cache(export, serverUUID, html); boolean export = Settings.ANALYSIS_EXPORT.isTrue();
} cache(export, serverUUID, Base64Util.decode(html));
} catch (DBException e) {
throw new TransferDatabaseException(e);
}
return DefaultResponses.SUCCESS.get(); return DefaultResponses.SUCCESS.get();
} }