diff --git a/src/client/logs.v b/src/client/logs.v index 85063bc..e5969dd 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -41,3 +41,10 @@ pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time t return data } + +// remove_build_log removes the build log with the given id from the server. +pub fn (c &Client) remove_build_log(id int) !string { + data := c.send_request(.delete, '/api/v1/logs/$id', {})! + + return data.data +} diff --git a/src/console/logs/logs.v b/src/console/logs/logs.v index 3064a58..19c46f6 100644 --- a/src/console/logs/logs.v +++ b/src/console/logs/logs.v @@ -138,6 +138,18 @@ pub fn cmd() cli.Command { list(conf, filter, raw)! } }, + cli.Command{ + name: 'remove' + required_args: 1 + usage: 'id' + description: 'Remove a build log that matches the given id.' + execute: fn (cmd cli.Command) ! { + config_file := cmd.flags.get_string('config-file')! + conf := vconf.load(prefix: 'VIETER_', default_path: config_file)! + + remove(conf, cmd.args[0])! + } + }, cli.Command{ name: 'info' required_args: 1 @@ -204,3 +216,9 @@ fn content(conf Config, id int) ! { println(content) } + +// remove removes a build log from the server's list. +fn remove(conf Config, id string) ! { + c := client.new(conf.address, conf.api_key) + c.remove_build_log(id.int())! +} diff --git a/src/server/api_logs.v b/src/server/api_logs.v index c7521dd..352266c 100644 --- a/src/server/api_logs.v +++ b/src/server/api_logs.v @@ -124,3 +124,22 @@ fn (mut app App) v1_post_log() web.Result { return app.json(.ok, new_data_response(log_id)) } + +// v1_delete_log allows removing a build log from the system. +['/api/v1/logs/:id'; auth; delete] +fn (mut app App) v1_delete_log(id int) web.Result { + log := app.db.get_build_log(id) or { return app.status(.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, + file_name) + + os.rm(full_path) or { + app.lerror('Failed to remove log file $full_path: $err.msg()') + + return app.status(.internal_server_error) + } + + app.db.delete_build_log(id) + + return app.status(.ok) +}