From 59a0efe59ac8e62ed08f945cc411680dda9cc8b7 Mon Sep 17 00:00:00 2001 From: xuthus5 Date: Sun, 15 Oct 2023 21:30:40 +0800 Subject: [PATCH] feat: read raw content --- Dockerfile | 1 + .../v1/autogen_router_pastebin_service.go | 27 +- api_services/v1/pastebin_controller.go | 41 ++- api_services/v1/pastebin_module.pb.go | 251 ++++++++++++++---- api_services/v1/pastebin_module.proto | 12 + config_dev.yaml | 2 +- go.mod | 14 +- model/v1/autogen_model_pastebin_model.go | 2 +- register/router.go | 10 +- webui/src/App.vue | 16 +- .../gen/api_services/v1/pastebin_module.ts | 201 +++++++++++--- webui/src/gen/model/v1/pastebin_model.ts | 48 ++-- webui/src/views/DocumentView.vue | 10 +- 13 files changed, 468 insertions(+), 167 deletions(-) diff --git a/Dockerfile b/Dockerfile index df0e120..5879013 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN sed -e 's|^metalink=|#metalink=|g' \ npm config set registry https://registry.npm.taobao.org COPY . /app +RUN buf generate --exclude-path node_modules RUN cd webui && npm install && npm run build &&\ cd .. && go mod tidy && go build . diff --git a/api_services/v1/autogen_router_pastebin_service.go b/api_services/v1/autogen_router_pastebin_service.go index 17fa868..08d4254 100644 --- a/api_services/v1/autogen_router_pastebin_service.go +++ b/api_services/v1/autogen_router_pastebin_service.go @@ -1,24 +1,25 @@ // Code generated by protoc-gen-coco. DO NOT EDIT. // source: api_services/v1/pastebin_module.proto -// generate at: 2023-09-30 21:44:38 +// generate at: 2023-10-15 21:21:24 package api_servicesv1 import ( - "gitter.top/coco/coco/core" + "gitter.top/coco/coco" ) type AutoGenPastebinServiceImpl interface { - List(ctx *core.Context, req *PastebinServiceListReq) (resp *PastebinServiceListResp, err error) - Add(ctx *core.Context, req *PastebinServiceAddReq) (resp *PastebinServiceAddResp, err error) - Update(ctx *core.Context, req *PastebinServiceUpdateReq) (resp *PastebinServiceUpdateResp, err error) - Get(ctx *core.Context, req *PastebinServiceGetReq) (resp *PastebinServiceGetResp, err error) + List(ctx *coco.Context, req *PastebinServiceListReq) (resp *PastebinServiceListResp, err error) + Add(ctx *coco.Context, req *PastebinServiceAddReq) (resp *PastebinServiceAddResp, err error) + Update(ctx *coco.Context, req *PastebinServiceUpdateReq) (resp *PastebinServiceUpdateResp, err error) + Get(ctx *coco.Context, req *PastebinServiceGetReq) (resp *PastebinServiceGetResp, err error) + Raw(ctx *coco.Context, req *PastebinServiceRawReq) (resp *PastebinServiceRawResp, err error) } -var ( - AutoGenPastebinServiceRouterMap = &core.Routers{ +func (receiver *PastebinService) GetRouterMap() *coco.Routers { + return &coco.Routers{ BaseURL: "/v1/pastebin", - Apis: core.RouterMap{ + Apis: coco.RouterMap{ "List": { API: "/list", Method: "GET", @@ -43,6 +44,12 @@ var ( Author: "Young Xu", Describe: "获取一条记录", }, + "Raw": { + API: "/raw", + Method: "GET", + Author: "Young Xu", + Describe: "获取原文内容", + }, }, } -) +} diff --git a/api_services/v1/pastebin_controller.go b/api_services/v1/pastebin_controller.go index 01bd2db..e350155 100644 --- a/api_services/v1/pastebin_controller.go +++ b/api_services/v1/pastebin_controller.go @@ -2,7 +2,7 @@ package api_servicesv1 import ( "github.com/sirupsen/logrus" - "gitter.top/coco/coco/core" + "gitter.top/coco/coco" "pastebin/common" "pastebin/internal/repositories" modelv1 "pastebin/model/v1" @@ -15,7 +15,7 @@ type PastebinService struct{} var _ AutoGenPastebinServiceImpl = (*PastebinService)(nil) // List 列表 -func (receiver *PastebinService) List(ctx *core.Context, req *PastebinServiceListReq) (resp *PastebinServiceListResp, err error) { +func (receiver *PastebinService) List(ctx *coco.Context, req *PastebinServiceListReq) (resp *PastebinServiceListResp, err error) { resp = new(PastebinServiceListResp) if req.PageSize == 0 { @@ -66,7 +66,7 @@ func (receiver *PastebinService) List(ctx *core.Context, req *PastebinServiceLis } // Add 新建 -func (receiver *PastebinService) Add(ctx *core.Context, req *PastebinServiceAddReq) (resp *PastebinServiceAddResp, err error) { +func (receiver *PastebinService) Add(ctx *coco.Context, req *PastebinServiceAddReq) (resp *PastebinServiceAddResp, err error) { resp = new(PastebinServiceAddResp) var expiredAt = time.Now() @@ -107,7 +107,7 @@ func (receiver *PastebinService) Add(ctx *core.Context, req *PastebinServiceAddR } // Update 更新 -func (receiver *PastebinService) Update(ctx *core.Context, req *PastebinServiceUpdateReq) (resp *PastebinServiceUpdateResp, err error) { +func (receiver *PastebinService) Update(ctx *coco.Context, req *PastebinServiceUpdateReq) (resp *PastebinServiceUpdateResp, err error) { resp = new(PastebinServiceUpdateResp) // TODO impl... @@ -116,7 +116,7 @@ func (receiver *PastebinService) Update(ctx *core.Context, req *PastebinServiceU } // Get 获取一条记录 -func (receiver *PastebinService) Get(ctx *core.Context, req *PastebinServiceGetReq) (resp *PastebinServiceGetResp, err error) { +func (receiver *PastebinService) Get(ctx *coco.Context, req *PastebinServiceGetReq) (resp *PastebinServiceGetResp, err error) { resp = new(PastebinServiceGetResp) db := repositories.GetPastebin() @@ -129,11 +129,11 @@ func (receiver *PastebinService) Get(ctx *core.Context, req *PastebinServiceGetR } if record.NeedPassword && req.Password == "" { - return nil, core.CreateErrorWithMsg(4001, "pastebin need password") + return nil, coco.CreateErrorWithMsg(4001, "pastebin need password") } if record.NeedPassword && req.Password != record.Password { - return nil, core.CreateErrorWithMsg(4002, "incorrect password") + return nil, coco.CreateErrorWithMsg(4002, "incorrect password") } item := &PastebinServiceRecord{ @@ -152,3 +152,30 @@ func (receiver *PastebinService) Get(ctx *core.Context, req *PastebinServiceGetR return resp, nil } + +// Raw 获取原文内容 +func (receiver *PastebinService) Raw(ctx *coco.Context, req *PastebinServiceRawReq) (resp *PastebinServiceRawResp, err error) { + resp = new(PastebinServiceRawResp) + + db := repositories.GetPastebin() + + var record modelv1.ModelPastebin + + if err := db.Find().SetWhere("short_id = ?", req.Key).FindOne(&record); err != nil { + logrus.Errorf("query records failed: %v", err) + return nil, err + } + + if record.NeedPassword && req.Password == "" { + return nil, coco.CreateErrorWithMsg(4001, "pastebin need password") + } + + if record.NeedPassword && req.Password != record.Password { + return nil, coco.CreateErrorWithMsg(4002, "incorrect password") + } + + _, _ = ctx.Writer.WriteString(record.Content) + ctx.Header("Content-Type", "text/plain") + + return resp, nil +} diff --git a/api_services/v1/pastebin_module.pb.go b/api_services/v1/pastebin_module.pb.go index f83d032..a750210 100644 --- a/api_services/v1/pastebin_module.pb.go +++ b/api_services/v1/pastebin_module.pb.go @@ -592,6 +592,99 @@ func (x *PastebinServiceGetResp) GetRecord() *PastebinServiceRecord { return nil } +type PastebinServiceRawReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *PastebinServiceRawReq) Reset() { + *x = PastebinServiceRawReq{} + if protoimpl.UnsafeEnabled { + mi := &file_api_services_v1_pastebin_module_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PastebinServiceRawReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PastebinServiceRawReq) ProtoMessage() {} + +func (x *PastebinServiceRawReq) ProtoReflect() protoreflect.Message { + mi := &file_api_services_v1_pastebin_module_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PastebinServiceRawReq.ProtoReflect.Descriptor instead. +func (*PastebinServiceRawReq) Descriptor() ([]byte, []int) { + return file_api_services_v1_pastebin_module_proto_rawDescGZIP(), []int{9} +} + +func (x *PastebinServiceRawReq) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *PastebinServiceRawReq) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type PastebinServiceRawResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *PastebinServiceRawResp) Reset() { + *x = PastebinServiceRawResp{} + if protoimpl.UnsafeEnabled { + mi := &file_api_services_v1_pastebin_module_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PastebinServiceRawResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PastebinServiceRawResp) ProtoMessage() {} + +func (x *PastebinServiceRawResp) ProtoReflect() protoreflect.Message { + mi := &file_api_services_v1_pastebin_module_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PastebinServiceRawResp.ProtoReflect.Descriptor instead. +func (*PastebinServiceRawResp) Descriptor() ([]byte, []int) { + return file_api_services_v1_pastebin_module_proto_rawDescGZIP(), []int{10} +} + var File_api_services_v1_pastebin_module_proto protoreflect.FileDescriptor var file_api_services_v1_pastebin_module_proto_rawDesc = []byte{ @@ -659,47 +752,59 @@ var file_api_services_v1_pastebin_module_proto_rawDesc = []byte{ 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, - 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2a, 0x42, 0x0a, 0x0b, 0x45, 0x78, 0x70, 0x69, 0x72, - 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x6f, 0x72, 0x65, 0x76, 0x65, - 0x72, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x61, 0x79, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, - 0x57, 0x65, 0x65, 0x6b, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x6f, 0x6e, 0x74, 0x68, 0x10, - 0x03, 0x12, 0x08, 0x0a, 0x04, 0x59, 0x65, 0x61, 0x72, 0x10, 0x04, 0x32, 0xfd, 0x02, 0x0a, 0x0f, - 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, - 0x59, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x27, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, - 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, - 0x1a, 0x28, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x56, 0x0a, 0x03, 0x41, 0x64, - 0x64, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x22, 0x45, 0x0a, 0x15, 0x50, 0x61, 0x73, 0x74, 0x65, + 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x61, 0x77, 0x52, 0x65, 0x71, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x18, + 0x0a, 0x16, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x52, 0x61, 0x77, 0x52, 0x65, 0x73, 0x70, 0x2a, 0x42, 0x0a, 0x0b, 0x45, 0x78, 0x70, 0x69, + 0x72, 0x65, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x6f, 0x72, 0x65, 0x76, + 0x65, 0x72, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x61, 0x79, 0x10, 0x01, 0x12, 0x08, 0x0a, + 0x04, 0x57, 0x65, 0x65, 0x6b, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x6f, 0x6e, 0x74, 0x68, + 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x59, 0x65, 0x61, 0x72, 0x10, 0x04, 0x32, 0xd5, 0x03, 0x0a, + 0x0f, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x59, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x27, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, + 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x71, 0x1a, 0x28, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x69, 0x5f, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, - 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x52, 0x65, - 0x73, 0x70, 0x12, 0x5f, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x29, 0x2e, 0x61, - 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, - 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x2a, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, - 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x12, 0x56, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x69, - 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, - 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x47, 0x65, 0x74, 0x52, - 0x65, 0x71, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x56, 0x0a, 0x03, 0x41, + 0x64, 0x64, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x42, 0xb9, 0x01, 0x0a, 0x13, - 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x2e, 0x76, 0x31, 0x42, 0x13, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x34, 0x70, 0x61, 0x73, 0x74, - 0x65, 0x62, 0x69, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x73, 0x2f, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x76, - 0x31, 0x3b, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x76, 0x31, - 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58, 0xaa, 0x02, 0x0e, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0e, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1a, 0x41, 0x70, 0x69, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0f, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x69, + 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, + 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x52, + 0x65, 0x73, 0x70, 0x12, 0x5f, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x29, 0x2e, + 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x2a, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, + 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x56, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x26, 0x2e, 0x61, 0x70, + 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, + 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x47, 0x65, 0x74, + 0x52, 0x65, 0x71, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x56, 0x0a, 0x03, + 0x52, 0x61, 0x77, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x61, 0x77, 0x52, 0x65, 0x71, 0x1a, 0x27, 0x2e, 0x61, 0x70, + 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, + 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x61, 0x77, + 0x52, 0x65, 0x73, 0x70, 0x42, 0xb9, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x70, 0x69, + 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x13, 0x50, 0x61, + 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x50, 0x01, 0x5a, 0x34, 0x70, 0x61, 0x73, 0x74, 0x65, 0x62, 0x69, 0x6e, 0x2f, 0x61, 0x70, + 0x69, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x5f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x70, 0x69, 0x5f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58, 0xaa, + 0x02, 0x0e, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x56, 0x31, + 0xca, 0x02, 0x0e, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x5c, 0x56, + 0x31, 0xe2, 0x02, 0x1a, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x5c, + 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, + 0x0f, 0x41, 0x70, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x3a, 0x3a, 0x56, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -715,7 +820,7 @@ func file_api_services_v1_pastebin_module_proto_rawDescGZIP() []byte { } var file_api_services_v1_pastebin_module_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_api_services_v1_pastebin_module_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_api_services_v1_pastebin_module_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_api_services_v1_pastebin_module_proto_goTypes = []interface{}{ (ExpireLevel)(0), // 0: api_services.v1.ExpireLevel (*PastebinServiceRecord)(nil), // 1: api_services.v1.PastebinServiceRecord @@ -727,26 +832,30 @@ var file_api_services_v1_pastebin_module_proto_goTypes = []interface{}{ (*PastebinServiceUpdateResp)(nil), // 7: api_services.v1.PastebinServiceUpdateResp (*PastebinServiceGetReq)(nil), // 8: api_services.v1.PastebinServiceGetReq (*PastebinServiceGetResp)(nil), // 9: api_services.v1.PastebinServiceGetResp + (*PastebinServiceRawReq)(nil), // 10: api_services.v1.PastebinServiceRawReq + (*PastebinServiceRawResp)(nil), // 11: api_services.v1.PastebinServiceRawResp } var file_api_services_v1_pastebin_module_proto_depIdxs = []int32{ - 0, // 0: api_services.v1.PastebinServiceRecord.expire_level:type_name -> api_services.v1.ExpireLevel - 1, // 1: api_services.v1.PastebinServiceListResp.items:type_name -> api_services.v1.PastebinServiceRecord - 1, // 2: api_services.v1.PastebinServiceAddReq.record:type_name -> api_services.v1.PastebinServiceRecord - 1, // 3: api_services.v1.PastebinServiceUpdateReq.record:type_name -> api_services.v1.PastebinServiceRecord - 1, // 4: api_services.v1.PastebinServiceGetResp.record:type_name -> api_services.v1.PastebinServiceRecord - 2, // 5: api_services.v1.PastebinService.List:input_type -> api_services.v1.PastebinServiceListReq - 4, // 6: api_services.v1.PastebinService.Add:input_type -> api_services.v1.PastebinServiceAddReq - 6, // 7: api_services.v1.PastebinService.Update:input_type -> api_services.v1.PastebinServiceUpdateReq - 8, // 8: api_services.v1.PastebinService.Get:input_type -> api_services.v1.PastebinServiceGetReq - 3, // 9: api_services.v1.PastebinService.List:output_type -> api_services.v1.PastebinServiceListResp - 5, // 10: api_services.v1.PastebinService.Add:output_type -> api_services.v1.PastebinServiceAddResp - 7, // 11: api_services.v1.PastebinService.Update:output_type -> api_services.v1.PastebinServiceUpdateResp - 9, // 12: api_services.v1.PastebinService.Get:output_type -> api_services.v1.PastebinServiceGetResp - 9, // [9:13] is the sub-list for method output_type - 5, // [5:9] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 0, // 0: api_services.v1.PastebinServiceRecord.expire_level:type_name -> api_services.v1.ExpireLevel + 1, // 1: api_services.v1.PastebinServiceListResp.items:type_name -> api_services.v1.PastebinServiceRecord + 1, // 2: api_services.v1.PastebinServiceAddReq.record:type_name -> api_services.v1.PastebinServiceRecord + 1, // 3: api_services.v1.PastebinServiceUpdateReq.record:type_name -> api_services.v1.PastebinServiceRecord + 1, // 4: api_services.v1.PastebinServiceGetResp.record:type_name -> api_services.v1.PastebinServiceRecord + 2, // 5: api_services.v1.PastebinService.List:input_type -> api_services.v1.PastebinServiceListReq + 4, // 6: api_services.v1.PastebinService.Add:input_type -> api_services.v1.PastebinServiceAddReq + 6, // 7: api_services.v1.PastebinService.Update:input_type -> api_services.v1.PastebinServiceUpdateReq + 8, // 8: api_services.v1.PastebinService.Get:input_type -> api_services.v1.PastebinServiceGetReq + 10, // 9: api_services.v1.PastebinService.Raw:input_type -> api_services.v1.PastebinServiceRawReq + 3, // 10: api_services.v1.PastebinService.List:output_type -> api_services.v1.PastebinServiceListResp + 5, // 11: api_services.v1.PastebinService.Add:output_type -> api_services.v1.PastebinServiceAddResp + 7, // 12: api_services.v1.PastebinService.Update:output_type -> api_services.v1.PastebinServiceUpdateResp + 9, // 13: api_services.v1.PastebinService.Get:output_type -> api_services.v1.PastebinServiceGetResp + 11, // 14: api_services.v1.PastebinService.Raw:output_type -> api_services.v1.PastebinServiceRawResp + 10, // [10:15] is the sub-list for method output_type + 5, // [5:10] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_api_services_v1_pastebin_module_proto_init() } @@ -863,6 +972,30 @@ func file_api_services_v1_pastebin_module_proto_init() { return nil } } + file_api_services_v1_pastebin_module_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PastebinServiceRawReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_services_v1_pastebin_module_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PastebinServiceRawResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -870,7 +1003,7 @@ func file_api_services_v1_pastebin_module_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_api_services_v1_pastebin_module_proto_rawDesc, NumEnums: 1, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/api_services/v1/pastebin_module.proto b/api_services/v1/pastebin_module.proto index 2936f64..6be7edd 100644 --- a/api_services/v1/pastebin_module.proto +++ b/api_services/v1/pastebin_module.proto @@ -29,6 +29,11 @@ service PastebinService { // @method: GET // @api: /get rpc Get (PastebinServiceGetReq) returns (PastebinServiceGetResp); + // @desc: 获取原文内容 + // @author: Young Xu + // @method: GET + // @api: /raw + rpc Raw (PastebinServiceRawReq) returns (PastebinServiceRawResp); } @@ -85,3 +90,10 @@ message PastebinServiceGetReq { message PastebinServiceGetResp { PastebinServiceRecord record = 1; } + +message PastebinServiceRawReq { + string key = 1; + string password = 2; +} + +message PastebinServiceRawResp {} diff --git a/config_dev.yaml b/config_dev.yaml index bce8865..b9fd63e 100644 --- a/config_dev.yaml +++ b/config_dev.yaml @@ -1,5 +1,5 @@ server-name: pastebin -server-listen: 0.0.0.0:38080 +server-listen: 127.0.0.1:38080 environment: dev db: dbname: pastebin.db diff --git a/go.mod b/go.mod index 0388774..5dca1f4 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/sqids/sqids-go v0.4.1 - gitter.top/coco/coco v0.0.0-20230903142509-eaab943a68bc + gitter.top/coco/coco v0.0.0-20231013143029-cb23d9e80ddd gitter.top/common/lormatter v0.0.0-20230910075849-28d49dccd03a gitter.top/drivers/sdbc v0.0.0-20230929063242-b4baa9aa7ff8 google.golang.org/protobuf v1.31.0 @@ -15,17 +15,17 @@ require ( ) require ( - github.com/bytedance/sonic v1.10.0 // indirect + github.com/bytedance/sonic v1.10.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/glebarez/go-sqlite v1.21.2 // indirect github.com/glebarez/sqlite v1.9.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.15.3 // indirect + github.com/go-playground/validator/v10 v10.15.5 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/uuid v1.3.1 // indirect github.com/gorilla/schema v1.2.0 // indirect @@ -46,9 +46,9 @@ require ( github.com/ugorji/go/codec v1.2.11 // indirect gitter.top/common/goref v0.0.0-20230916075900-7b64840146ae // indirect golang.org/x/arch v0.5.0 // indirect - golang.org/x/crypto v0.12.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect gorm.io/gorm v1.25.4 // indirect modernc.org/libc v1.24.1 // indirect diff --git a/model/v1/autogen_model_pastebin_model.go b/model/v1/autogen_model_pastebin_model.go index c5e7813..518a487 100644 --- a/model/v1/autogen_model_pastebin_model.go +++ b/model/v1/autogen_model_pastebin_model.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-coco. DO NOT EDIT. // source: model/v1/pastebin_model.proto -// generate at: 2023-09-30 21:44:38 +// generate at: 2023-10-15 21:21:24 package modelv1 diff --git a/register/router.go b/register/router.go index 72d8550..b1ffbb3 100644 --- a/register/router.go +++ b/register/router.go @@ -3,7 +3,7 @@ package register import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "gitter.top/coco/coco/core" + "gitter.top/coco/coco" "pastebin/api_services/v1" "pastebin/config" @@ -19,10 +19,10 @@ func NewRouter() *Router { func (receiver *Router) Register() error { cfg := config.Get() // 从这里开始实例化路由注册器 - var register = core.NewRegister() - register.DefaultRouter(core.WithListenAddress(cfg.ServerListen), - core.WithGinMode(gin.ReleaseMode), core.WithCors(), core.WithRecovery()) - register.RegisterStruct(api_servicesv1.AutoGenPastebinServiceRouterMap, &api_servicesv1.PastebinService{}) + var register = coco.NewRegister() + register.DefaultRouter(coco.WithListenAddress(cfg.ServerListen), + coco.WithGinMode(gin.ReleaseMode), coco.WithCors(), coco.WithRecovery()) + register.RegisterStruct(&api_servicesv1.PastebinService{}) _ = register.PreRun(func() error { engine := register.RawEngine() engine.Static("/assets", "./webui/dist/assets") diff --git a/webui/src/App.vue b/webui/src/App.vue index 1ecbd5d..1e64d27 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -6,14 +6,22 @@ const pager = usePageStore()