feat(channels): add line and zalo minio override config
This commit is contained in:
+61
-6
@@ -26,6 +26,8 @@ function resolveChannelMinioShare(config: Config): {
|
||||
bucket: string;
|
||||
prefix: string;
|
||||
secure: boolean;
|
||||
expires?: string;
|
||||
mcPath?: string;
|
||||
} | undefined {
|
||||
const minio = config.backup.minio;
|
||||
if (!minio.enabled || !minio.endpoint || !minio.access_key || !minio.secret_key || !minio.bucket) {
|
||||
@@ -42,6 +44,55 @@ function resolveChannelMinioShare(config: Config): {
|
||||
};
|
||||
}
|
||||
|
||||
function resolveChannelMinioShareWithOverrides(
|
||||
base: ReturnType<typeof resolveChannelMinioShare>,
|
||||
override: {
|
||||
enabled: boolean;
|
||||
endpoint?: string;
|
||||
access_key?: string;
|
||||
secret_key?: string;
|
||||
bucket?: string;
|
||||
prefix: string;
|
||||
secure: boolean;
|
||||
expires: string;
|
||||
mc_path?: string;
|
||||
} | undefined,
|
||||
): {
|
||||
enabled: boolean;
|
||||
endpoint: string;
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
bucket: string;
|
||||
prefix: string;
|
||||
secure: boolean;
|
||||
expires?: string;
|
||||
mcPath?: string;
|
||||
} | undefined {
|
||||
if (!override?.enabled) {
|
||||
return base;
|
||||
}
|
||||
|
||||
const endpoint = override.endpoint ?? base?.endpoint;
|
||||
const accessKey = override.access_key ?? base?.accessKey;
|
||||
const secretKey = override.secret_key ?? base?.secretKey;
|
||||
const bucket = override.bucket ?? base?.bucket;
|
||||
if (!endpoint || !accessKey || !secretKey || !bucket) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: true,
|
||||
endpoint,
|
||||
accessKey,
|
||||
secretKey,
|
||||
bucket,
|
||||
prefix: override.prefix,
|
||||
secure: override.secure,
|
||||
expires: override.expires,
|
||||
mcPath: override.mc_path,
|
||||
};
|
||||
}
|
||||
|
||||
export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||
const { config, channelRegistry, hookEngine, pairingManager, gateway } = deps;
|
||||
const channelMinioShare = resolveChannelMinioShare(config);
|
||||
@@ -181,15 +232,17 @@ export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||
|
||||
// Register LINE adapter (if configured)
|
||||
if (config.line) {
|
||||
const lineMinioShare = resolveChannelMinioShareWithOverrides(channelMinioShare, config.line.minio);
|
||||
const effectiveLineMinioShare = lineMinioShare && !config.line.minio.enabled
|
||||
? { ...lineMinioShare, prefix: `${lineMinioShare.prefix.replace(/\/+$/, '')}/channels/line` }
|
||||
: lineMinioShare;
|
||||
const lineAdapter = new LineAdapter({
|
||||
channelAccessToken: config.line.channel_access_token,
|
||||
channelSecret: config.line.channel_secret,
|
||||
allowedSourceIds: config.line.allowed_source_ids.length > 0 ? config.line.allowed_source_ids : undefined,
|
||||
requireMention: config.line.require_mention,
|
||||
mentionName: config.line.mention_name,
|
||||
minio: channelMinioShare
|
||||
? { ...channelMinioShare, prefix: `${channelMinioShare.prefix.replace(/\/+$/, '')}/channels/line` }
|
||||
: undefined,
|
||||
minio: effectiveLineMinioShare,
|
||||
});
|
||||
channelRegistry.register(lineAdapter);
|
||||
gateway.setLineHandler(lineAdapter);
|
||||
@@ -212,6 +265,10 @@ export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||
|
||||
// Register Zalo adapter (if configured)
|
||||
if (config.zalo) {
|
||||
const zaloMinioShare = resolveChannelMinioShareWithOverrides(channelMinioShare, config.zalo.minio);
|
||||
const effectiveZaloMinioShare = zaloMinioShare && !config.zalo.minio.enabled
|
||||
? { ...zaloMinioShare, prefix: `${zaloMinioShare.prefix.replace(/\/+$/, '')}/channels/zalo` }
|
||||
: zaloMinioShare;
|
||||
const zaloAdapter = new ZaloAdapter({
|
||||
oaAccessToken: config.zalo.oa_access_token,
|
||||
endpoint: config.zalo.endpoint,
|
||||
@@ -219,9 +276,7 @@ export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||
allowedUserIds: config.zalo.allowed_user_ids.length > 0 ? config.zalo.allowed_user_ids : undefined,
|
||||
requireMention: config.zalo.require_mention,
|
||||
mentionName: config.zalo.mention_name,
|
||||
minio: channelMinioShare
|
||||
? { ...channelMinioShare, prefix: `${channelMinioShare.prefix.replace(/\/+$/, '')}/channels/zalo` }
|
||||
: undefined,
|
||||
minio: effectiveZaloMinioShare,
|
||||
});
|
||||
channelRegistry.register(zaloAdapter);
|
||||
gateway.setZaloHandler(zaloAdapter);
|
||||
|
||||
Reference in New Issue
Block a user