From 27d949fd8e193ed536d33f7bb5164286711bfbda Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Wed, 24 May 2023 17:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=9F=A5=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=96=87=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 31083cc07b2b34ce4bc4f6b69b9b920fb6d3af1b --- adaptor/PCM-CORE/api/desc/pcm.api | 3 ++ .../PCM-CORE/api/desc/storage/pcm-storage.api | 11 ++++++- .../internal/handler/image/checkhandler.go | 28 +++++++++++++++++ .../PCM-CORE/api/internal/handler/routes.go | 6 +++- .../api/internal/logic/image/checklogic.go | 31 +++++++++++++++++++ adaptor/PCM-CORE/api/internal/types/types.go | 8 +++++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 adaptor/PCM-CORE/api/internal/handler/image/checkhandler.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/image/checklogic.go diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 6dc1a14a..3d81dc34 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -192,4 +192,7 @@ service pcm { @handler imageListHandler get /image/list () returns (imageListResp) + + @handler checkHandler + get /image/check (checkReq) returns (checkResp) } \ No newline at end of file diff --git a/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api b/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api index 87117496..96ecd53d 100644 --- a/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api +++ b/adaptor/PCM-CORE/api/desc/storage/pcm-storage.api @@ -118,4 +118,13 @@ type ( name string `json:"name"` tags []string `json:"tags" copier:"tags"` } -) \ No newline at end of file +) + +type ( + checkReq { + fileMd5 string `json:"fileMd5"` + } + checkResp { + exist bool `json:"exist"` + } +) diff --git a/adaptor/PCM-CORE/api/internal/handler/image/checkhandler.go b/adaptor/PCM-CORE/api/internal/handler/image/checkhandler.go new file mode 100644 index 00000000..663475f2 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/image/checkhandler.go @@ -0,0 +1,28 @@ +package image + +import ( + "net/http" + + "PCM/adaptor/PCM-CORE/api/internal/logic/image" + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func CheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CheckReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := image.NewCheckLogic(r.Context(), svcCtx) + resp, err := l.Check(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/adaptor/PCM-CORE/api/internal/handler/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index 7acf9dc8..48c5e148 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -286,8 +286,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/image/list", Handler: image.ImageListHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/image/check", + Handler: image.CheckHandler(serverCtx), + }, }, - rest.WithMaxBytes(624288000), rest.WithPrefix("/pcm/v1"), ) } diff --git a/adaptor/PCM-CORE/api/internal/logic/image/checklogic.go b/adaptor/PCM-CORE/api/internal/logic/image/checklogic.go new file mode 100644 index 00000000..51783b07 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/image/checklogic.go @@ -0,0 +1,31 @@ +package image + +import ( + "context" + "path" + + "PCM/adaptor/PCM-CORE/api/internal/svc" + "PCM/adaptor/PCM-CORE/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CheckLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckLogic { + return &CheckLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CheckLogic) Check(req *types.CheckReq) (resp *types.CheckResp, err error) { + // todo: add your logic here and delete this line + path.Join() + return +} diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index 50522c5d..07c2ad12 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -1902,3 +1902,11 @@ type ImageTagsResp struct { Name string `json:"name"` Tags []string `json:"tags" copier:"tags"` } + +type CheckReq struct { + FileMd5 string `json:"fileMd5"` +} + +type CheckResp struct { + Exist bool `json:"exist"` +}