* 添加搜索引擎
(engine: WebSearchEngine)
| 113 | * 添加搜索引擎 |
| 114 | */ |
| 115 | public async addEngine(engine: WebSearchEngine): Promise<{ success: boolean; error?: string }> { |
| 116 | const validated = this.validateAndNormalizeEngine(engine, false) |
| 117 | if (!validated.success) { |
| 118 | return { success: false, error: validated.error } |
| 119 | } |
| 120 | const normalizedEngine = validated.engine! |
| 121 | |
| 122 | const engines = this.getAllEngines() |
| 123 | |
| 124 | // 自动生成 ID |
| 125 | if (!normalizedEngine.id) { |
| 126 | normalizedEngine.id = randomUUID() |
| 127 | } |
| 128 | |
| 129 | // 检查重复 ID |
| 130 | if (engines.some((e) => e.id === normalizedEngine.id)) { |
| 131 | return { success: false, error: '该搜索引擎 ID 已存在' } |
| 132 | } |
| 133 | |
| 134 | engines.push(normalizedEngine) |
| 135 | databaseAPI.dbPut(this.DB_KEY, engines) |
| 136 | |
| 137 | this.notifyCommandsChanged() |
| 138 | |
| 139 | return { success: true } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * 更新搜索引擎 |
no test coverage detected