From fe98112f796d39bb14175386f6e0a0b29e94500b Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 21 Feb 2022 22:40:59 +0100 Subject: [PATCH] Added repos delete route --- src/server/git.v | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/server/git.v b/src/server/git.v index 8c569e66..d506c7e9 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -96,3 +96,34 @@ pub fn (mut app App) post_repo() web.Result { return app.ok('Repo added successfully.') } + +['/api/repos'; delete] +pub fn (mut app App) delete_repo() web.Result { + if !app.is_authorized() { + return app.text('Unauthorized.') + } + + if !('url' in app.query && 'branch' in app.query) { + return app.server_error(400) + } + + repo_to_remove := GitRepo{ + url: app.query['url'] + branch: app.query['branch'] + } + + mut repos := rlock app.git_mutex { + read_repos(app.conf.repos_file) or { + app.lerror('Failed to read repos file.') + + return app.server_error(500) + } + } + filtered := repos.filter(it != repo_to_remove) + + lock app.git_mutex { + write_repos(app.conf.repos_file, filtered) or { return app.server_error(500) } + } + + return app.ok('Repo removed successfully.') +}