forked from vieter-v/vieter
First attempt at writing PUT route
parent
625018518d
commit
12aff4ff9f
|
@ -1,3 +1,6 @@
|
||||||
*.c
|
*.c
|
||||||
data/
|
data/
|
||||||
vieter/vieter
|
vieter/vieter
|
||||||
|
|
||||||
|
# Ignore testing files
|
||||||
|
*.pkg*
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run:
|
run:
|
||||||
API_KEY=test REPO_DIR=data v run vieter
|
API_KEY=test REPO_DIR=data v watch run vieter
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
|
|
|
@ -17,17 +17,27 @@ fn exit_with_message(code int, msg string) {
|
||||||
exit(code)
|
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() {
|
fn main() {
|
||||||
key := os.getenv_opt('API_KEY') or { exit_with_message(1, 'No API key was provided.') }
|
key := os.getenv_opt('API_KEY') or { exit_with_message(1, 'No API key was provided.') }
|
||||||
repo_dir := os.getenv_opt('REPO_DIR') or {
|
repo_dir := os.getenv_opt('REPO_DIR') or {
|
||||||
exit_with_message(1, 'No repo directory was configured.')
|
exit_with_message(1, 'No repo directory was configured.')
|
||||||
}
|
}
|
||||||
|
println(repo_dir)
|
||||||
|
|
||||||
// We create the upload directory during startup
|
// We create the upload directory during startup
|
||||||
if !os.is_dir(repo_dir) {
|
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{
|
vweb.run(&App{
|
||||||
|
|
Loading…
Reference in New Issue