@@ -18,21 +18,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
1818package api
1919
2020import (
21- "bash06/vxinstagram/flags"
22- "bash06/vxinstagram/utils"
23- "log/slog"
2421 "bash06/vxinstagram/flags"
2522 "bash06/vxinstagram/utils"
2623 "log/slog"
2724 "net/http"
2825 "net/http/httputil"
2926 "net/url"
3027 "strings"
31- "net/http/httputil"
32- "net/url"
33- "strings"
3428
35- "github.com/getsentry/sentry-go"
3629 "github.com/getsentry/sentry-go"
3730 "github.com/gin-gonic/gin"
3831)
@@ -64,17 +57,6 @@ func FollowShare(c *gin.Context) {
6457 return
6558 }
6659
67- res , err := client .Do (req )
68- if err != nil {
69- slog .Error ("Failed to follow redirects" , slog .Any ("err" , err ))
70- sentry .CaptureException (err )
71- c .HTML (http .StatusOK , "embed.html" , & HtmlOpenGraphData {
72- Title : "VxInstagram - Server Error" ,
73- Description : "VxInstagram encountered a server side error while processing your request. Request ID:`" + span .SpanID .String () + "`" ,
74- })
75- return
76- }
77- res .Body .Close ()
7860 res , err := client .Do (req )
7961 if err != nil {
8062 slog .Error ("Failed to follow redirects" , slog .Any ("err" , err ))
@@ -87,8 +69,6 @@ func FollowShare(c *gin.Context) {
8769 }
8870 res .Body .Close ()
8971
90- urlSplit := strings .Split (res .Request .URL .String (), "/" )
91- postId := urlSplit [len (urlSplit )- 2 ]
9272 urlSplit := strings .Split (res .Request .URL .String (), "/" )
9373 postId := urlSplit [len (urlSplit )- 2 ]
9474
@@ -130,16 +110,6 @@ func FollowShare(c *gin.Context) {
130110 })
131111 }
132112 }
133- videoUrl = data .Items [0 ].VideoVersions [0 ].URL
134-
135- if videoUrl == "" {
136- slog .Debug ("No video URL found! :(" )
137- c .HTML (http .StatusOK , "embed.html" , & HtmlOpenGraphData {
138- Title : "VxInstagram - Empty Response" ,
139- Description : "Instagram returned an empty response meaning we can't embed the video. You'll need to watch it in your browser. Sorry!" ,
140- })
141- }
142- }
143113
144114 remote , err := url .Parse (videoUrl )
145115 if err != nil {
@@ -150,24 +120,9 @@ func FollowShare(c *gin.Context) {
150120 Description : "VxInstagram encountered a server side error while processing your request. Request ID:`" + span .SpanID .String () + "`" ,
151121 })
152122 return
153- }
154- remote , err := url .Parse (videoUrl )
155- if err != nil {
156- slog .Error ("Failed to parse CDN video URL" , slog .Any ("err" , err ))
157- sentry .CaptureException (err )
158- c .HTML (http .StatusOK , "embed.html" , & HtmlOpenGraphData {
159- Title : "VxInstagram - Server Error" ,
160- Description : "VxInstagram encountered a server side error while processing your request. Request ID:`" + span .SpanID .String () + "`" ,
161- })
162- return
123+
163124 }
164125
165- proxy := httputil .NewSingleHostReverseProxy (remote )
166- proxy .Director = func (r * http.Request ) {
167- r .Header = c .Request .Header
168- r .Host = remote .Host
169- r .URL = remote
170- r .Header = c .Request .Header .Clone ()
171126 proxy := httputil .NewSingleHostReverseProxy (remote )
172127 proxy .Director = func (r * http.Request ) {
173128 r .Header = c .Request .Header
@@ -178,14 +133,6 @@ func FollowShare(c *gin.Context) {
178133 hopHeaders := []string {
179134 "Connection" , "Keep-Alive" , "Proxy-Authenticate" , "Proxy-Authorization" , "Te" , "Trailer" , "Transfer-Encoding" ,
180135 }
181- hopHeaders := []string {
182- "Connection" , "Keep-Alive" , "Proxy-Authenticate" , "Proxy-Authorization" , "Te" , "Trailer" , "Transfer-Encoding" ,
183- }
184-
185- for _ , h := range hopHeaders {
186- r .Header .Del (h )
187- }
188- }
189136 for _ , h := range hopHeaders {
190137 r .Header .Del (h )
191138 }
@@ -194,7 +141,4 @@ func FollowShare(c *gin.Context) {
194141 slog .Debug ("Success!" )
195142 c .Header ("Cache-Control" , "max-age=43200" )
196143 proxy .ServeHTTP (c .Writer , c .Request )
197- slog .Debug ("Success!" )
198- c .Header ("Cache-Control" , "max-age=43200" )
199- proxy .ServeHTTP (c .Writer , c .Request )
200144}
0 commit comments