added refresh db capability and did some refactoring

This commit is contained in:
2026-04-14 22:46:23 -06:00
parent 36f856cb25
commit 5687f7f992
5 changed files with 70 additions and 33 deletions
+5 -5
View File
@@ -9,17 +9,17 @@ import (
"gitea.ewpt3ch.dev/ewpt3ch/pkgstash/internal/cache"
)
func handlePackage(w http.ResponseWriter, req *http.Request, c *cache.Cache) {
func (s *Server) handlePackage(w http.ResponseWriter, req *http.Request) {
// build file paths from the request, they follow archlinux repo
// <reporoot>/[core, extra, etc]/os/[x86_64, arm, etc]/package.pkg.tar.zst[.sig]
// <mirrorroot>/[core, extra, etc]/os/[x86_64, arm, etc]/package.pkg.tar.zst[.sig]
repo := req.PathValue("repo")
arch := req.PathValue("arch")
file := req.PathValue("file")
relPath := filepath.Join(repo, "os", arch, file) //path from repo root to pkg or db file
pkgPath := filepath.Join(repoRoot, relPath) //path for local read of the file
repoPath := filepath.Join(repo, "os", arch, file) //path from mirror root to pkg or db file
pkgPath := filepath.Join(s.cfg.MirrorRoot, repoPath) //absolute path for local read of the file
if _, err := os.Stat(pkgPath); err != nil {
err = c.Fetch(relPath)
err = s.c.Fetch(repoPath)
if err != nil {
var upstreamErr *cache.UpstreamError
if errors.As(err, &upstreamErr) {