mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 07:30:41 +09:00
Use config instead of constants, other review commetns
This commit is contained in:
1 parent
c6f10e2195
commit
25099c03ba
4 files changed
+35
-35
No files matched your search
@@ -524,7 +524,8 @@ export default class ControlConnection extends BaseConnection {
|
||||
const cacheKey = `${request.factorioVersion}-${request.hide_deprecated}`;
|
||||
const cachedData = this._controller.modPortalCache.get(cacheKey);
|
||||
|
||||
if (cachedData && Date.now() - cachedData.timestamp < Controller.MOD_PORTAL_CACHE_DURATION) {
|
||||
const cacheDuration = this._controller.config.get("controller.mod_portal_cache_duration_minutes") * 60 * 1000;
|
||||
if (cachedData && Date.now() - cachedData.timestamp < cacheDuration) {
|
||||
return new lib.ModPortalGetAllRequest.Response(cachedData.data);
|
||||
}
|
||||
|
||||
@@ -532,6 +533,7 @@ export default class ControlConnection extends BaseConnection {
|
||||
logger.info(`Fetching mod portal data for ${cacheKey}`);
|
||||
const mods = await lib.ModStore.fetchAllModsFromPortal(
|
||||
request.factorioVersion,
|
||||
this._controller.config.get("controller.mod_portal_page_size"),
|
||||
request.hide_deprecated
|
||||
);
|
||||
this._controller.modPortalCache.set(cacheKey, { timestamp: Date.now(), data: mods });
|
||||
@@ -555,7 +557,6 @@ export default class ControlConnection extends BaseConnection {
|
||||
// Check if mod already exists
|
||||
if (this._controller.modStore.files.has(filename)) {
|
||||
logger.verbose(`Mod ${filename} already exists, skipping download.`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return this._controller.modStore.files.get(filename)!;
|
||||
}
|
||||
|
||||
@@ -564,11 +565,7 @@ export default class ControlConnection extends BaseConnection {
|
||||
const token = this._controller.config.get("controller.factorio_token");
|
||||
|
||||
if (!username || !token) {
|
||||
// Attempt download without credentials - might fail for some mods
|
||||
logger.warn(`Factorio username or token not configured. Attempting anonymous download for ${filename}.`);
|
||||
// Note: The Factorio Mod Portal API might reject downloads without credentials.
|
||||
// Consider throwing an error here if credentials are required by your setup.
|
||||
// throw new lib.RequestError("Factorio credentials (username, token) not configured on the controller.");
|
||||
throw new lib.RequestError("Factorio credentials (username, token) not configured on the controller.");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -97,12 +97,8 @@ export default class Controller {
|
||||
clusterLogBuildInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
// Cache for mod portal requests
|
||||
static MOD_PORTAL_CACHE_DURATION = 30 * 60 * 1000; // 30 minutes
|
||||
modPortalCache = new Map<string, { timestamp: number, data: any[] }>();
|
||||
|
||||
/** @type {?module:lib.ProcessConnector} */
|
||||
process = null;
|
||||
|
||||
static async bootstrap(config: lib.ControllerConfig) {
|
||||
let databaseDirectory = config.get("controller.database_directory");
|
||||
await fs.ensureDir(databaseDirectory);
|
||||
|
||||
Reference in new issue
Block a user