add apt gestion
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
274ea454dd
commit
c4776d81dd
22 changed files with 1465 additions and 163 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue