forked from vieter-v/vieter
docs: added comment string to each function
This commit is contained in:
parent
fb65efdfbe
commit
f9f440500e
12 changed files with 49 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ module server
|
|||
|
||||
import net.http
|
||||
|
||||
// is_authorized checks whether the provided API key is correct.
|
||||
fn (mut app App) is_authorized() bool {
|
||||
x_header := app.req.header.get_custom('X-Api-Key', http.HeaderQueryConfig{ exact: true }) or {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import response { new_data_response, new_response }
|
|||
|
||||
const repos_file = 'repos.json'
|
||||
|
||||
// get_repos returns the current list of repos.
|
||||
['/api/repos'; get]
|
||||
fn (mut app App) get_repos() web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
@ -25,6 +26,7 @@ fn (mut app App) get_repos() web.Result {
|
|||
return app.json(http.Status.ok, new_data_response(repos))
|
||||
}
|
||||
|
||||
// get_single_repo returns the information for a single repo.
|
||||
['/api/repos/:id'; get]
|
||||
fn (mut app App) get_single_repo(id string) web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
@ -48,6 +50,7 @@ fn (mut app App) get_single_repo(id string) web.Result {
|
|||
return app.json(http.Status.ok, new_data_response(repo))
|
||||
}
|
||||
|
||||
// post_repo creates a new repo from the provided query string.
|
||||
['/api/repos'; post]
|
||||
fn (mut app App) post_repo() web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
@ -86,6 +89,7 @@ fn (mut app App) post_repo() web.Result {
|
|||
return app.json(http.Status.ok, new_response('Repo added successfully.'))
|
||||
}
|
||||
|
||||
// delete_repo removes a given repo from the server's list.
|
||||
['/api/repos/:id'; delete]
|
||||
fn (mut app App) delete_repo(id string) web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
@ -113,6 +117,7 @@ fn (mut app App) delete_repo(id string) web.Result {
|
|||
return app.json(http.Status.ok, new_response('Repo removed successfully.'))
|
||||
}
|
||||
|
||||
// patch_repo updates a repo's data with the given query params.
|
||||
['/api/repos/:id'; patch]
|
||||
fn (mut app App) patch_repo(id string) web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ pub fn (mut app App) healthcheck() web.Result {
|
|||
return app.json(http.Status.ok, new_response('Healthy.'))
|
||||
}
|
||||
|
||||
// get_repo_file handles all Pacman-related routes. It returns both the
|
||||
// repository's archives, but also package archives or the contents of a
|
||||
// package's desc file.
|
||||
['/:repo/:arch/:filename'; get; head]
|
||||
fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Result {
|
||||
mut full_path := ''
|
||||
|
|
@ -54,6 +57,7 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
|
|||
return app.file(full_path)
|
||||
}
|
||||
|
||||
// put_package handles publishing a package to a repository.
|
||||
['/:repo/publish'; post]
|
||||
fn (mut app App) put_package(repo string) web.Result {
|
||||
if !app.is_authorized() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue