(
name: string,
type: string,
parameters: ParametersType,
exAdditional: ParametersType = {},
opt?: { obscure?: boolean; noObscure?: boolean }
)
| 67 | } |
| 68 | |
| 69 | async function createStorage( |
| 70 | name: string, |
| 71 | type: string, |
| 72 | parameters: ParametersType, |
| 73 | exAdditional: ParametersType = {}, |
| 74 | opt?: { obscure?: boolean; noObscure?: boolean } |
| 75 | ): Promise<boolean> { |
| 76 | // 输入验证 |
| 77 | const validation = validateStorageInput(name, type, parameters) |
| 78 | if (!validation.valid) { |
| 79 | Message.error(validation.error || '输入参数无效') |
| 80 | console.error('Storage validation failed:', validation.error) |
| 81 | return false |
| 82 | } |
| 83 | |
| 84 | const storageInfo = searchStorageInfo(type) |
| 85 | if (!storageInfo) { |
| 86 | Message.error('不支持的存储类型: ' + type) |
| 87 | console.error('Storage type not found:', type) |
| 88 | return false |
| 89 | } |
| 90 | |
| 91 | const storage = searchStorage(name) |
| 92 | let backData |
| 93 | |
| 94 | try { |
| 95 | switch (storageInfo.framework) { |
| 96 | case 'rclone': { |
| 97 | const requestBody: ParametersType = { |
| 98 | name: name, |
| 99 | type: storageInfo.type, |
| 100 | parameters: parameters, |
| 101 | ...exAdditional, |
| 102 | } |
| 103 | // 如果提供了 opt 参数,添加到请求中 |
| 104 | if (opt) { |
| 105 | requestBody['opt'] = opt |
| 106 | } |
| 107 | backData = await rclone_api_post('/config/create', requestBody) |
| 108 | await reupStorage() |
| 109 | return backData ? isEmptyObject(backData as Record<string, unknown>) : false |
| 110 | } |
| 111 | |
| 112 | case 'openlist': { |
| 113 | // 安全序列化 addition |
| 114 | let serializedAddition: string |
| 115 | try { |
| 116 | serializedAddition = JSON.stringify(parameters.addition) |
| 117 | } catch (e) { |
| 118 | console.error('Failed to serialize addition:', e) |
| 119 | Message.error('存储参数序列化失败') |
| 120 | return false |
| 121 | } |
| 122 | |
| 123 | const openlistParams = { |
| 124 | ...parameters, |
| 125 | addition: serializedAddition, |
| 126 | driver: storageInfo.type, |
no test coverage detected