43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
export const DINGTALK_NOTIFICATION_DRAFT_CONFIG_KEY =
|
|
"dingtalk_notification_draft_config";
|
|
|
|
export type DingTalkNotificationDraftConfig = {
|
|
title: string;
|
|
content: string;
|
|
};
|
|
|
|
export const defaultDingTalkNotificationDraftConfig: DingTalkNotificationDraftConfig =
|
|
{
|
|
title: "",
|
|
content: "",
|
|
};
|
|
|
|
function normalizeDraftTitle(value: unknown) {
|
|
return String(value || "")
|
|
.replace(/[\u2028\u2029]/g, "")
|
|
.replace(/[\u0000-\u001F\u007F]/g, "")
|
|
.trim();
|
|
}
|
|
|
|
function normalizeDraftContent(value: unknown) {
|
|
return String(value || "")
|
|
.replace(/[\u2028\u2029]/g, "")
|
|
.replace(/\u0000/g, "")
|
|
.replace(/\r\n?/g, "\n")
|
|
.trim();
|
|
}
|
|
|
|
export function normalizeDingTalkNotificationDraftConfig(
|
|
value: unknown,
|
|
): DingTalkNotificationDraftConfig {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return defaultDingTalkNotificationDraftConfig;
|
|
}
|
|
|
|
const raw = value as Partial<DingTalkNotificationDraftConfig>;
|
|
return {
|
|
title: normalizeDraftTitle(raw.title),
|
|
content: normalizeDraftContent(raw.content),
|
|
};
|
|
}
|