aptly icon indicating copy to clipboard operation
aptly copied to clipboard

Serve api and published packages simultaneously

Open aol-nnov opened this issue 3 years ago • 1 comments

Not sure about the reason making it two separate commands, but the following patch allows to perform both in one call.

diff --git a/api/router.go b/api/router.go
index fdfbb94..18aa742 100644
--- a/api/router.go
+++ b/api/router.go
@@ -1,6 +1,7 @@
 package api
 
 import (
+       "github.com/aptly-dev/aptly/aptly"
        "net/http"
 
        ctx "github.com/aptly-dev/aptly/context"
@@ -14,8 +15,22 @@ func Router(c *ctx.AptlyContext) http.Handler {
        context = c
 
        router := gin.Default()
+       router.RedirectTrailingSlash = false
        router.Use(gin.ErrorLogger())
 
+ router.GET("/repos/:storage/*pkgPath", func(c *gin.Context) {
+         pkgpath := c.Param("pkgPath")
+
+         storage := c.Param("storage")
+         if storage == "-" {
+                 storage = ""
+         }
+
+         publicPath := context.GetPublishedStorage("filesystem:" + storage).(aptly.FileSystemPublishedStorage).PublicPath()
+
+         c.FileFromFS(pkgpath, http.Dir(publicPath))
+ })
+
        if context.Flags().Lookup("no-lock").Value.Get().(bool) {
                // We use a goroutine to count the number of
                // concurrent requests. When no more requests are

Changes are pretty minimalistic and I'd be glad to see them included. If there are no objections, I'm ready to make a PR. (disclamer: I'm not a gopher ;) )

aol-nnov avatar Feb 04 '22 10:02 aol-nnov

@aol-nnov , the best way here is to propose a PR, @randombenj will be able to accpet it or not and peaple will be able to reviw your code.

Regards

flotho avatar Apr 05 '22 17:04 flotho