diff --git a/src/lib/langs/en.json b/src/lib/langs/en.json index 74865e94..3d71ee90 100644 --- a/src/lib/langs/en.json +++ b/src/lib/langs/en.json @@ -216,6 +216,13 @@ "Migrate agents from file repository to MongoDB": "Migrate agents from file repository to MongoDB", "Setting": "Setting", "Start Migration": "Start Migration", + "Select agents to migrate": "Select agents to migrate", + "Search agents": "Search agents", + "Select the agents to copy to the MongoDB datastore. Only the selected agents are migrated.": "Select the agents to copy to the MongoDB datastore. Only the selected agents are migrated.", + "You will migrate {n} selected agent(s) to mongoDb.": "You will migrate {n} selected agent(s) to mongoDb.", + "Failed to load agents.": "Failed to load agents.", + "Failed to migrate agents.": "Failed to migrate agents.", + "No agent files found, or the default database is the file repository.": "No agent files found, or the default database is the file repository.", "Plugin": "Plugin", "My Profile": "My Profile", "Detail": "Detail", diff --git a/src/lib/langs/zh.json b/src/lib/langs/zh.json index ba533234..9c95e04f 100644 --- a/src/lib/langs/zh.json +++ b/src/lib/langs/zh.json @@ -410,6 +410,13 @@ "Migrate agents from file repository to MongoDB": "将代理从文件存储库迁移到MongoDB", "Setting": "设置", "Start Migration": "开始迁移", + "Select agents to migrate": "选择要迁移的代理", + "Search agents": "搜索代理", + "Select the agents to copy to the MongoDB datastore. Only the selected agents are migrated.": "选择要复制到MongoDB的代理,仅迁移所选代理。", + "You will migrate {n} selected agent(s) to mongoDb.": "将把所选的 {n} 个代理迁移到MongoDB。", + "Failed to load agents.": "加载代理列表失败。", + "Failed to migrate agents.": "迁移代理失败。", + "No agent files found, or the default database is the file repository.": "未找到代理文件,或默认数据库是文件存储库。", "Plugin": "插件", "My Profile": "我的资料", "Detail": "细节", diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index 12652c65..e09f6543 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -76,12 +76,26 @@ export async function deleteAgent(agentId, options = null) { } /** - * Refresh agent data + * Migrate the given agents from the file repository to the database + * @param {string[]} agentIds * @returns {Promise} */ -export async function refreshAgents() { - const url = endpoints.agentRefreshUrl; - const response = await axios.post(url, {}); +export async function refreshAgents(agentIds) { + if (!agentIds.length) { + // An empty list would make the server migrate every agent. + throw new Error('Select at least one agent to migrate.'); + } + + const response = await axios.post(endpoints.agentRefreshUrl, { agent_ids: agentIds }); + return response.data; +} + +/** + * Get agents defined in the file repository (candidates to migrate) + * @returns {Promise} + */ +export async function getFileAgents() { + const response = await axios.get(endpoints.fileAgentsUrl); return response.data; } diff --git a/src/lib/services/api-endpoints.js b/src/lib/services/api-endpoints.js index 71dac76e..54aec91d 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -37,6 +37,7 @@ export const endpoints = { agentOptionsUrl: `${host}/agent/options`, agentDetailUrl: `${host}/agent/{id}`, agentRefreshUrl: `${host}/refresh-agents`, + fileAgentsUrl: `${host}/file-agents`, agentCreateUrl: `${host}/agent`, agentUtilityOptionsUrl: `${host}/agent/utility/options`, agentRuleOptionsUrl: `${host}/rule/triggers`, diff --git a/src/routes/page/setting/+page.svelte b/src/routes/page/setting/+page.svelte index 92ad6a50..6111773e 100644 --- a/src/routes/page/setting/+page.svelte +++ b/src/routes/page/setting/+page.svelte @@ -1,23 +1,12 @@ - - - -
@@ -145,34 +79,4 @@
-
-
-
- - - -
-

{$_('Migrate agents from file repository to MongoDB')}

-

One-time migration. All agents will be copied to the MongoDB datastore.

-
-
-
- -
-
-
- - This action cannot be undone. Make sure you have a backup before proceeding. -
- -
-
-
+ diff --git a/src/routes/page/setting/agent-migration.svelte b/src/routes/page/setting/agent-migration.svelte new file mode 100644 index 00000000..bf4a1513 --- /dev/null +++ b/src/routes/page/setting/agent-migration.svelte @@ -0,0 +1,139 @@ + + + + + (confirmOpen = false)} + toggleModal={() => (confirmOpen = false)} +/> + +
+
+
+ + + +
+

{$_('Migrate agents from file repository to MongoDB')}

+

{$_('Select the agents to copy to the MongoDB datastore. Only the selected agents are migrated.')}

+
+
+
+ +
+
+