From 3b321f099d1d164ede48da39627f8bac193bab97 Mon Sep 17 00:00:00 2001 From: timerzz Date: Mon, 2 Dec 2024 14:11:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=A1=AB=E5=86=99?= =?UTF-8?q?=E7=9A=84pid=E4=B8=8D=E8=83=BD=E5=8C=85=E5=90=AB/=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/spider.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 {