2022-08-11 19:28:17 +02:00
|
|
|
module server
|
|
|
|
|
|
|
|
import web
|
|
|
|
import net.http
|
2022-08-13 13:16:31 +02:00
|
|
|
import web.response { new_response }
|
2022-08-11 19:28:17 +02:00
|
|
|
|
|
|
|
// delete_package tries to remove the given package.
|
2022-09-04 19:36:08 +02:00
|
|
|
['/:repo/:arch/:pkg'; auth; delete]
|
2022-08-11 19:28:17 +02:00
|
|
|
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
|
|
|
|
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.'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete_arch_repo tries to remove the given arch-repo.
|
2022-09-04 19:36:08 +02:00
|
|
|
['/:repo/:arch'; auth; delete]
|
2022-08-11 19:28:17 +02:00
|
|
|
fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
|
|
|
|
res := app.repo.remove_arch_repo(repo, arch) or {
|
|
|
|
app.lerror('Error while deleting arch-repo: $err.msg()')
|
|
|
|
|
|
|
|
return app.json(http.Status.internal_server_error, new_response('Failed to delete arch-repo.'))
|
|
|
|
}
|
|
|
|
|
|
|
|
if res {
|
|
|
|
app.linfo("Removed '$repo/$arch'")
|
|
|
|
|
|
|
|
return app.json(http.Status.ok, new_response('Arch-repo removed.'))
|
|
|
|
} else {
|
|
|
|
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
|
|
|
|
|
|
|
|
return app.json(http.Status.not_found, new_response('Arch-repo not found.'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete_repo tries to remove the given repo.
|
2022-09-04 19:36:08 +02:00
|
|
|
['/:repo'; auth; delete]
|
2022-08-11 19:28:17 +02:00
|
|
|
fn (mut app App) delete_repo(repo string) web.Result {
|
|
|
|
res := app.repo.remove_repo(repo) or {
|
|
|
|
app.lerror('Error while deleting repo: $err.msg()')
|
|
|
|
|
|
|
|
return app.json(http.Status.internal_server_error, new_response('Failed to delete repo.'))
|
|
|
|
}
|
|
|
|
|
|
|
|
if res {
|
|
|
|
app.linfo("Removed '$repo'")
|
|
|
|
|
|
|
|
return app.json(http.Status.ok, new_response('Repo removed.'))
|
|
|
|
} else {
|
|
|
|
app.linfo("Tried removing '$repo', but it doesn't exist.")
|
|
|
|
|
|
|
|
return app.json(http.Status.not_found, new_response('Repo not found.'))
|
|
|
|
}
|
|
|
|
}
|