First attempt at writing PUT route

main
Jef Roosens 2022-01-09 10:36:02 +01:00
parent 625018518d
commit 12aff4ff9f
Signed by untrusted user: Jef Roosens
GPG Key ID: 955C0660072F691F
3 changed files with 16 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
*.c
data/
vieter/vieter
# Ignore testing files
*.pkg*

View File

@ -1,6 +1,6 @@
.PHONY: run
run:
API_KEY=test REPO_DIR=data v run vieter
API_KEY=test REPO_DIR=data v watch run vieter
.PHONY: fmt
fmt:

View File

@ -17,17 +17,27 @@ fn exit_with_message(code int, msg string) {
exit(code)
}
[put; '/pkgs/:filename']
fn (mut app App) put_package(filename string) vweb.Result {
os.write_file('$app.repo_dir/$filename', app.req.data) or {
return app.text(err.msg)
}
return app.text('yeet')
}
fn main() {
key := os.getenv_opt('API_KEY') or { exit_with_message(1, 'No API key was provided.') }
repo_dir := os.getenv_opt('REPO_DIR') or {
exit_with_message(1, 'No repo directory was configured.')
}
println(repo_dir)
// We create the upload directory during startup
if !os.is_dir(repo_dir) {
os.mkdir_all(repo_dir) or { exit_with_message(2, 'Failed to create repo directory.') }
os.mkdir_all(repo_dir) or { exit_with_message(2, "Failed to create repo directory '$repo_dir'.") }
println('Repo directory created.')
println("Repo directory '$repo_dir' created.")
}
vweb.run(&App{