feat: plugins v1
This commit is contained in:
@@ -10,6 +10,10 @@ export interface LinkPreviewConfig {
|
||||
maxCacheSizeMb: number;
|
||||
}
|
||||
|
||||
export interface OpenApiDocsConfig {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface ServerVariablesConfig {
|
||||
klipyApiKey: string;
|
||||
rawgApiKey: string;
|
||||
@@ -18,6 +22,7 @@ export interface ServerVariablesConfig {
|
||||
serverProtocol: ServerHttpProtocol;
|
||||
serverHost: string;
|
||||
linkPreview: LinkPreviewConfig;
|
||||
openApiDocs: OpenApiDocsConfig;
|
||||
}
|
||||
|
||||
const DATA_DIR = resolveRuntimePath('data');
|
||||
@@ -102,6 +107,14 @@ function normalizeLinkPreviewConfig(value: unknown): LinkPreviewConfig {
|
||||
return { enabled, cacheTtlMinutes: cacheTtl, maxCacheSizeMb: maxSize };
|
||||
}
|
||||
|
||||
function normalizeOpenApiDocsConfig(value: unknown): OpenApiDocsConfig {
|
||||
const raw = (value && typeof value === 'object' && !Array.isArray(value))
|
||||
? value as Record<string, unknown>
|
||||
: {};
|
||||
|
||||
return { enabled: raw.enabled === true };
|
||||
}
|
||||
|
||||
function hasEnvironmentOverride(value: string | undefined): value is string {
|
||||
return typeof value === 'string' && value.trim().length > 0;
|
||||
}
|
||||
@@ -149,7 +162,8 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
|
||||
serverPort: normalizeServerPort(remainingParsed.serverPort),
|
||||
serverProtocol: normalizeServerProtocol(remainingParsed.serverProtocol),
|
||||
serverHost: normalizeServerHost(remainingParsed.serverHost ?? legacyServerIpAddress),
|
||||
linkPreview: normalizeLinkPreviewConfig(remainingParsed.linkPreview)
|
||||
linkPreview: normalizeLinkPreviewConfig(remainingParsed.linkPreview),
|
||||
openApiDocs: normalizeOpenApiDocsConfig(remainingParsed.openApiDocs)
|
||||
};
|
||||
const nextContents = JSON.stringify(normalized, null, 2) + '\n';
|
||||
|
||||
@@ -164,7 +178,8 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
|
||||
serverPort: normalized.serverPort,
|
||||
serverProtocol: normalized.serverProtocol,
|
||||
serverHost: normalized.serverHost,
|
||||
linkPreview: normalized.linkPreview
|
||||
linkPreview: normalized.linkPreview,
|
||||
openApiDocs: normalized.openApiDocs
|
||||
};
|
||||
}
|
||||
|
||||
@@ -218,6 +233,31 @@ export function isHttpsServerEnabled(): boolean {
|
||||
return getServerProtocol() === 'https';
|
||||
}
|
||||
|
||||
export function areOpenApiDocsEnabled(): boolean {
|
||||
if (hasEnvironmentOverride(process.env.OPENAPI_DOCS_ENABLED)) {
|
||||
return process.env.OPENAPI_DOCS_ENABLED.trim().toLowerCase() === 'true';
|
||||
}
|
||||
|
||||
return getVariablesConfig().openApiDocs.enabled;
|
||||
}
|
||||
|
||||
export function setOpenApiDocsEnabled(enabled: boolean): OpenApiDocsConfig {
|
||||
if (!fs.existsSync(DATA_DIR)) {
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
const { parsed } = readRawVariables();
|
||||
const next = {
|
||||
...parsed,
|
||||
openApiDocs: { enabled }
|
||||
};
|
||||
|
||||
fs.writeFileSync(VARIABLES_FILE, JSON.stringify(next, null, 2) + '\n', 'utf8');
|
||||
ensureVariablesConfig();
|
||||
|
||||
return { enabled };
|
||||
}
|
||||
|
||||
export function getLinkPreviewConfig(): LinkPreviewConfig {
|
||||
return getVariablesConfig().linkPreview;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user