mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
[#1019] Exporting of network page
- Exported on enable - Exported when a server sends a /server page
This commit is contained in:
parent
0b3dad1d40
commit
bf30f4b5be
@ -72,7 +72,10 @@ public class ExportSystem implements SubSystem {
|
||||
processing.submitNonCritical(htmlExport::exportAvailablePlayers);
|
||||
}
|
||||
if (config.isTrue(ExportSettings.SERVER_PAGE)) {
|
||||
processing.submitNonCritical(htmlExport::exportAvailableServerPages);
|
||||
processing.submitNonCritical(() -> {
|
||||
htmlExport.cacheNetworkPage();
|
||||
htmlExport.exportAvailableServerPages();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,11 @@ import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.ExportSettings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse;
|
||||
import com.djrapitops.plan.utilities.html.pages.InspectPage;
|
||||
import com.djrapitops.plan.utilities.html.pages.NetworkPage;
|
||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
@ -165,6 +169,35 @@ public class HtmlExport extends SpecificExport {
|
||||
}
|
||||
}
|
||||
|
||||
public void cacheNetworkPage() {
|
||||
if (serverInfo.getServer().isNotProxy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkPage networkPage = pageFactory.networkPage();
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverInfo.getServerUUID()), () -> {
|
||||
try {
|
||||
return new NetworkPageResponse(networkPage);
|
||||
} catch (ParseException e) {
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void exportNetworkPage() {
|
||||
if (serverInfo.getServer().isNotProxy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
cacheNetworkPage();
|
||||
try {
|
||||
exportAvailableServerPage(serverInfo.getServerUUID(), serverInfo.getServer().getName());
|
||||
} catch (IOException e) {
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void exportAvailableServerPages() {
|
||||
try {
|
||||
Map<UUID, String> serverNames = dbSystem.getDatabase().query(ServerQueries.fetchServerNames());
|
||||
|
@ -42,7 +42,7 @@ public abstract class SpecificExport {
|
||||
private final PlanFiles files;
|
||||
protected final ServerInfo serverInfo;
|
||||
|
||||
protected SpecificExport(
|
||||
SpecificExport(
|
||||
PlanFiles files,
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
@ -74,19 +74,19 @@ public abstract class SpecificExport {
|
||||
Files.write(to.toPath(), lines, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
protected File getServerFolder() {
|
||||
File getServerFolder() {
|
||||
File server = new File(getFolder(), "server");
|
||||
server.mkdirs();
|
||||
return server;
|
||||
}
|
||||
|
||||
protected File getPlayerFolder() {
|
||||
File getPlayerFolder() {
|
||||
File player = new File(getFolder(), "player");
|
||||
player.mkdirs();
|
||||
return player;
|
||||
}
|
||||
|
||||
protected void exportPlayerPage(String playerName, String html) throws IOException {
|
||||
void exportPlayerPage(String playerName, String html) throws IOException {
|
||||
List<String> lines = Arrays.asList(html.replace("../", "../../").split("\n"));
|
||||
|
||||
File htmlLocation = new File(getPlayerFolder(), URLEncoder.encode(playerName, "UTF-8").replace(".", "%2E"));
|
||||
@ -96,7 +96,7 @@ public abstract class SpecificExport {
|
||||
export(exportFile, lines);
|
||||
}
|
||||
|
||||
protected void exportAvailablePlayerPage(UUID playerUUID, String name) throws IOException {
|
||||
void exportAvailablePlayerPage(UUID playerUUID, String name) throws IOException {
|
||||
Response response = ResponseCache.loadResponse(PageId.PLAYER.of(playerUUID));
|
||||
if (response == null) {
|
||||
return;
|
||||
@ -106,7 +106,7 @@ public abstract class SpecificExport {
|
||||
exportPlayerPage(name, html);
|
||||
}
|
||||
|
||||
protected void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
|
||||
void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
|
||||
|
||||
Response response = ResponseCache.loadResponse(PageId.SERVER.of(serverUUID));
|
||||
if (response == null) {
|
||||
|
@ -105,7 +105,10 @@ public class CacheAnalysisPageRequest extends InfoRequestWithVariables implement
|
||||
}
|
||||
|
||||
if (config.get(ExportSettings.SERVER_PAGE)) {
|
||||
processing.submitNonCritical(() -> htmlExport.exportServer(serverUUID));
|
||||
processing.submitNonCritical(() -> {
|
||||
htmlExport.exportNetworkPage();
|
||||
htmlExport.exportServer(serverUUID);
|
||||
});
|
||||
}
|
||||
if (config.get(ExportSettings.SERVER_JSON)) {
|
||||
processing.submitNonCritical(() -> jsonExport.exportServerJSON(serverUUID));
|
||||
|
@ -82,7 +82,9 @@ public class ResponseCache {
|
||||
*/
|
||||
public static void cacheResponse(String identifier, Supplier<Response> loader) {
|
||||
Response response = loader.get();
|
||||
cache.put(identifier, response);
|
||||
if (response != null) {
|
||||
cache.put(identifier, response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user