mirror of
https://github.com/Afilmory/afilmory
synced 2026-04-24 23:05:05 +00:00
refactor(config): simplify default builder configuration and enforce storage requirement
- Removed unnecessary fields from the default builder configuration, including repository and storage settings. - Set storage to null to enforce configuration validation. - Updated loadBuilderConfig to ensure storage configuration is provided, throwing an error if missing. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -1,37 +1,15 @@
|
||||
import os from 'node:os'
|
||||
|
||||
import thumbnailStoragePlugin from '../plugins/thumbnail-storage/index.js'
|
||||
import type { BuilderConfig } from '../types/config.js'
|
||||
|
||||
export function createDefaultBuilderConfig(): BuilderConfig {
|
||||
return {
|
||||
repo: {
|
||||
enable: false,
|
||||
url: process.env.BUILDER_REPO_URL || '',
|
||||
token: process.env.GIT_TOKEN,
|
||||
},
|
||||
storage: {
|
||||
provider: 's3',
|
||||
bucket: process.env.S3_BUCKET_NAME,
|
||||
region: process.env.S3_REGION,
|
||||
endpoint: process.env.S3_ENDPOINT,
|
||||
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
||||
prefix: process.env.S3_PREFIX,
|
||||
customDomain: process.env.S3_CUSTOM_DOMAIN,
|
||||
excludeRegex: process.env.S3_EXCLUDE_REGEX,
|
||||
maxFileLimit: process.env.S3_MAX_FILE_LIMIT ? Number.parseInt(process.env.S3_MAX_FILE_LIMIT, 10) : 1000,
|
||||
keepAlive: true,
|
||||
maxSockets: 64,
|
||||
connectionTimeoutMs: 5_000,
|
||||
socketTimeoutMs: 30_000,
|
||||
requestTimeoutMs: 20_000,
|
||||
idleTimeoutMs: 10_000,
|
||||
totalTimeoutMs: 60_000,
|
||||
retryMode: 'standard',
|
||||
maxAttempts: 3,
|
||||
downloadConcurrency: 16,
|
||||
url: '',
|
||||
token: '',
|
||||
},
|
||||
storage: null!,
|
||||
options: {
|
||||
defaultConcurrency: 10,
|
||||
enableLivePhotoDetection: true,
|
||||
@@ -52,6 +30,6 @@ export function createDefaultBuilderConfig(): BuilderConfig {
|
||||
workerConcurrency: 2,
|
||||
},
|
||||
},
|
||||
plugins: [thumbnailStoragePlugin()],
|
||||
plugins: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import { createDefaultBuilderConfig } from './defaults.js'
|
||||
export interface LoadBuilderConfigOptions {
|
||||
cwd?: string
|
||||
configFile?: string
|
||||
defaults?: BuilderConfig
|
||||
}
|
||||
|
||||
function normalizeBuilderConfig(defaults: BuilderConfig, input: BuilderConfigInput): BuilderConfig {
|
||||
@@ -30,8 +29,6 @@ function normalizeBuilderConfig(defaults: BuilderConfig, input: BuilderConfigInp
|
||||
}
|
||||
|
||||
export async function loadBuilderConfig(options: LoadBuilderConfigOptions = {}): Promise<BuilderConfig> {
|
||||
const defaults = options.defaults ?? createDefaultBuilderConfig()
|
||||
|
||||
const result = await loadConfig<BuilderConfigInput>({
|
||||
name: 'builder',
|
||||
cwd: options.cwd ?? process.cwd(),
|
||||
@@ -42,8 +39,13 @@ export async function loadBuilderConfig(options: LoadBuilderConfigOptions = {}):
|
||||
|
||||
const userConfig = result.config ?? {}
|
||||
|
||||
const defaults = createDefaultBuilderConfig()
|
||||
const config = normalizeBuilderConfig(defaults, userConfig)
|
||||
|
||||
if (!config.storage) {
|
||||
throw new Error('缺失存储配置,请配置 storage 字段')
|
||||
}
|
||||
|
||||
if (process.env.DEBUG === '1') {
|
||||
const logger = consola.withTag('CONFIG')
|
||||
logger.info('Using builder config from', result.configFile ?? 'defaults')
|
||||
|
||||
Reference in New Issue
Block a user