diff --git a/server/spider.go b/server/spider.go index e96d027..0a30231 100644 --- a/server/spider.go +++ b/server/spider.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "net/url" "strconv" "gitea.timerzz.com/kedaya_haitao/coach-spider/spider" @@ -50,31 +51,31 @@ func (s *SpiderSvc) FetchArticlePrice(ctx fiber.Ctx) error { } func (s *SpiderSvc) FetchArticleDetail(ctx fiber.Ctx) error { - pid := ctx.Params("pid") - if pid == "" { - return fmt.Errorf("pid is empty") + pid, err := url.QueryUnescape(ctx.Params("pid")) + if err != nil { + return err } - if err := s.ctl.FetchArticleDetail(ctx.Context(), pid); err != nil { + if err = s.ctl.FetchArticleDetail(ctx.Context(), pid); err != nil { return err } return ctx.JSON(web.NewResponse("ok")) } func (s *SpiderSvc) FetchArticleAts(ctx fiber.Ctx) error { - pid := ctx.Params("pid") - if pid == "" { - return fmt.Errorf("pid is empty") + pid, err := url.QueryUnescape(ctx.Params("pid")) + if err != nil { + return err } - if err := s.ctl.FetchArticleAts(ctx.Context(), pid); err != nil { + if err = s.ctl.FetchArticleAts(ctx.Context(), pid); err != nil { return err } return ctx.JSON(web.NewResponse("ok")) } func (s *SpiderSvc) GetArticleAts(ctx fiber.Ctx) error { - pid := ctx.Params("pid") - if pid == "" { - return fmt.Errorf("pid is empty") + pid, err := url.QueryUnescape(ctx.Params("pid")) + if err != nil { + return err } ats, err := s.ctl.GetArticleAts(ctx.Context(), pid) if err != nil {