impr: add local api server configuration cache

This commit is contained in:
Miodec 2023-11-07 16:34:05 +00:00
parent a670ee7d8b
commit 52ea0a6cbd
7 changed files with 124 additions and 1 deletions

View file

@ -9,6 +9,7 @@ declare namespace MonkeyTypes {
mode2: string;
}
//keep this in sync with the frontend
interface Configuration {
maintenance: boolean;
quotes: {

View file

@ -0,0 +1,9 @@
export default class Root {
constructor(private httpClient: Ape.HttpClient) {
this.httpClient = httpClient;
}
async get(): Ape.EndpointResponse {
return await this.httpClient.get("/configuration");
}
}

View file

@ -7,6 +7,7 @@ import Results from "./results";
import Users from "./users";
import ApeKeys from "./ape-keys";
import Public from "./public";
import Configuration from "./configuration";
export default {
Configs,
@ -18,4 +19,5 @@ export default {
Results,
Users,
ApeKeys,
Configuration,
};

View file

@ -19,6 +19,7 @@ const Ape = {
presets: new endpoints.Presets(httpClient),
publicStats: new endpoints.Public(httpClient),
apeKeys: new endpoints.ApeKeys(httpClient),
configuration: new endpoints.Configuration(httpClient),
};
export default Ape;

View file

@ -0,0 +1,18 @@
import Ape from ".";
let config: MonkeyTypes.ServerConfiguration | undefined = undefined;
export function get(): MonkeyTypes.ServerConfiguration | undefined {
return config;
}
export async function sync(): Promise<void> {
const response = await Ape.configuration.get();
if (response.status !== 200) {
console.error("Could not fetch configuration", response.message);
return;
} else {
config = response.data as MonkeyTypes.ServerConfiguration;
}
}

View file

@ -14,6 +14,7 @@ import * as FunboxList from "./test/funbox/funbox-list";
import Konami from "konami";
import { log } from "./controllers/analytics-controller";
import { envConfig } from "./constants/env-config";
import * as ServerConfiguration from "./ape/server-configuration";
if (Misc.isDevEnvironment()) {
$("footer .currentVersion .text").text("localhost");
@ -79,7 +80,10 @@ $(document).ready(() => {
.removeClass("hidden")
.stop(true, true)
.animate({ opacity: 1 }, 250);
if (ConnectionState.get()) PSA.show();
if (ConnectionState.get()) {
PSA.show();
ServerConfiguration.sync();
}
MonkeyPower.init();
new Konami("https://keymash.io/");

View file

@ -914,4 +914,92 @@ declare namespace MonkeyTypes {
histogramDataBucketSize: number;
historyStepSize: number;
}
interface ServerConfiguration {
maintenance: boolean;
quotes: {
reporting: {
enabled: boolean;
maxReports: number;
contentReportLimit: number;
};
submissionsEnabled: boolean;
maxFavorites: number;
};
results: {
savingEnabled: boolean;
objectHashCheckEnabled: boolean;
filterPresets: {
enabled: boolean;
maxPresetsPerUser: number;
};
};
users: {
signUp: boolean;
lastHashesCheck: {
enabled: boolean;
maxHashes: number;
};
autoBan: {
enabled: boolean;
maxCount: number;
maxHours: number;
};
profiles: {
enabled: boolean;
};
discordIntegration: {
enabled: boolean;
};
xp: {
enabled: boolean;
funboxBonus: number;
gainMultiplier: number;
maxDailyBonus: number;
minDailyBonus: number;
streak: {
enabled: boolean;
maxStreakDays: number;
maxStreakMultiplier: number;
};
};
inbox: {
enabled: boolean;
maxMail: number;
};
};
admin: {
endpointsEnabled: boolean;
};
apeKeys: {
endpointsEnabled: boolean;
acceptKeys: boolean;
maxKeysPerUser: number;
apeKeyBytes: number;
apeKeySaltRounds: number;
};
rateLimiting: {
badAuthentication: {
enabled: boolean;
penalty: number;
flaggedStatusCodes: number[];
};
};
dailyLeaderboards: {
enabled: boolean;
leaderboardExpirationTimeInDays: number;
maxResults: number;
validModeRules: ValidModeRule[];
scheduleRewardsModeRules: ValidModeRule[];
topResultsToAnnounce: number;
xpRewardBrackets: RewardBracket[];
};
leaderboards: {
weeklyXp: {
enabled: boolean;
expirationTimeInDays: number;
xpRewardBrackets: RewardBracket[];
};
};
}
}