forked from vieter-v/vieter
refactor(server): migrated all routes to new auth system
This commit is contained in:
parent
4887af26d3
commit
272f14b264
6 changed files with 13 additions and 78 deletions
|
|
@ -12,12 +12,8 @@ import models { BuildLog, BuildLogFilter }
|
|||
|
||||
// v1_get_logs returns all build logs in the database. A 'target' query param can
|
||||
// optionally be added to limit the list of build logs to that repository.
|
||||
['/api/v1/logs'; get]
|
||||
['/api/v1/logs'; auth; get]
|
||||
fn (mut app App) v1_get_logs() web.Result {
|
||||
if !app.is_authorized() {
|
||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
filter := models.from_params<BuildLogFilter>(app.query) or {
|
||||
return app.json(http.Status.bad_request, new_response('Invalid query parameters.'))
|
||||
}
|
||||
|
|
@ -27,24 +23,16 @@ fn (mut app App) v1_get_logs() web.Result {
|
|||
}
|
||||
|
||||
// v1_get_single_log returns the build log with the given id.
|
||||
['/api/v1/logs/:id'; get]
|
||||
['/api/v1/logs/:id'; auth; get]
|
||||
fn (mut app App) v1_get_single_log(id int) web.Result {
|
||||
if !app.is_authorized() {
|
||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
log := app.db.get_build_log(id) or { return app.not_found() }
|
||||
|
||||
return app.json(http.Status.ok, new_data_response(log))
|
||||
}
|
||||
|
||||
// v1_get_log_content returns the actual build log file for the given id.
|
||||
['/api/v1/logs/:id/content'; get]
|
||||
['/api/v1/logs/:id/content'; auth; get]
|
||||
fn (mut app App) v1_get_log_content(id int) web.Result {
|
||||
if !app.is_authorized() {
|
||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
log := app.db.get_build_log(id) or { return app.not_found() }
|
||||
file_name := log.start_time.custom_format('YYYY-MM-DD_HH-mm-ss')
|
||||
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.target_id.str(), log.arch,
|
||||
|
|
@ -63,12 +51,8 @@ fn parse_query_time(query string) ?time.Time {
|
|||
}
|
||||
|
||||
// v1_post_log adds a new log to the database.
|
||||
['/api/v1/logs'; post]
|
||||
['/api/v1/logs'; auth; post]
|
||||
fn (mut app App) v1_post_log() web.Result {
|
||||
if !app.is_authorized() {
|
||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
// Parse query params
|
||||
start_time_int := app.query['startTime'].int()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue