feat: read raw content

This commit is contained in:
xuthus5 2023-10-15 21:30:40 +08:00
parent d50a651865
commit 59a0efe59a
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
13 changed files with 468 additions and 167 deletions

View File

@ -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 .

View File

@ -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: "获取原文内容",
},
},
}
)
}

View File

@ -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
}

View File

@ -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,6 +832,8 @@ 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
@ -738,12 +845,14 @@ var file_api_services_v1_pastebin_module_proto_depIdxs = []int32{
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
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
@ -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,
},

View File

@ -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 {}

View File

@ -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

14
go.mod
View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -6,14 +6,22 @@ const pager = usePageStore()
</script>
<template>
<div class="hero bg-base-200">
<div class="hero bg-base-200" v-if="pager.page !== 'raw'">
<div class="hero-content text-center">
<div class="max-w-md">
<h1 class="text-5xl font-bold">Pastebin!</h1>
<p class="py-6">本网站旨在用作各方之间粘贴信息的短期交换提交的数据不保证是永久性的并且可能随时被删除</p>
<RouterLink :to="{name: pager.reversal()}" class="btn btn-primary">
<span v-if="pager.reversal() === 'home'">首页</span>
<span v-else>列表</span>
<RouterLink :to="{name: 'list'}" class="btn btn-primary" v-if="pager.page === 'home'">
列表
</RouterLink>
<RouterLink :to="{name: 'home'}" class="btn btn-primary" v-if="pager.page === 'list'">
首页
</RouterLink>
<RouterLink :to="{name: 'home'}" class="btn btn-primary" v-if="pager.page === 'doc'">
首页
</RouterLink>
<RouterLink :to="{name: 'list'}" class="btn btn-primary ml-2" v-if="pager.page === 'doc'">
列表
</RouterLink>
</div>
</div>

View File

@ -119,6 +119,14 @@ export interface PastebinServiceGetResp {
record: PastebinServiceRecord | undefined;
}
export interface PastebinServiceRawReq {
key: string;
password: string;
}
export interface PastebinServiceRawResp {
}
function createBasePastebinServiceRecord(): PastebinServiceRecord {
return {
id: 0,
@ -279,18 +287,18 @@ export const PastebinServiceRecord = {
fromJSON(object: any): PastebinServiceRecord {
return {
id: isSet(object.id) ? Number(object.id) : 0,
key: isSet(object.key) ? String(object.key) : "",
title: isSet(object.title) ? String(object.title) : "",
content: isSet(object.content) ? String(object.content) : "",
created_at: isSet(object.createdAt) ? String(object.createdAt) : "",
expired_at: isSet(object.expiredAt) ? String(object.expiredAt) : "",
need_password: isSet(object.needPassword) ? Boolean(object.needPassword) : false,
editable: isSet(object.editable) ? Boolean(object.editable) : false,
id: isSet(object.id) ? globalThis.Number(object.id) : 0,
key: isSet(object.key) ? globalThis.String(object.key) : "",
title: isSet(object.title) ? globalThis.String(object.title) : "",
content: isSet(object.content) ? globalThis.String(object.content) : "",
created_at: isSet(object.createdAt) ? globalThis.String(object.createdAt) : "",
expired_at: isSet(object.expiredAt) ? globalThis.String(object.expiredAt) : "",
need_password: isSet(object.needPassword) ? globalThis.Boolean(object.needPassword) : false,
editable: isSet(object.editable) ? globalThis.Boolean(object.editable) : false,
expire_level: isSet(object.expireLevel) ? expireLevelFromJSON(object.expireLevel) : 0,
password: isSet(object.password) ? String(object.password) : "",
lang: isSet(object.lang) ? String(object.lang) : "",
author: isSet(object.author) ? String(object.author) : "",
password: isSet(object.password) ? globalThis.String(object.password) : "",
lang: isSet(object.lang) ? globalThis.String(object.lang) : "",
author: isSet(object.author) ? globalThis.String(object.author) : "",
};
},
@ -403,8 +411,8 @@ export const PastebinServiceListReq = {
fromJSON(object: any): PastebinServiceListReq {
return {
page_size: isSet(object.pageSize) ? Number(object.pageSize) : 0,
current_page: isSet(object.currentPage) ? Number(object.currentPage) : 0,
page_size: isSet(object.pageSize) ? globalThis.Number(object.pageSize) : 0,
current_page: isSet(object.currentPage) ? globalThis.Number(object.currentPage) : 0,
};
},
@ -477,8 +485,10 @@ export const PastebinServiceListResp = {
fromJSON(object: any): PastebinServiceListResp {
return {
items: Array.isArray(object?.items) ? object.items.map((e: any) => PastebinServiceRecord.fromJSON(e)) : [],
has_more: isSet(object.hasMore) ? Boolean(object.hasMore) : false,
items: globalThis.Array.isArray(object?.items)
? object.items.map((e: any) => PastebinServiceRecord.fromJSON(e))
: [],
has_more: isSet(object.hasMore) ? globalThis.Boolean(object.hasMore) : false,
};
},
@ -755,8 +765,8 @@ export const PastebinServiceGetReq = {
fromJSON(object: any): PastebinServiceGetReq {
return {
key: isSet(object.key) ? String(object.key) : "",
password: isSet(object.password) ? String(object.password) : "",
key: isSet(object.key) ? globalThis.String(object.key) : "",
password: isSet(object.password) ? globalThis.String(object.password) : "",
};
},
@ -841,6 +851,123 @@ export const PastebinServiceGetResp = {
},
};
function createBasePastebinServiceRawReq(): PastebinServiceRawReq {
return { key: "", password: "" };
}
export const PastebinServiceRawReq = {
encode(message: PastebinServiceRawReq, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.key !== "") {
writer.uint32(10).string(message.key);
}
if (message.password !== "") {
writer.uint32(18).string(message.password);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): PastebinServiceRawReq {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePastebinServiceRawReq();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag !== 10) {
break;
}
message.key = reader.string();
continue;
case 2:
if (tag !== 18) {
break;
}
message.password = reader.string();
continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(object: any): PastebinServiceRawReq {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
password: isSet(object.password) ? globalThis.String(object.password) : "",
};
},
toJSON(message: PastebinServiceRawReq): unknown {
const obj: any = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.password !== "") {
obj.password = message.password;
}
return obj;
},
create<I extends Exact<DeepPartial<PastebinServiceRawReq>, I>>(base?: I): PastebinServiceRawReq {
return PastebinServiceRawReq.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<PastebinServiceRawReq>, I>>(object: I): PastebinServiceRawReq {
const message = createBasePastebinServiceRawReq();
message.key = object.key ?? "";
message.password = object.password ?? "";
return message;
},
};
function createBasePastebinServiceRawResp(): PastebinServiceRawResp {
return {};
}
export const PastebinServiceRawResp = {
encode(_: PastebinServiceRawResp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): PastebinServiceRawResp {
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePastebinServiceRawResp();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},
fromJSON(_: any): PastebinServiceRawResp {
return {};
},
toJSON(_: PastebinServiceRawResp): unknown {
const obj: any = {};
return obj;
},
create<I extends Exact<DeepPartial<PastebinServiceRawResp>, I>>(base?: I): PastebinServiceRawResp {
return PastebinServiceRawResp.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<PastebinServiceRawResp>, I>>(_: I): PastebinServiceRawResp {
const message = createBasePastebinServiceRawResp();
return message;
},
};
/**
* @route_group: true
* @base_url: /v1/pastebin
@ -875,6 +1002,13 @@ export interface PastebinService {
* @api: /get
*/
Get(request: PastebinServiceGetReq): Promise<PastebinServiceGetResp>;
/**
* @desc:
* @author: Young Xu
* @method: GET
* @api: /raw
*/
Raw(request: PastebinServiceRawReq): Promise<PastebinServiceRawResp>;
}
export const PastebinServiceServiceName = "api_services.v1.PastebinService";
@ -888,6 +1022,7 @@ export class PastebinServiceClientImpl implements PastebinService {
this.Add = this.Add.bind(this);
this.Update = this.Update.bind(this);
this.Get = this.Get.bind(this);
this.Raw = this.Raw.bind(this);
}
List(request: PastebinServiceListReq): Promise<PastebinServiceListResp> {
const data = PastebinServiceListReq.encode(request).finish();
@ -912,35 +1047,23 @@ export class PastebinServiceClientImpl implements PastebinService {
const promise = this.rpc.request(this.service, "Get", data);
return promise.then((data) => PastebinServiceGetResp.decode(_m0.Reader.create(data)));
}
Raw(request: PastebinServiceRawReq): Promise<PastebinServiceRawResp> {
const data = PastebinServiceRawReq.encode(request).finish();
const promise = this.rpc.request(this.service, "Raw", data);
return promise.then((data) => PastebinServiceRawResp.decode(_m0.Reader.create(data)));
}
}
interface Rpc {
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
}
declare const self: any | undefined;
declare const window: any | undefined;
declare const global: any | undefined;
const tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
@ -949,8 +1072,8 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}

View File

@ -179,17 +179,17 @@ export const ModelPastebin = {
fromJSON(object: any): ModelPastebin {
return {
id: isSet(object.id) ? Number(object.id) : 0,
created_at: isSet(object.createdAt) ? Number(object.createdAt) : 0,
expired_at: isSet(object.expiredAt) ? Number(object.expiredAt) : 0,
short_id: isSet(object.shortId) ? String(object.shortId) : "",
title: isSet(object.title) ? String(object.title) : "",
author: isSet(object.author) ? String(object.author) : "",
content: isSet(object.content) ? String(object.content) : "",
lang: isSet(object.lang) ? String(object.lang) : "",
password: isSet(object.password) ? String(object.password) : "",
need_password: isSet(object.needPassword) ? Boolean(object.needPassword) : false,
editable: isSet(object.editable) ? Boolean(object.editable) : false,
id: isSet(object.id) ? globalThis.Number(object.id) : 0,
created_at: isSet(object.createdAt) ? globalThis.Number(object.createdAt) : 0,
expired_at: isSet(object.expiredAt) ? globalThis.Number(object.expiredAt) : 0,
short_id: isSet(object.shortId) ? globalThis.String(object.shortId) : "",
title: isSet(object.title) ? globalThis.String(object.title) : "",
author: isSet(object.author) ? globalThis.String(object.author) : "",
content: isSet(object.content) ? globalThis.String(object.content) : "",
lang: isSet(object.lang) ? globalThis.String(object.lang) : "",
password: isSet(object.password) ? globalThis.String(object.password) : "",
need_password: isSet(object.needPassword) ? globalThis.Boolean(object.needPassword) : false,
editable: isSet(object.editable) ? globalThis.Boolean(object.editable) : false,
};
},
@ -251,29 +251,11 @@ export const ModelPastebin = {
},
};
declare const self: any | undefined;
declare const window: any | undefined;
declare const global: any | undefined;
const tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
@ -282,8 +264,8 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}

View File

@ -4,6 +4,10 @@ import {useRouter} from "vue-router";
const router = useRouter()
let doc_id = ref(router.currentRoute.value.params.id);
import {usePageStore} from "@stores/counter";
const pager = usePageStore()
pager.change('doc')
import {get} from "@request/api";
import {PastebinServiceGetResp, PastebinServiceRecord} from "@gen/api_services/v1/pastebin_module.ts";
import {onMounted, reactive, ref} from "vue";
@ -28,6 +32,10 @@ async function document() {
doc.instance = response.data.record as PastebinServiceRecord
}
function getDocumentLink(key:string) {
return "/v1/pastebin/raw?key="+key
}
onMounted(async () => {
await document()
})
@ -70,7 +78,7 @@ onMounted(async () => {
<div class="divider"></div>
<div class="join grid grid-cols-2 content-center place-items-center mt-8">
<button class="join-item btn btn-neutral self-auto">查看原文</button>
<a :href="getDocumentLink(doc.instance.key)" class="join-item btn btn-neutral self-auto">查看原文</a>
<button class="join-item btn btn-neutral self-auto" v-if="doc.instance.editable">编辑原文</button>
<button class="join-item btn btn-neutral self-auto" v-else disabled>编辑原文</button>
</div>