deploy: sync server CloudSearch 0.5.6
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { SystemConfigEntry } from '../admin/system-config.service';
|
||||
import { mergeRedactedUpdate } from '../utils/redact';
|
||||
|
||||
function parseJsonObject(value: unknown): any {
|
||||
if (!value) return {};
|
||||
if (typeof value === 'object') return value;
|
||||
if (typeof value !== 'string') return {};
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return parsed && typeof parsed === 'object' ? parsed : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function mergeJsonStringUpdate(incoming: string, existing: string | undefined): string {
|
||||
try {
|
||||
const parsedIncoming = JSON.parse(incoming);
|
||||
const parsedExisting = parseJsonObject(existing);
|
||||
return JSON.stringify(mergeRedactedUpdate(parsedIncoming, parsedExisting));
|
||||
} catch {
|
||||
return mergeRedactedUpdate(incoming, existing);
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeSystemConfigEntriesUpdate(
|
||||
entries: Array<{ key: string; value: string }>,
|
||||
existing: SystemConfigEntry[],
|
||||
): Array<{ key: string; value: string }> {
|
||||
const existingByKey = new Map(existing.map(entry => [entry.key, entry.value]));
|
||||
return entries.map(entry => {
|
||||
const oldValue = existingByKey.get(entry.key);
|
||||
return { ...entry, value: mergeJsonStringUpdate(entry.value, oldValue) };
|
||||
});
|
||||
}
|
||||
|
||||
export function mergeNotifySettingsUpdate(incoming: any, existing: any): any {
|
||||
return mergeRedactedUpdate(incoming || {}, existing || {});
|
||||
}
|
||||
|
||||
export function mergePushUserNotifyConfigUpdate(incoming: { notify_config?: any }, existing?: { notify_config?: string }): any {
|
||||
return mergeNotifySettingsUpdate(
|
||||
parseJsonObject(incoming?.notify_config),
|
||||
parseJsonObject(existing?.notify_config),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user