Compare commits

..

No commits in common. "9268ef0302d9ec3d73dc1fa7f38809655f2adbeb" and "cc5df95a1a9b742ca3945bfda16c1df53b294a0c" have entirely different histories.

12 changed files with 35 additions and 29 deletions

View File

@ -16,7 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
providing a Git repository
* CLI commands for searching the AUR & directly adding packages
* HTTP routes for removing packages, arch-repos & repos
* All endpoints serving files now support HTTP byte range requests
### Changed
@ -26,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Branch name for 'git' targets is now optional; if not provided, the
repository will be cloned with the default branch
* Build containers now explicitely set the PATH variable
* Refactor of web framework
### Removed

View File

@ -48,8 +48,15 @@ update`.
### Compiler
I used to maintain a mirror that tracked the latest master, but nowadays, I
solely target V 0.3 as a compiler.
Vieter compiles with the standard Vlang compiler. However, I do maintain a
[mirror](https://git.rustybever.be/vieter-v/v). This is to ensure my CI does
not break without reason, as I control when & how frequently the mirror is
updated to reflect the official repository.
If you encounter issues using the latest V compiler, try using my mirror
instead. `make v` will clone the repository & build the mirror. Afterwards,
prepending any make command with `V_PATH=v/v` tells make to use the locally
compiled mirror instead.
## Contributing

View File

@ -2,7 +2,7 @@ module client
import net.http { Method }
import net.urllib
import web.response { Response }
import response { Response }
import json
pub struct Client {

View File

@ -2,7 +2,7 @@ module client
import models { BuildLog, BuildLogFilter }
import net.http { Method }
import web.response { Response }
import response { Response }
import time
// get_build_logs returns all build logs.

View File

@ -2,7 +2,7 @@ module client
import models { Target, TargetFilter }
import net.http { Method }
import web.response { Response }
import response { Response }
// get_targets returns a list of targets, given a filter object.
pub fn (c &Client) get_targets(filter TargetFilter) ?[]Target {

View File

@ -3,7 +3,7 @@ module server
import web
import net.http
import net.urllib
import web.response { new_data_response, new_response }
import response { new_data_response, new_response }
import db
import time
import os

View File

@ -2,7 +2,7 @@ module server
import web
import net.http
import web.response { new_data_response, new_response }
import response { new_data_response, new_response }
import db
import models { Target, TargetArch, TargetFilter }

View File

@ -7,7 +7,7 @@ import time
import rand
import util
import net.http
import web.response { new_response }
import response { new_response }
// healthcheck just returns a string, but can be used to quickly check if the
// server is still responsive.

View File

@ -2,13 +2,13 @@ module server
import web
import net.http
import web.response { new_response }
import response { new_response }
// delete_package tries to remove the given package.
['/:repo/:arch/:pkg'; delete]
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
if !app.is_authorized() {
return app.json(.unauthorized, new_response('Unauthorized.'))
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
}
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {

View File

@ -9,7 +9,7 @@ pub struct Result {}
pub const (
methods_with_form = [http.Method.post, .put, .patch]
headers_close = http.new_custom_header_from_map({
'Server': 'Vieter'
'Server': 'VWeb'
http.CommonHeader.connection.str(): 'close'
}) or { panic('should never fail') }

View File

@ -91,22 +91,15 @@ fn (mut ctx Context) send_reader(mut reader io.Reader, size u64) ? {
}
}
// send_custom_response sends the given http.Response to the client. It can be
// used to overwrite the Context object & send a completely custom
// http.Response instead.
fn (mut ctx Context) send_custom_response(resp &http.Response) ? {
ctx.send_string(resp.bytestr())?
}
// send_response_header constructs a valid HTTP response with an empty body &
// sends it to the client.
pub fn (mut ctx Context) send_response_header() ? {
mut resp := http.Response{
header: ctx.header.join(headers_close)
}
resp.set_version(.v1_1)
resp.set_status(ctx.status)
ctx.send_custom_response(resp)?
ctx.send_string(resp.bytestr())?
}
// send is a convenience function for sending the HTTP response with an empty
@ -229,8 +222,10 @@ pub fn (mut ctx Context) status(status http.Status) Result {
// server_error Response a server error
pub fn (mut ctx Context) server_error(ecode int) Result {
ctx.send_custom_response(http_500) or {}
$if debug {
eprintln('> ctx.server_error ecode: $ecode')
}
ctx.send_string(http_500.bytestr()) or {}
return Result{}
}
@ -239,17 +234,23 @@ pub fn (mut ctx Context) redirect(url string) Result {
mut resp := http_302
resp.header = resp.header.join(ctx.header)
resp.header.add(.location, url)
ctx.send_custom_response(resp) or {}
ctx.send_string(resp.bytestr()) or { return Result{} }
return Result{}
}
// not_found Send an not_found response
pub fn (mut ctx Context) not_found() Result {
ctx.send_custom_response(http_404) or {}
return ctx.status(http.Status.not_found)
}
return Result{}
// add_header Adds an header to the response with key and val
pub fn (mut ctx Context) add_header(key string, val string) {
ctx.header.add_custom(key, val) or {}
}
// get_header Returns the header data from the key
pub fn (ctx &Context) get_header(key string) string {
return ctx.req.header.get_custom(key) or { '' }
}
interface DbInterface {