forked from vieter-v/vieter
Compare commits
2 Commits
cc5df95a1a
...
9268ef0302
| Author | SHA1 | Date |
|---|---|---|
|
|
9268ef0302 | |
|
|
e23635a1d3 |
|
|
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
providing a Git repository
|
providing a Git repository
|
||||||
* CLI commands for searching the AUR & directly adding packages
|
* CLI commands for searching the AUR & directly adding packages
|
||||||
* HTTP routes for removing packages, arch-repos & repos
|
* HTTP routes for removing packages, arch-repos & repos
|
||||||
|
* All endpoints serving files now support HTTP byte range requests
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ 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
|
* Branch name for 'git' targets is now optional; if not provided, the
|
||||||
repository will be cloned with the default branch
|
repository will be cloned with the default branch
|
||||||
* Build containers now explicitely set the PATH variable
|
* Build containers now explicitely set the PATH variable
|
||||||
|
* Refactor of web framework
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|
|
||||||
11
README.md
11
README.md
|
|
@ -48,15 +48,8 @@ update`.
|
||||||
|
|
||||||
### Compiler
|
### Compiler
|
||||||
|
|
||||||
Vieter compiles with the standard Vlang compiler. However, I do maintain a
|
I used to maintain a mirror that tracked the latest master, but nowadays, I
|
||||||
[mirror](https://git.rustybever.be/vieter-v/v). This is to ensure my CI does
|
solely target V 0.3 as a compiler.
|
||||||
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
|
## Contributing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module client
|
||||||
|
|
||||||
import net.http { Method }
|
import net.http { Method }
|
||||||
import net.urllib
|
import net.urllib
|
||||||
import response { Response }
|
import web.response { Response }
|
||||||
import json
|
import json
|
||||||
|
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module client
|
||||||
|
|
||||||
import models { BuildLog, BuildLogFilter }
|
import models { BuildLog, BuildLogFilter }
|
||||||
import net.http { Method }
|
import net.http { Method }
|
||||||
import response { Response }
|
import web.response { Response }
|
||||||
import time
|
import time
|
||||||
|
|
||||||
// get_build_logs returns all build logs.
|
// get_build_logs returns all build logs.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module client
|
||||||
|
|
||||||
import models { Target, TargetFilter }
|
import models { Target, TargetFilter }
|
||||||
import net.http { Method }
|
import net.http { Method }
|
||||||
import response { Response }
|
import web.response { Response }
|
||||||
|
|
||||||
// get_targets returns a list of targets, given a filter object.
|
// get_targets returns a list of targets, given a filter object.
|
||||||
pub fn (c &Client) get_targets(filter TargetFilter) ?[]Target {
|
pub fn (c &Client) get_targets(filter TargetFilter) ?[]Target {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module server
|
||||||
import web
|
import web
|
||||||
import net.http
|
import net.http
|
||||||
import net.urllib
|
import net.urllib
|
||||||
import response { new_data_response, new_response }
|
import web.response { new_data_response, new_response }
|
||||||
import db
|
import db
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module server
|
||||||
|
|
||||||
import web
|
import web
|
||||||
import net.http
|
import net.http
|
||||||
import response { new_data_response, new_response }
|
import web.response { new_data_response, new_response }
|
||||||
import db
|
import db
|
||||||
import models { Target, TargetArch, TargetFilter }
|
import models { Target, TargetArch, TargetFilter }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import time
|
||||||
import rand
|
import rand
|
||||||
import util
|
import util
|
||||||
import net.http
|
import net.http
|
||||||
import response { new_response }
|
import web.response { new_response }
|
||||||
|
|
||||||
// healthcheck just returns a string, but can be used to quickly check if the
|
// healthcheck just returns a string, but can be used to quickly check if the
|
||||||
// server is still responsive.
|
// server is still responsive.
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ module server
|
||||||
|
|
||||||
import web
|
import web
|
||||||
import net.http
|
import net.http
|
||||||
import response { new_response }
|
import web.response { new_response }
|
||||||
|
|
||||||
// delete_package tries to remove the given package.
|
// delete_package tries to remove the given package.
|
||||||
['/:repo/:arch/:pkg'; delete]
|
['/:repo/:arch/:pkg'; delete]
|
||||||
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
|
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
|
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub struct Result {}
|
||||||
pub const (
|
pub const (
|
||||||
methods_with_form = [http.Method.post, .put, .patch]
|
methods_with_form = [http.Method.post, .put, .patch]
|
||||||
headers_close = http.new_custom_header_from_map({
|
headers_close = http.new_custom_header_from_map({
|
||||||
'Server': 'VWeb'
|
'Server': 'Vieter'
|
||||||
http.CommonHeader.connection.str(): 'close'
|
http.CommonHeader.connection.str(): 'close'
|
||||||
}) or { panic('should never fail') }
|
}) or { panic('should never fail') }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,15 +91,22 @@ 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 &
|
// send_response_header constructs a valid HTTP response with an empty body &
|
||||||
// sends it to the client.
|
// sends it to the client.
|
||||||
pub fn (mut ctx Context) send_response_header() ? {
|
pub fn (mut ctx Context) send_response_header() ? {
|
||||||
mut resp := http.Response{
|
mut resp := http.Response{
|
||||||
header: ctx.header.join(headers_close)
|
header: ctx.header.join(headers_close)
|
||||||
}
|
}
|
||||||
resp.set_version(.v1_1)
|
|
||||||
resp.set_status(ctx.status)
|
resp.set_status(ctx.status)
|
||||||
ctx.send_string(resp.bytestr())?
|
|
||||||
|
ctx.send_custom_response(resp)?
|
||||||
}
|
}
|
||||||
|
|
||||||
// send is a convenience function for sending the HTTP response with an empty
|
// send is a convenience function for sending the HTTP response with an empty
|
||||||
|
|
@ -222,10 +229,8 @@ pub fn (mut ctx Context) status(status http.Status) Result {
|
||||||
|
|
||||||
// server_error Response a server error
|
// server_error Response a server error
|
||||||
pub fn (mut ctx Context) server_error(ecode int) Result {
|
pub fn (mut ctx Context) server_error(ecode int) Result {
|
||||||
$if debug {
|
ctx.send_custom_response(http_500) or {}
|
||||||
eprintln('> ctx.server_error ecode: $ecode')
|
|
||||||
}
|
|
||||||
ctx.send_string(http_500.bytestr()) or {}
|
|
||||||
return Result{}
|
return Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,23 +239,17 @@ pub fn (mut ctx Context) redirect(url string) Result {
|
||||||
mut resp := http_302
|
mut resp := http_302
|
||||||
resp.header = resp.header.join(ctx.header)
|
resp.header = resp.header.join(ctx.header)
|
||||||
resp.header.add(.location, url)
|
resp.header.add(.location, url)
|
||||||
ctx.send_string(resp.bytestr()) or { return Result{} }
|
|
||||||
|
ctx.send_custom_response(resp) or {}
|
||||||
|
|
||||||
return Result{}
|
return Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not_found Send an not_found response
|
// not_found Send an not_found response
|
||||||
pub fn (mut ctx Context) not_found() Result {
|
pub fn (mut ctx Context) not_found() Result {
|
||||||
return ctx.status(http.Status.not_found)
|
ctx.send_custom_response(http_404) or {}
|
||||||
}
|
|
||||||
|
|
||||||
// add_header Adds an header to the response with key and val
|
return Result{}
|
||||||
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 {
|
interface DbInterface {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue