Updated routes for multi-repo setup (untested)
parent
a47cace296
commit
014ade5092
|
@ -70,8 +70,12 @@ fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ?bool {
|
||||||
if pkg.info.arch == "any" {
|
if pkg.info.arch == "any" {
|
||||||
repo_dir := os.join_path_single(r.data_dir, repo)
|
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 := []string{}
|
||||||
mut arch_repos := os.ls(repo_dir) ?.filter(os.is_dir(os.join_path_single(repo_dir, it)))
|
|
||||||
|
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 {
|
if arch_repos.len == 0 {
|
||||||
arch_repos << r.default_arch
|
arch_repos << r.default_arch
|
||||||
|
|
|
@ -8,8 +8,6 @@ import rand
|
||||||
import util
|
import util
|
||||||
import net.http
|
import net.http
|
||||||
|
|
||||||
const default_repo = "vieter"
|
|
||||||
|
|
||||||
// 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.
|
||||||
['/health'; get]
|
['/health'; get]
|
||||||
|
@ -17,15 +15,20 @@ pub fn (mut app App) healthcheck() web.Result {
|
||||||
return app.text('Healthy')
|
return app.text('Healthy')
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_root handles a GET request for a file on the root
|
['/:repo/:arch/:filename'; get; head]
|
||||||
['/:filename'; get; head]
|
fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Result {
|
||||||
fn (mut app App) get_root(filename string) web.Result {
|
|
||||||
mut full_path := ''
|
mut full_path := ''
|
||||||
|
|
||||||
if filename.ends_with('.db') || filename.ends_with('.files') {
|
db_exts := ['.db', '.files', '.db.tar.gz', '.files.tar.gz']
|
||||||
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') {
|
if db_exts.any(filename.ends_with(it)) {
|
||||||
full_path = os.join_path_single(app.repo.data_dir, '$filename')
|
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 {
|
} else {
|
||||||
full_path = os.join_path_single(app.repo.pkg_dir, filename)
|
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)
|
return app.file(full_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
['/publish'; post]
|
['/:repo/publish'; post]
|
||||||
fn (mut app App) put_package() web.Result {
|
fn (mut app App) put_package(repo string) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.text('Unauthorized.')
|
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.")
|
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')
|
app.lerror('Error while adding package: $err.msg')
|
||||||
|
|
||||||
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
|
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
|
||||||
|
|
2
test.py
2
test.py
|
@ -97,7 +97,7 @@ async def upload_random_package(tar_path, sem):
|
||||||
async with sem:
|
async with sem:
|
||||||
with open(tar_path, 'rb') as f:
|
with open(tar_path, 'rb') as f:
|
||||||
async with aiohttp.ClientSession() as s:
|
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)
|
return await check_output(r)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue