Add push-image action, small fixes (#21)

* Add push-image action

* Update example
This commit is contained in:
Chris Marshall
2020-11-22 11:35:28 -05:00
committed by GitHub
parent b64c44e6ac
commit bc61c2dc7e
5 changed files with 98 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"github.com/labstack/echo/v4"
@ -55,10 +56,7 @@ func NewRouter(cfg *Config) (*echo.Echo, error) {
return c.JSONPretty(http.StatusOK, files, " ")
})
e.GET("/assets/*", func(c echo.Context) error {
path := filepath.Join(cfg.AssetsDir, c.Param("*"))
d, f := filepath.Split(path)
f = f[strings.Index(f, "-")+1:]
path = filepath.Join(d, f)
path := filepath.Join(cfg.AssetsDir, trimAssetName(c.Param("*")))
if _, err := os.Stat(path); os.IsNotExist(err) {
return c.String(http.StatusNotFound, "file not found")
}
@ -131,3 +129,11 @@ func NewRouter(cfg *Config) (*echo.Echo, error) {
})
return e, nil
}
var assetPattern = regexp.MustCompile(`(\d+-)`)
// trimAssetName returns a path string that has been prefixed with a crc32
// checksum.
func trimAssetName(s string) string {
return assetPattern.ReplaceAllLiteralString(s, "")
}