add apt gestion

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-25 19:03:26 +02:00
commit c4776d81dd
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
22 changed files with 1465 additions and 163 deletions

View file

@ -21,13 +21,15 @@ func NewProxyHandler(repoSvc *core.RepoService, dataDir string) *ProxyHandler {
}
func (h *ProxyHandler) ServeFile(w http.ResponseWriter, r *http.Request) {
repoID, err := strconv.ParseInt(chi.URLParam(r, "repo_id"), 10, 64)
if err != nil {
http.Error(w, "invalid repo_id", http.StatusBadRequest)
return
}
ref := chi.URLParam(r, "repo_ref")
repo, err := h.repoSvc.Get(r.Context(), repoID)
var repo *store.Repo
var err error
if id, parseErr := strconv.ParseInt(ref, 10, 64); parseErr == nil {
repo, err = h.repoSvc.Get(r.Context(), id)
} else {
repo, err = h.repoSvc.GetByName(r.Context(), ref)
}
if errors.Is(err, store.ErrNotFound) {
http.NotFound(w, r)
return
@ -37,7 +39,7 @@ func (h *ProxyHandler) ServeFile(w http.ResponseWriter, r *http.Request) {
return
}
localDir := fmt.Sprintf("%s/repos/%d/%s", h.dataDir, repoID, repo.Type)
prefix := fmt.Sprintf("/mirror/%d", repoID)
localDir := fmt.Sprintf("%s/repos/%d/%s", h.dataDir, repo.ID, repo.Type)
prefix := fmt.Sprintf("/mirror/%s", ref)
http.StripPrefix(prefix, http.FileServer(http.Dir(localDir))).ServeHTTP(w, r)
}