This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push: new bca0d0e5 File API fixes bca0d0e5 is described below commit bca0d0e57bdfa026ed3447ba52c5e934307a0458 Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Fri Nov 1 17:53:41 2024 -0400 File API fixes --- .../camel/karavan/api/ProjectFileResource.java | 24 ++++++++-------- karavan-app/src/main/webui/src/api/KaravanApi.tsx | 33 ++++++---------------- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java index fc5bdf42..2147af16 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java @@ -38,9 +38,6 @@ public class ProjectFileResource { @Inject KaravanCache karavanCache; - @Inject - CodeService codeService; - @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{projectId}") @@ -129,16 +126,19 @@ public class ProjectFileResource { @POST @Produces(MediaType.APPLICATION_JSON) - @Path("/copy/{project}") - public Response copy(@PathParam("project") String project, JsonObject copy) throws Exception { - var projectId = URLDecoder.decode(project, StandardCharsets.UTF_8); - var from = copy.getString("from"); - var to = copy.getString("to"); - var tofile = karavanCache.getProjectFile(projectId, to); - if (tofile == null) { - var file = karavanCache.getProjectFile(projectId, from); + @Path("/copy") + public Response copy(JsonObject copy) throws Exception { + var fromProjectId = copy.getString("fromProjectId"); + var fromFilename = copy.getString("fromFilename"); + var toProjectId = copy.getString("toProjectId"); + var toFilename = copy.getString("toFilename"); + var overwrite = copy.getBoolean("overwrite", false); + var tofile = karavanCache.getProjectFile(toProjectId, toFilename); + if (overwrite || tofile == null) { + var file = karavanCache.getProjectFile(fromProjectId, fromFilename); var copyFile = file.copy(); - copyFile.setName(to); + copyFile.setProjectId(toProjectId); + copyFile.setName(toFilename); karavanCache.saveProjectFile(copyFile, false, false); return Response.ok().build(); } else { diff --git a/karavan-app/src/main/webui/src/api/KaravanApi.tsx b/karavan-app/src/main/webui/src/api/KaravanApi.tsx index 30accd1d..59df8fdd 100644 --- a/karavan-app/src/main/webui/src/api/KaravanApi.tsx +++ b/karavan-app/src/main/webui/src/api/KaravanApi.tsx @@ -208,30 +208,6 @@ export class KaravanApi { }); } - static async getProjectDeploymentStatus(projectId: string, env: string, after: (status?: DeploymentStatus) => void) { - instance.get('/ui/status/deployment/' + projectId + "/" + env) - .then(res => { - if (res.status === 200) { - after(res.data); - } else if (res.status === 204) { - after(undefined); - } - }).catch(err => { - ErrorEventBus.sendApiError(err); - }); - } - - static async getProjectCamelStatus(projectId: string, env: string, after: (status: CamelStatus) => void) { - instance.get('/ui/status/camel/' + projectId + "/" + env) - .then(res => { - if (res.status === 200) { - after(res.data); - } - }).catch(err => { - ErrorEventBus.sendApiError(err); - }); - } - static async getAllCamelContextStatuses(after: (statuses: CamelStatus[]) => void) { instance.get('/ui/status/camel/context') .then(res => { @@ -390,6 +366,15 @@ export class KaravanApi { }); } + static async copyProjectFile(fromProjectId: string, fromFilename: string, toProjectId: string, toFilename: string, overwrite: boolean, after: (res: AxiosResponse<any>) => void) { + instance.post('/ui/file/copy', {fromProjectId: fromProjectId, fromFilename: fromFilename, toProjectId: toProjectId, toFilename: toFilename, overwrite: overwrite}) + .then(res => { + after(res); + }).catch(err => { + after(err); + }); + } + static async push(params: {}, after: (res: AxiosResponse<any>) => void) { instance.post('/ui/git', params) .then(res => {