diff --git a/CHANGELOG.md b/CHANGELOG.md index a46a433..93e566a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * CLI flags to take advantage of above API improvements * Added CLI command to generate all man pages * PKGBUILDs now install man pages -* Hosted CLI man pages ([vieter(1)](https://rustybever.be/man/vieter/vieter.1.html)) -* Proper HTTP API docs ([link](https://rustybever.be/docs/vieter/api/)) +* CLI man pages are now hosted on https://rustybever.be ### Changed diff --git a/docs/api/source/includes/_git.md b/docs/api/source/includes/_git.md index f41d28d..f797a63 100644 --- a/docs/api/source/includes/_git.md +++ b/docs/api/source/includes/_git.md @@ -17,7 +17,7 @@ curl \ https://example.com/api/repos?offset=10&limit=20 ``` -> JSON output format +> JSON Output format ```json { @@ -63,7 +63,7 @@ curl \ https://example.com/api/repos/15 ``` -> JSON output format +> JSON Output format ```json { @@ -73,7 +73,7 @@ curl \ "url": "https://aur.archlinux.org/discord-ptb.git", "branch": "master", "repo": "bur", - "schedule": "0 3", + "schedule": " 0 3", "arch": [ { "id": 1, @@ -95,7 +95,7 @@ Get info about a specific Git repository. Parameter | Description --------- | ----------- -id | ID of requested repo +repo | ID of requested repo ## Create a new repo @@ -121,13 +121,7 @@ Modify the data of an existing Git repository. ### HTTP Request -`PATCH /api/repos/:id` - -### URL Parameters - -Parameter | Description ---------- | ----------- -id | ID of requested repo +`PATCH /api/repos` ### Query Parameters @@ -151,4 +145,4 @@ Remove a Git repository from the server. Parameter | Description --------- | ----------- -id | ID of repo to remove +repo | ID of repo to remove diff --git a/docs/api/source/includes/_logs.md b/docs/api/source/includes/_logs.md index d4f7632..e69de29 100644 --- a/docs/api/source/includes/_logs.md +++ b/docs/api/source/includes/_logs.md @@ -1,140 +0,0 @@ -# Build Logs - - - -Endpoints for interacting with stored build logs. - -## List logs - -```shell -curl \ - -H 'X-Api-Key: secret' \ - https://example.com/api/logs?offset=10&limit=20 -``` - -> JSON output format - -```json -{ - "message": "", - "data": [ - { - "id": 1, - "repo_id": 3, - "start_time": 1652008554, - "end_time": 1652008559, - "arch": "x86_64", - "exit_code": 0 - } - ] -} -``` - -Retrieve a list of build logs. - -### HTTP Request - -`GET /api/logs` - -### Query Parameters - -Parameter | Description ---------- | ----------- -limit | Maximum amount of results to return. -offset | Offset of results. -repo | Only return builds published to this repository. -before | Only return logs started before this time (UTC epoch) -after | Only return logs started after this time (UTC epoch) -arch | Only return logs built on this architecture -exit_codes | Comma-separated list of exit codes to limit result to; using `!` as a prefix makes it exclude that value. For example, `1,2` only returns logs with status code 1 or 2, while `!1,!2` returns those that don't have 1 or 2 as the result. - - -## Get build log - -```shell -curl \ - -H 'X-Api-Key: secret' \ - https://example.com/api/logs/15 -``` - -> JSON output format - -```json -{ - "message": "", - "data": { - "id": 1, - "repo_id": 3, - "start_time": 1652008554, - "end_time": 1652008559, - "arch": "x86_64", - "exit_code": 0 - } -} -``` - -Retrieve info about a specific build log. - -### HTTP Request - -`GET /api/logs/:id` - -### URL Parameters - -Parameter | Description ---------- | ----------- -id | ID of requested log - -## Get log contents - -```shell -curl \ - -H 'X-Api-Key: secret' \ - https://example.com/api/logs/15/content -``` - -Retrieve the contents of a build log. The response is the build log in -plaintext. - -### HTTP Request - -`GET /api/logs/:id/content` - -### URL Parameters - -Parameter | Description ---------- | ----------- -id | ID of requested log - -## Publish build log - - - -Publish a new build log to the server. - -### HTTP Request - -`POST /api/logs` - -### Query parameters - -Parameter | Description ---------- | ----------- -id | ID of requested log -startTime | Start time of the build (UTC epoch) -endTime | End time of the build (UTC epoch) -arch | Architecture on which the build was done -exitCode | Exit code of the build container - -### Request body - -Plaintext contents of the build log. diff --git a/src/client/client.v b/src/client/client.v index 2bb1ac2..7cb6be5 100644 --- a/src/client/client.v +++ b/src/client/client.v @@ -66,5 +66,5 @@ fn (c &Client) send_request_with_body(method Method, url string, params map[s fn (c &Client) send_request_raw_response(method Method, url string, params map[string]string, body string) ?string { res := c.send_request_raw(method, url, params, body)? - return res.body + return res.text } diff --git a/src/client/logs.v b/src/client/logs.v index 739de23..d4d373f 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -42,8 +42,8 @@ pub fn (c &Client) get_build_log_content(id int) ?string { pub fn (c &Client) add_build_log(repo_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) ?Response { params := { 'repo': repo_id.str() - 'startTime': start_time.unix_time().str() - 'endTime': end_time.unix_time().str() + 'startTime': start_time.str() + 'endTime': end_time.str() 'arch': arch 'exitCode': exit_code.str() } diff --git a/src/server/logs.v b/src/server/logs.v index 314e322..51b364f 100644 --- a/src/server/logs.v +++ b/src/server/logs.v @@ -70,19 +70,13 @@ fn (mut app App) post_log() web.Result { } // Parse query params - start_time_int := app.query['startTime'].int() - - if start_time_int == 0 { + start_time := parse_query_time(app.query['startTime']) or { return app.json(http.Status.bad_request, new_response('Invalid or missing start time.')) } - start_time := time.unix(start_time_int) - end_time_int := app.query['endTime'].int() - - if end_time_int == 0 { + end_time := parse_query_time(app.query['endTime']) or { return app.json(http.Status.bad_request, new_response('Invalid or missing end time.')) } - end_time := time.unix(end_time_int) if 'exitCode' !in app.query { return app.json(http.Status.bad_request, new_response('Missing exit code.')) diff --git a/src/web/web.v b/src/web/web.v index b053904..f237e24 100644 --- a/src/web/web.v +++ b/src/web/web.v @@ -25,12 +25,12 @@ pub const ( http_302 = http.new_response( status: .found - body: '302 Found' + text: '302 Found' header: headers_close ) http_400 = http.new_response( status: .bad_request - body: '400 Bad Request' + text: '400 Bad Request' header: http.new_header( key: .content_type value: 'text/plain' @@ -38,7 +38,7 @@ pub const ( ) http_404 = http.new_response( status: .not_found - body: '404 Not Found' + text: '404 Not Found' header: http.new_header( key: .content_type value: 'text/plain' @@ -46,7 +46,7 @@ pub const ( ) http_500 = http.new_response( status: .internal_server_error - body: '500 Internal Server Error' + text: '500 Internal Server Error' header: http.new_header( key: .content_type value: 'text/plain' @@ -209,7 +209,7 @@ pub fn (mut ctx Context) send_response_to_client(mimetype string, res string) bo mut resp := http.Response{ header: header.join(web.headers_close) - body: res + text: res } resp.set_version(.v1_1) resp.set_status(ctx.status)