Skip to content

Commit c87cd41

Browse files
committed
fixed some bugs and more
1 parent 473c84b commit c87cd41

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

cmd/favicon.ico

16.6 KB
Binary file not shown.

cmd/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"log"
66
"net"
77
"net/http"
8+
9+
_ "embed"
810
"os"
911

1012
"github.com/SyNdicateFoundation/SteamDownloaderAPI/internal/handler"
@@ -29,6 +31,9 @@ func init() {
2931
flag.Parse()
3032
}
3133

34+
//go:embed favicon.ico
35+
var favicon []byte
36+
3237
func main() {
3338
s, err := steamcmd.New(steamCmdPath, steamUser, steamPassword)
3439
if err != nil {
@@ -45,14 +50,14 @@ func main() {
4550
}
4651
}
4752

48-
router := gin.Default()
49-
5053
gin.SetMode(gin.ReleaseMode)
5154

5255
if debugMode {
5356
gin.SetMode(gin.DebugMode)
5457
}
5558

59+
router := gin.Default()
60+
5661
h := handler.New(s)
5762
defer h.Cleanup()
5863

@@ -65,8 +70,13 @@ func main() {
6570

6671
router.Any("/workshop/*path", h.SteamProxyHandler)
6772
router.Any("/app/*path", h.SteamProxyHandler)
73+
router.Any("/public/*path", h.SteamProxyHandler)
6874
router.Any("/sharedfiles/*path", h.SteamProxyHandler)
6975

76+
router.GET("favicon.ico", func(c *gin.Context) {
77+
c.Data(http.StatusOK, "image/x-icon", favicon)
78+
})
79+
7080
unsupportedRoutes := []string{
7181
"/login/home/", "/market/", "/discussions/", "/my/",
7282
"/id/", "/account/", "/profiles/",

internal/handler/proxy.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,33 @@ func (h *SteamDownloaderAPI) SteamProxyHandler(c *gin.Context) {
5353
}
5454

5555
proxy.ModifyResponse = func(res *http.Response) error {
56-
if !strings.Contains(res.Header.Get("Content-Type"), "text/html") {
57-
return nil
58-
}
59-
6056
body, err := io.ReadAll(res.Body)
6157
if err != nil {
6258
return fmt.Errorf("failed to read response body: %w", err)
6359
}
6460

6561
defer res.Body.Close()
6662

63+
if !strings.Contains(res.Header.Get("Content-Type"), "text/html") {
64+
body = bytes.ReplaceAll(body,
65+
[]byte("https://steamcommunity.com/workshop/ajaxfindworkshops"),
66+
[]byte("/workshop/ajaxfindworkshops"),
67+
)
68+
69+
res.Body = io.NopCloser(bytes.NewReader(body))
70+
return nil
71+
}
72+
6773
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(body))
6874
if err != nil {
6975
return fmt.Errorf("failed to parse HTML: %w", err)
7076
}
7177

78+
titleElm := doc.Find("title")
79+
title := titleElm.Text()
80+
title = strings.Replace(title, "Steam Community", "SteamDownloaderAPI", 1)
81+
titleElm.SetText(title)
82+
7283
replacedCollection := true
7384

7485
doc.Find("a[onclick*='SubscribeItem']").Each(func(i int, s *goquery.Selection) {
@@ -80,6 +91,10 @@ func (h *SteamDownloaderAPI) SteamProxyHandler(c *gin.Context) {
8091
}
8192
})
8293

94+
doc.Find(`span[class="valve_links"]`).Each(func(i int, s *goquery.Selection) {
95+
s.AppendHtml(` | <a style="color: #1497cb;font-weight: bold;font-size: medium;" href="https://github.com/SyNdicateFoundation/SteamDownloaderAPI" target="_blank">SteamDownloaderAPI GitHub</a>`)
96+
})
97+
8398
doc.Find(".subscribe[onclick*='SubscribeCollection']").Each(func(i int, s *goquery.Selection) {
8499
onclick, _ := s.Attr("onclick")
85100
if matches := infoRegex.FindStringSubmatch(onclick); len(matches) == 3 {

0 commit comments

Comments
 (0)