From 2b3c83023ee23c2deb6d7e649427d0baa6282dc4 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Tue, 1 Dec 2020 14:59:28 -0500 Subject: [PATCH] redirect everything to player --- Makefile | 7 +++++-- main.go | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index df750d6..d141824 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ VERSION = $(shell git --git-dir=${DIR}/.git describe --dirty --always --long --a LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION} -X ${IMPORT_PATH}/meta.Time=$(shell date +%s) -w" -.PHONY: build clean test lint +.PHONY: build clean test lint dev .DEFAULT_GOAL: build @@ -23,4 +23,7 @@ test: go test ./... -v -cover lint: - go get github.com/alecthomas/gometalinter && gometalinter --install && gometalinter ./... \ No newline at end of file + go get github.com/alecthomas/gometalinter && gometalinter --install && gometalinter ./... + +dev: + reflex --decoration=none --start-service=true --regex='main.go' go run . \ No newline at end of file diff --git a/main.go b/main.go index b4dc5ec..aca7549 100644 --- a/main.go +++ b/main.go @@ -91,7 +91,7 @@ func main() { corsConfig.AllowOrigins = []string{"*"} r.Use(cors.New(corsConfig)) r.POST("/api/claim/publish", publish) - r.GET("/view/:id/:claimname", view) + r.GET("/*url", view) r.MaxMultipartMemory = 8 << 20 // 8 MiB r.Run(":5000") } @@ -99,6 +99,23 @@ func main() { var daemon *jsonrpc.Client func view(c *gin.Context) { + url := c.Param("url") + if url == "favicon.ico" { + c.AbortWithStatus(http.StatusNotFound) + return + } + + url = strings.TrimLeft(url, "/") + if url == "" { + _ = c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid url: %s", c.Param("url"))) + return + } + + c.Redirect(302, "https://cdn.lbryplayer.xyz/speech/"+url) + return +} + +func viewOld(c *gin.Context) { id := c.Param("id") claimNameWithExt := c.Param("claimname") claimName := strings.TrimSuffix(claimNameWithExt, filepath.Ext(claimNameWithExt)) @@ -221,7 +238,6 @@ func view(c *gin.Context) { } c.DataFromReader(http.StatusOK, f.Size(), contentType, reader, nil) return - } func isFileInDir(directory, fileName string) (bool, error) {