mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 17:11:43 +01:00
Fixed exported page constantly updating data in the background
This commit is contained in:
parent
b3ef8e5a51
commit
155910554f
@ -75,6 +75,17 @@ public class PlayerPageExporter extends FileExporter {
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public static String[] getRedirections(UUID playerUUID) {
|
||||
String player = "player/";
|
||||
return new String[]{
|
||||
player + playerUUID,
|
||||
player + playerUUID + "/overview",
|
||||
player + playerUUID + "/sessions",
|
||||
player + playerUUID + "/pvppve",
|
||||
player + playerUUID + "/servers",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform export for a player page.
|
||||
*
|
||||
@ -119,13 +130,10 @@ public class PlayerPageExporter extends FileExporter {
|
||||
private void exportReactRedirects(Path toDirectory, UUID playerUUID) throws IOException {
|
||||
if (config.isFalse(PluginSettings.FRONTEND_BETA)) return;
|
||||
|
||||
Resource redirect = files.getResourceFromJar("web/export-redirect.html");
|
||||
String player = "player/";
|
||||
exportReactRedirect(toDirectory, redirect, player + playerUUID);
|
||||
exportReactRedirect(toDirectory, redirect, player + playerUUID + "/overview");
|
||||
exportReactRedirect(toDirectory, redirect, player + playerUUID + "/sessions");
|
||||
exportReactRedirect(toDirectory, redirect, player + playerUUID + "/pvppve");
|
||||
exportReactRedirect(toDirectory, redirect, player + playerUUID + "/servers");
|
||||
Resource redirectPage = files.getResourceFromJar("web/export-redirect.html");
|
||||
for (String redirection : getRedirections(playerUUID)) {
|
||||
exportReactRedirect(toDirectory, redirectPage, redirection);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportReactRedirect(Path toDirectory, Resource redirectHtml, String path) throws IOException {
|
||||
|
@ -132,22 +132,30 @@ public class ServerPageExporter extends FileExporter {
|
||||
export(to, exportPaths.resolveExportPaths(html));
|
||||
}
|
||||
|
||||
public static String[] getRedirections(ServerUUID serverUUID) {
|
||||
String server = "server/";
|
||||
return new String[]{
|
||||
server + serverUUID,
|
||||
server + serverUUID + "/overview",
|
||||
server + serverUUID + "/online-activity",
|
||||
server + serverUUID + "/sessions",
|
||||
server + serverUUID + "/pvppve",
|
||||
server + serverUUID + "/playerbase",
|
||||
server + serverUUID + "/join-addresses",
|
||||
server + serverUUID + "/players",
|
||||
server + serverUUID + "/geolocations",
|
||||
server + serverUUID + "/performance",
|
||||
server + serverUUID + "/plugins-overview",
|
||||
};
|
||||
}
|
||||
|
||||
private void exportReactRedirects(Path toDirectory, ServerUUID serverUUID) throws IOException {
|
||||
if (config.isFalse(PluginSettings.FRONTEND_BETA)) return;
|
||||
|
||||
Resource redirect = files.getResourceFromJar("web/export-redirect.html");
|
||||
String server = "server/";
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID);
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/overview");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/online-activity");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/sessions");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/pvppve");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/playerbase");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/join-addresses");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/players");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/geolocations");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/performance");
|
||||
exportReactRedirect(toDirectory, redirect, server + serverUUID + "/plugins-overview");
|
||||
Resource redirectPage = files.getResourceFromJar("web/export-redirect.html");
|
||||
for (String redirection : getRedirections(serverUUID)) {
|
||||
exportReactRedirect(toDirectory, redirectPage, redirection);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportReactRedirect(Path toDirectory, Resource redirectHtml, String path) throws IOException {
|
||||
|
@ -33,6 +33,7 @@ public enum ErrorPageLang implements Lang {
|
||||
ACCESS_DENIED_403("403AccessDenied", "Access Denied"),
|
||||
NOT_FOUND_404("html.error.404NotFound", "Not Found"),
|
||||
NO_SUCH_SERVER_404("html.error.serverNotSeen", "Server doesn't exist"),
|
||||
NO_SUCH_SERVER_404_EXPORT("html.error.serverNotExported", "Server doesn't exist, its data might not have been exported yet."),
|
||||
PAGE_NOT_FOUND_404("html.error.404PageNotFound", "Page does not exist.");
|
||||
|
||||
private final String key;
|
||||
|
@ -108,6 +108,10 @@ public class Lists {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Lists.Builder<V> addAll(V[] values) {
|
||||
return addAll(Arrays.asList(values));
|
||||
}
|
||||
|
||||
public Lists.Builder<V> apply(UnaryOperator<Lists.Builder<V>> operator) {
|
||||
return operator.apply(this);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.djrapitops.plan.identification.ServerUUID;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
import utilities.RandomData;
|
||||
import utilities.dagger.PlanPluginComponent;
|
||||
@ -78,6 +79,7 @@ public class FullSystemExtension implements ParameterResolver, BeforeAllCallback
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
|
||||
Class<?> type = parameterContext.getParameter().getType();
|
||||
return PlanSystem.class.equals(type) ||
|
||||
PlanFiles.class.equals(type) ||
|
||||
PlanConfig.class.equals(type) ||
|
||||
ServerUUID.class.equals(type) ||
|
||||
PlanPluginComponent.class.equals(type) ||
|
||||
@ -91,6 +93,9 @@ public class FullSystemExtension implements ParameterResolver, BeforeAllCallback
|
||||
if (PlanSystem.class.equals(type)) {
|
||||
return planSystem;
|
||||
}
|
||||
if (PlanFiles.class.equals(type)) {
|
||||
return planSystem.getPlanFiles();
|
||||
}
|
||||
if (PlanConfig.class.equals(type)) {
|
||||
return planSystem.getConfigSystem().getConfig();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ const RedirectPlaceholder = () => {
|
||||
|
||||
const MainPageRedirect = () => {
|
||||
const {authLoaded, authRequired, loggedIn, user} = useAuth();
|
||||
const {isProxy, serverName} = useMetadata();
|
||||
const {isProxy, serverName, serverUUID} = useMetadata();
|
||||
|
||||
if (staticSite) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
@ -58,15 +58,17 @@ const MainPageRedirect = () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (!authLoaded || !serverName) {
|
||||
if (!authLoaded || !serverName || !serverUUID) {
|
||||
return <RedirectPlaceholder/>
|
||||
}
|
||||
|
||||
const server = staticSite ? serverUUID : encodeURIComponent(serverName);
|
||||
const redirectBasedOnPermissions = () => {
|
||||
if (isProxy && user.permissions.includes('page.network')) {
|
||||
return (<Navigate to={"/network/overview"} replace={true}/>)
|
||||
} else if (user.permissions.includes('page.server')) {
|
||||
return (<Navigate to={"/server/" + encodeURIComponent(serverName) + "/overview"} replace={true}/>)
|
||||
return (<Navigate to={"/server/" + server + "/overview"}
|
||||
replace={true}/>)
|
||||
} else if (user.permissions.includes('page.player.other')) {
|
||||
return (<Navigate to={"/players"} replace={true}/>)
|
||||
} else if (user.permissions.includes('page.player.self')) {
|
||||
@ -79,8 +81,9 @@ const MainPageRedirect = () => {
|
||||
} else if (authRequired && loggedIn) {
|
||||
return redirectBasedOnPermissions();
|
||||
} else {
|
||||
return (<Navigate to={isProxy ? "/network/overview" : "/server/" + encodeURIComponent(serverName) + "/overview"}
|
||||
replace={true}/>)
|
||||
return (<Navigate
|
||||
to={isProxy ? "/network/overview" : "/server/" + server + "/overview"}
|
||||
replace={true}/>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ export const useDataRequest = (fetchMethod, parameters) => {
|
||||
const handleResponse = (json, error, skipOldData, timeout) => {
|
||||
if (json) {
|
||||
const timestamp = json.timestamp;
|
||||
if (staticSite || timestamp) {
|
||||
if (!staticSite && timestamp) {
|
||||
// Data has timestamp, the data may come from cache
|
||||
const acceptedTimestamp = timestamp + (refreshBarrierMs ? refreshBarrierMs : 15000);
|
||||
if (acceptedTimestamp < updateRequested) {
|
||||
|
@ -70,7 +70,8 @@ export const doSomeRequest = async (url, statusOptions, axiosFunction) => {
|
||||
}
|
||||
|
||||
export const standard200option = {status: 200, get: response => response.data}
|
||||
const exported404options = {status: 404, get: () => 'Data not yet exported'}
|
||||
|
||||
export const doGetRequest = async url => {
|
||||
return doSomeGetRequest(url, [standard200option])
|
||||
return doSomeGetRequest(url, staticSite ? [standard200option, exported404options] : [standard200option])
|
||||
}
|
@ -143,7 +143,10 @@ const ServerPage = () => {
|
||||
if (error) return <ErrorPage error={error}/>;
|
||||
if (identityLoadingError) {
|
||||
if (identityLoadingError.status === 404) return <ErrorPage
|
||||
error={{title: t('html.error.404NotFound'), message: t('html.error.serverNotSeen')}}/>
|
||||
error={{
|
||||
title: t('html.error.404NotFound'),
|
||||
message: t(staticSite ? 'html.error.serverNotExported' : 'html.error.serverNotSeen')
|
||||
}}/>
|
||||
return <ErrorPage error={identityLoadingError}/>
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user