Proxy s.pximg.net #45

This commit is contained in:
VnPower
2024-01-22 19:45:21 +07:00
parent 8f65044b00
commit 4d06de3eb3
3 changed files with 34 additions and 1 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ type ArtworkBrief struct {
}
func ProxyImages(s, proxy string) string {
s = strings.ReplaceAll(s, `i.pximg.net`, proxy)
s = strings.ReplaceAll(s, `https:\/\/i.pximg.net`, "https://"+proxy)
s = strings.ReplaceAll(s, `https:\/\/s.pximg.net`, "/s.pximg.net")
return s
}
+2
View File
@@ -144,6 +144,8 @@ func main() {
return c.Redirect("artworks/" + c.Query("illust_id"))
})
server.Get("/s.pximg.net/*", pages.SPximgProxy)
// Listen
if config.GlobalServerConfig.UnixSocket != "" {
ln, err := net.Listen("unix", config.GlobalServerConfig.UnixSocket)
+30
View File
@@ -0,0 +1,30 @@
package pages
import (
"fmt"
"io"
"net/http"
"github.com/gofiber/fiber/v2"
)
func SPximgProxy(c *fiber.Ctx) error {
URL := fmt.Sprintf("https://s.pximg.net/%s", c.Params("*"))
req, _ := http.NewRequest("GET", URL, nil)
// Make the request
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
c.Set("Content-Type", "image/jpg, image/png, image/jpeg")
return c.Send([]byte(body))
}