diff --git a/.gitignore b/.gitignore index e07ad958..4114c9de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.c data/ vieter/vieter + +# Ignore testing files +*.pkg* diff --git a/Makefile b/Makefile index 82707064..0a22bbdd 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/vieter/main.v b/vieter/main.v index cc930c48..b4b46404 100644 --- a/vieter/main.v +++ b/vieter/main.v @@ -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{