forked from wangziqi/gongxue-base
108 lines
4.9 KiB
TypeScript
108 lines
4.9 KiB
TypeScript
import { DEFAULT_DATABASE_URL, envBoolean, envList, envNumber, envString, loadDotenv } from '../../../packages/config/src/index.js';
|
|
|
|
loadDotenv();
|
|
|
|
export interface WorkerConfig {
|
|
databaseUrl: string;
|
|
crmBatchSize: number;
|
|
crmPollIntervalMs: number;
|
|
crmMaxAttempts: number;
|
|
crmBackoffSeconds: number[];
|
|
crmRequestTimeoutMs: number;
|
|
crmAllowInsecureLocalhost: boolean;
|
|
commerceBatchSize: number;
|
|
commerceMinAgeSeconds: number;
|
|
commerceRequestTimeoutMs: number;
|
|
assetBatchSize: number;
|
|
assetMinAgeSeconds: number;
|
|
assetRecheckIntervalSeconds: number;
|
|
assetRequestTimeoutMs: number;
|
|
importBatchSize: number;
|
|
importWorkerId: string;
|
|
importBackoffSeconds: number[];
|
|
publicBankSyncBatchSize: number;
|
|
publicBankSyncCopyLimit: number;
|
|
publicBankSyncWorkerId: string;
|
|
publicBankSyncClaimStaleSeconds: number;
|
|
storageMaxUploadBytes: number;
|
|
storageAllowedMimePrefixes: string[];
|
|
storageAllowedMimeTypes: string[];
|
|
storageRequireTenantPrefix: boolean;
|
|
aliyunOssRegion: string;
|
|
aliyunOssEndpoint: string;
|
|
aliyunOssAccessKeyId: string;
|
|
aliyunOssAccessKeySecret: string;
|
|
aliyunOssStsToken: string;
|
|
aliyunOssInternal: boolean;
|
|
tencentCosRegion: string;
|
|
tencentCosAppId: string;
|
|
tencentCosSecretId: string;
|
|
tencentCosSecretKey: string;
|
|
tencentCosSecurityToken: string;
|
|
supabaseStorageUrl: string;
|
|
supabaseStorageServiceKey: string;
|
|
}
|
|
|
|
export const config: WorkerConfig = {
|
|
databaseUrl: envString('DATABASE_URL', DEFAULT_DATABASE_URL),
|
|
crmBatchSize: envNumber('WORKER_CRM_BATCH_SIZE', 20),
|
|
crmPollIntervalMs: envNumber('WORKER_CRM_POLL_INTERVAL_MS', 10_000),
|
|
crmMaxAttempts: envNumber('WORKER_CRM_MAX_ATTEMPTS', 5),
|
|
crmBackoffSeconds: envList('WORKER_CRM_BACKOFF_SECONDS', '5,30,120,600,1800')
|
|
.map((value: string) => Number(value))
|
|
.filter((value: number) => Number.isFinite(value) && value > 0),
|
|
crmRequestTimeoutMs: envNumber('WORKER_CRM_REQUEST_TIMEOUT_MS', 10_000),
|
|
crmAllowInsecureLocalhost: envBoolean('WORKER_CRM_ALLOW_INSECURE_LOCALHOST', false),
|
|
commerceBatchSize: envNumber('WORKER_COMMERCE_BATCH_SIZE', 20),
|
|
commerceMinAgeSeconds: envNumber('WORKER_COMMERCE_MIN_AGE_SECONDS', 300),
|
|
commerceRequestTimeoutMs: envNumber('WORKER_COMMERCE_REQUEST_TIMEOUT_MS', 10_000),
|
|
assetBatchSize: envNumber('WORKER_ASSET_BATCH_SIZE', 50),
|
|
assetMinAgeSeconds: envNumber('WORKER_ASSET_MIN_AGE_SECONDS', 300),
|
|
assetRecheckIntervalSeconds: envNumber('WORKER_ASSET_RECHECK_INTERVAL_SECONDS', 60 * 60 * 24),
|
|
assetRequestTimeoutMs: envNumber('WORKER_ASSET_REQUEST_TIMEOUT_MS', 10_000),
|
|
importBatchSize: envNumber('WORKER_IMPORT_BATCH_SIZE', 5),
|
|
importWorkerId: envString('WORKER_IMPORT_ID', `imports-${process.pid}`),
|
|
importBackoffSeconds: envList('WORKER_IMPORT_BACKOFF_SECONDS', '30,120,600,1800')
|
|
.map((value: string) => Number(value))
|
|
.filter((value: number) => Number.isFinite(value) && value > 0),
|
|
publicBankSyncBatchSize: envNumber('WORKER_PUBLIC_BANK_SYNC_BATCH_SIZE', 5),
|
|
publicBankSyncCopyLimit: envNumber('WORKER_PUBLIC_BANK_SYNC_COPY_LIMIT', 1000),
|
|
publicBankSyncWorkerId: envString('WORKER_PUBLIC_BANK_SYNC_ID', `public-banks-${process.pid}`),
|
|
publicBankSyncClaimStaleSeconds: envNumber('WORKER_PUBLIC_BANK_SYNC_CLAIM_STALE_SECONDS', 15 * 60),
|
|
storageMaxUploadBytes: envNumber('STORAGE_MAX_UPLOAD_BYTES', 1024 * 1024 * 500),
|
|
storageAllowedMimePrefixes: envList('STORAGE_ALLOWED_MIME_PREFIXES', 'image/,video/,audio/'),
|
|
storageAllowedMimeTypes: envList(
|
|
'STORAGE_ALLOWED_MIME_TYPES',
|
|
[
|
|
'application/pdf',
|
|
'application/json',
|
|
'application/zip',
|
|
'application/x-zip-compressed',
|
|
'application/msword',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
'application/vnd.ms-excel',
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
'application/vnd.ms-powerpoint',
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
'application/octet-stream',
|
|
'text/plain',
|
|
'text/markdown',
|
|
'text/csv',
|
|
].join(','),
|
|
),
|
|
storageRequireTenantPrefix: envBoolean('STORAGE_REQUIRE_TENANT_PREFIX', true),
|
|
aliyunOssRegion: envString('ALIYUN_OSS_REGION', ''),
|
|
aliyunOssEndpoint: envString('ALIYUN_OSS_ENDPOINT', ''),
|
|
aliyunOssAccessKeyId: envString('ALIYUN_OSS_ACCESS_KEY_ID', ''),
|
|
aliyunOssAccessKeySecret: envString('ALIYUN_OSS_ACCESS_KEY_SECRET', ''),
|
|
aliyunOssStsToken: envString('ALIYUN_OSS_STS_TOKEN', ''),
|
|
aliyunOssInternal: envBoolean('ALIYUN_OSS_INTERNAL', false),
|
|
tencentCosRegion: envString('TENCENT_COS_REGION', ''),
|
|
tencentCosAppId: envString('TENCENT_COS_APP_ID', ''),
|
|
tencentCosSecretId: envString('TENCENT_COS_SECRET_ID', ''),
|
|
tencentCosSecretKey: envString('TENCENT_COS_SECRET_KEY', ''),
|
|
tencentCosSecurityToken: envString('TENCENT_COS_SECURITY_TOKEN', ''),
|
|
supabaseStorageUrl: envString('SUPABASE_STORAGE_URL', ''),
|
|
supabaseStorageServiceKey: envString('SUPABASE_STORAGE_SERVICE_KEY', ''),
|
|
};
|