Merge branch 'redirect_to_player'

* redirect_to_player:
  redirect everything to player
This commit is contained in:
Alex Grintsvayg 2020-12-02 11:49:59 -05:00
commit 694faae00f
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 23 additions and 4 deletions

View file

@ -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 ./...
go get github.com/alecthomas/gometalinter && gometalinter --install && gometalinter ./...
dev:
reflex --decoration=none --start-service=true --regex='main.go' go run .

20
main.go
View file

@ -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) {