mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-21 20:02:32 -05:00
URL encoding and catch requests other than 200 for clips
This commit is contained in:
parent
283d5f21e0
commit
1e4f4df6eb
1 changed files with 14 additions and 6 deletions
|
@ -2,6 +2,7 @@ package proxy
|
|||
|
||||
import (
|
||||
b64 "encoding/base64"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"safetwitch-backend/extractor/twitch"
|
||||
|
@ -14,7 +15,7 @@ func Routes(route *gin.Engine) {
|
|||
auth := route.Group("/proxy")
|
||||
|
||||
auth.GET("/img/:url", func(context *gin.Context) {
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("url"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("url"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -49,7 +50,7 @@ func Routes(route *gin.Engine) {
|
|||
})
|
||||
|
||||
auth.GET("/stream/sub/:encodedUrl", func(context *gin.Context) {
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -65,7 +66,7 @@ func Routes(route *gin.Engine) {
|
|||
})
|
||||
|
||||
auth.GET("/stream/segment/:encodedUrl", func(context *gin.Context) {
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -98,7 +99,7 @@ func Routes(route *gin.Engine) {
|
|||
})
|
||||
|
||||
auth.GET("/vod/sub/:encodedUrl/video.m3u8", func(context *gin.Context) {
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -115,7 +116,7 @@ func Routes(route *gin.Engine) {
|
|||
|
||||
auth.GET("/vod/sub/:encodedUrl/:segment", func(context *gin.Context) {
|
||||
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("encodedUrl"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -141,7 +142,7 @@ func Routes(route *gin.Engine) {
|
|||
})
|
||||
|
||||
auth.GET("/clip/:clipUrl", func(context *gin.Context) {
|
||||
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("clipUrl"))
|
||||
decodedUrl, err := b64.URLEncoding.DecodeString(context.Param("clipUrl"))
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
@ -152,6 +153,13 @@ func Routes(route *gin.Engine) {
|
|||
context.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
err := errors.New("status was not 200")
|
||||
context.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
_, err = io.Copy(context.Writer, resp.Body)
|
||||
|
|
Loading…
Add table
Reference in a new issue