mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
Proxy s.pximg.net #45
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
Reference in New Issue
Block a user