proxy.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package routes
  2. import (
  3. "fmt"
  4. "io"
  5. "net/http"
  6. "github.com/gofiber/fiber/v2"
  7. )
  8. func SPximgProxy(c *fiber.Ctx) error {
  9. URL := fmt.Sprintf("https://s.pximg.net/%s", c.Params("*"))
  10. req, err := http.NewRequest("GET", URL, nil)
  11. if err != nil {
  12. return err
  13. }
  14. req = req.WithContext(c.Context())
  15. // Make the request
  16. resp, err := http.DefaultClient.Do(req)
  17. if err != nil {
  18. return err
  19. }
  20. body, err := io.ReadAll(resp.Body)
  21. if err != nil {
  22. return err
  23. }
  24. c.Set("Content-Type", resp.Header.Get("Content-Type"))
  25. return c.Send([]byte(body))
  26. }
  27. func IPximgProxy(c *fiber.Ctx) error {
  28. URL := fmt.Sprintf("https://i.pximg.net/%s", c.Params("*"))
  29. req, err := http.NewRequest("GET", URL, nil)
  30. if err != nil {
  31. return err
  32. }
  33. req = req.WithContext(c.Context())
  34. req.Header.Add("Referer", "https://www.pixiv.net/")
  35. // Make the request
  36. resp, err := http.DefaultClient.Do(req)
  37. if err != nil {
  38. return err
  39. }
  40. body, err := io.ReadAll(resp.Body)
  41. if err != nil {
  42. return err
  43. }
  44. c.Set("Content-Type", resp.Header.Get("Content-Type"))
  45. return c.Send([]byte(body))
  46. }
  47. func UgoiraProxy(c *fiber.Ctx) error {
  48. URL := fmt.Sprintf("https://ugoira.com/api/mp4/%s", c.Params("*"))
  49. req, err := http.NewRequest("GET", URL, nil)
  50. if err != nil {
  51. return err
  52. }
  53. req = req.WithContext(c.Context())
  54. // Make the request
  55. resp, err := http.DefaultClient.Do(req)
  56. if err != nil {
  57. return err
  58. }
  59. body, err := io.ReadAll(resp.Body)
  60. if err != nil {
  61. return err
  62. }
  63. c.Set("Content-Type", resp.Header.Get("Content-Type"))
  64. return c.Send([]byte(body))
  65. }