feat(runtime): override deploy settings from the environment
SNOWLUMA_ variables can set the factory OneBot listen ports, WebUI TLS, packet and hook timeouts, the stream directory, file download timeout, and notification HTTP timeout. The values apply in memory and are not written back to saved config.
This commit is contained in:
19 files changed
+342
-14
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
const log = createLogger('OneBot.Stream');
|
||||
|
||||
export interface StreamStorageSnapshot {
|
||||
totalBytes: number;
|
||||
fileCount: number;
|
||||
@@ -273,7 +276,23 @@ function resolveManagedRoot(input: string): string {
|
||||
return path.join(fs.realpathSync(parent), path.basename(absolute));
|
||||
}
|
||||
|
||||
export const streamStorage = new StreamStorage(path.join(os.tmpdir(), 'onebot-stream'));
|
||||
export function createStreamStorage(env: NodeJS.ProcessEnv = process.env): StreamStorage {
|
||||
const fallback = path.join(os.tmpdir(), 'onebot-stream');
|
||||
const raw = env.SNOWLUMA_STREAM_DIR?.trim();
|
||||
if (!raw) return new StreamStorage(fallback);
|
||||
try {
|
||||
return new StreamStorage(raw);
|
||||
} catch (error) {
|
||||
log.warn(
|
||||
'SNOWLUMA_STREAM_DIR=%j is ignored: %s',
|
||||
raw,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
return new StreamStorage(fallback);
|
||||
}
|
||||
}
|
||||
|
||||
export const streamStorage = createStreamStorage();
|
||||
export const STREAM_ROOT = streamStorage.root;
|
||||
export const STREAM_UPLOAD_DIR = streamStorage.uploadDir;
|
||||
export const STREAM_DOWNLOAD_DIR = streamStorage.downloadDir;
|
||||
|
||||
Reference in new issue
Block a user