forked from vieter-v/vieter
feat(server): added endpoint to remove package from arch-repo
This commit is contained in:
parent
8a2b121cc7
commit
49ddb312de
3 changed files with 53 additions and 1 deletions
|
|
@ -158,7 +158,7 @@ fn (r &RepoGroupManager) add_pkg_in_arch_repo(repo string, arch string, pkg &pac
|
|||
// remove_pkg_from_arch_repo removes a package from an arch-repo's database. It
|
||||
// returns false if the package wasn't present in the database. It also
|
||||
// optionally re-syncs the repo archives.
|
||||
fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, sync bool) ?bool {
|
||||
pub fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, sync bool) ?bool {
|
||||
repo_dir := os.join_path(r.repos_dir, repo, arch)
|
||||
|
||||
// If the repository doesn't exist yet, the result is automatically false
|
||||
|
|
|
|||
|
|
@ -57,6 +57,29 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
|
|||
return app.file(full_path)
|
||||
}
|
||||
|
||||
['/:repo/:arch/:pkg'; delete]
|
||||
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
|
||||
if !app.is_authorized() {
|
||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
|
||||
app.lerror('Error while deleting package: $err.msg()')
|
||||
|
||||
return app.json(http.Status.internal_server_error, new_response('Failed to delete package.'))
|
||||
}
|
||||
|
||||
if res {
|
||||
app.linfo("Removed package '$pkg' from '$repo/$arch'")
|
||||
|
||||
return app.json(http.Status.ok, new_response('Package removed.'))
|
||||
} else {
|
||||
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
|
||||
|
||||
return app.json(http.Status.not_found, new_response('Package not found.'))
|
||||
}
|
||||
}
|
||||
|
||||
// put_package handles publishing a package to a repository.
|
||||
['/:repo/publish'; post]
|
||||
fn (mut app App) put_package(repo string) web.Result {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue