新增支付配置备份导出功能
This commit is contained in:
@@ -92,6 +92,16 @@ export async function fetchPaymentConfig(id: number, includeSecret = false) {
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function exportPaymentConfigBackup() {
|
||||
const response = await apiClient.get<Blob>('/admin/payment-configs/export', {
|
||||
responseType: 'blob',
|
||||
})
|
||||
return {
|
||||
blob: response.data,
|
||||
filename: readDownloadFilename(response.headers['content-disposition']) || fallbackBackupFilename(),
|
||||
}
|
||||
}
|
||||
|
||||
export async function createPaymentConfig(payload: CreatePaymentConfigRequest) {
|
||||
const { data } = await apiClient.post<ApiResponse<PaymentConfig>>('/admin/payment-configs', payload)
|
||||
return data.data
|
||||
@@ -106,3 +116,15 @@ export async function deletePaymentConfig(id: number) {
|
||||
const { data } = await apiClient.delete<ApiResponse<{ message: string }>>(`/admin/payment-configs/${id}`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
function readDownloadFilename(contentDisposition: unknown) {
|
||||
if (typeof contentDisposition !== 'string') return ''
|
||||
const encoded = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1]
|
||||
if (encoded) return decodeURIComponent(encoded)
|
||||
return contentDisposition.match(/filename="?([^";]+)"?/i)?.[1] || ''
|
||||
}
|
||||
|
||||
function fallbackBackupFilename() {
|
||||
const stamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, '')
|
||||
return `payment-config-backup-${stamp}.json`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user