feat: harden CMPP delivery and platform workflows

This commit is contained in:
hectorzhao
2026-07-20 18:07:29 +08:00
parent 80fb5a8f53
commit f02c33cbb7
61 changed files with 1834 additions and 281 deletions
+16
View File
@@ -0,0 +1,16 @@
export const IMAGE_UPLOAD_MAX_BYTES = 2 * 1024 * 1024;
export const FILE_UPLOAD_MAX_BYTES = 10 * 1024 * 1024;
const IMAGE_FILE_EXTENSION = /\.(?:avif|bmp|gif|heic|heif|jpe?g|png|svg|webp)$/i;
export function isImageUpload(file: Pick<File, 'name' | 'type'>) {
return file.type.toLowerCase().startsWith('image/') || IMAGE_FILE_EXTENSION.test(file.name);
}
export function assertUploadFileSize(file: Pick<File, 'name' | 'size' | 'type'>) {
const image = isImageUpload(file);
const limit = image ? IMAGE_UPLOAD_MAX_BYTES : FILE_UPLOAD_MAX_BYTES;
if (file.size > limit) {
throw new Error(image ? '图片大小不能超过 2MB' : '文件大小不能超过 10MB');
}
}
+9 -2
View File
@@ -8,6 +8,13 @@ const capabilityLabels = [
['uplinkWebhookEnabled', '上行回调'],
] as const;
const deliveryModeLabels: Record<string, string> = {
cmpp: 'CMPP 长连接',
http: 'HTTP Webhook',
both: 'CMPP 长连接 + HTTP Webhook',
none: '不投递',
};
export function formatHttpApiParams(response: HttpApiConfigResponse, origin: string) {
const config = response.config;
const baseUrl = `${origin.replace(/\/$/, '')}/api/openapi/v1`;
@@ -20,7 +27,7 @@ export function formatHttpApiParams(response: HttpApiConfigResponse, origin: str
`QPS限制: ${config?.qpsLimit ?? '-'}`,
`签名时间容差: ${config?.timestampToleranceSeconds ?? '-'}`,
`HTTP IP白名单: ${response.ipAllowlist.join('、') || '未限制'}`,
`回执投递方式: ${config?.receiptDeliveryMode ?? '-'}`,
`上行投递方式: ${config?.uplinkDeliveryMode ?? '-'}`,
`回执投递方式: ${config?.receiptDeliveryMode ? deliveryModeLabels[config.receiptDeliveryMode] ?? config.receiptDeliveryMode : '-'}`,
`上行投递方式: ${config?.uplinkDeliveryMode ? deliveryModeLabels[config.uplinkDeliveryMode] ?? config.uplinkDeliveryMode : '-'}`,
].join('\n');
}