redirect everything to player
This commit is contained in:
parent
2346864c82
commit
2b3c83023e
2 changed files with 23 additions and 4 deletions
7
Makefile
7
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 ./...
|
||||
go get github.com/alecthomas/gometalinter && gometalinter --install && gometalinter ./...
|
||||
|
||||
dev:
|
||||
reflex --decoration=none --start-service=true --regex='main.go' go run .
|
20
main.go
20
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) {
|
||||
|
|
Loading…
Reference in a new issue