Updated routes for multi-repo setup (untested)

cron
Jef Roosens 2022-03-27 17:00:11 +02:00
parent a47cace296
commit 014ade5092
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 22 additions and 15 deletions

View File

@ -70,8 +70,12 @@ fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ?bool {
if pkg.info.arch == "any" {
repo_dir := os.join_path_single(r.data_dir, repo)
// We get a listing of all currently present arch-repos in the given repo
mut arch_repos := os.ls(repo_dir) ?.filter(os.is_dir(os.join_path_single(repo_dir, it)))
mut arch_repos := []string{}
if os.exists(repo_dir) {
// We get a listing of all currently present arch-repos in the given repo
arch_repos = os.ls(repo_dir) ?.filter(os.is_dir(os.join_path_single(repo_dir, it)))
}
if arch_repos.len == 0 {
arch_repos << r.default_arch

View File

@ -8,8 +8,6 @@ import rand
import util
import net.http
const default_repo = "vieter"
// healthcheck just returns a string, but can be used to quickly check if the
// server is still responsive.
['/health'; get]
@ -17,15 +15,20 @@ pub fn (mut app App) healthcheck() web.Result {
return app.text('Healthy')
}
// get_root handles a GET request for a file on the root
['/:filename'; get; head]
fn (mut app App) get_root(filename string) web.Result {
['/:repo/:arch/:filename'; get; head]
fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Result {
mut full_path := ''
if filename.ends_with('.db') || filename.ends_with('.files') {
full_path = os.join_path_single(app.repo.data_dir, '${filename}.tar.gz')
} else if filename.ends_with('.db.tar.gz') || filename.ends_with('.files.tar.gz') {
full_path = os.join_path_single(app.repo.data_dir, '$filename')
db_exts := ['.db', '.files', '.db.tar.gz', '.files.tar.gz']
if db_exts.any(filename.ends_with(it)) {
full_path = os.join_path(app.repo.data_dir, repo, arch, filename)
// repo-add does this using symlinks, but we just change the requested
// path
if !full_path.ends_with('.tar.gz') {
full_path += '.tar.gz'
}
} else {
full_path = os.join_path_single(app.repo.pkg_dir, filename)
}
@ -42,8 +45,8 @@ fn (mut app App) get_root(filename string) web.Result {
return app.file(full_path)
}
['/publish'; post]
fn (mut app App) put_package() web.Result {
['/:repo/publish'; post]
fn (mut app App) put_package(repo string) web.Result {
if !app.is_authorized() {
return app.text('Unauthorized.')
}
@ -76,7 +79,7 @@ fn (mut app App) put_package() web.Result {
return app.text("Content-Type header isn't set.")
}
res := app.repo.add_pkg_from_path(default_repo, pkg_path) or {
res := app.repo.add_pkg_from_path(repo, pkg_path) or {
app.lerror('Error while adding package: $err.msg')
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }

View File

@ -97,7 +97,7 @@ async def upload_random_package(tar_path, sem):
async with sem:
with open(tar_path, 'rb') as f:
async with aiohttp.ClientSession() as s:
async with s.post("http://localhost:8000/publish", data=f.read(), headers={"x-api-key": "test"}) as r:
async with s.post("http://localhost:8000/vieter/publish", data=f.read(), headers={"x-api-key": "test"}) as r:
return await check_output(r)