添加文件分块上传的接口
This commit is contained in:
parent
a66990f564
commit
9edcfb8a3d
@ -789,6 +789,242 @@ func (x *SearchResp) GetItems() []*SearchResp_Nested {
|
||||
return nil
|
||||
}
|
||||
|
||||
type TusCreateReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
|
||||
UserSpacePath string `protobuf:"bytes,2,opt,name=userSpacePath,proto3" json:"userSpacePath,omitempty"`
|
||||
Override bool `protobuf:"varint,3,opt,name=override,proto3" json:"override,omitempty"`
|
||||
}
|
||||
|
||||
func (x *TusCreateReq) Reset() {
|
||||
*x = TusCreateReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_files_proto_msgTypes[12]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TusCreateReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TusCreateReq) ProtoMessage() {}
|
||||
|
||||
func (x *TusCreateReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_files_proto_msgTypes[12]
|
||||
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 TusCreateReq.ProtoReflect.Descriptor instead.
|
||||
func (*TusCreateReq) Descriptor() ([]byte, []int) {
|
||||
return file_files_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *TusCreateReq) GetPath() string {
|
||||
if x != nil {
|
||||
return x.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *TusCreateReq) GetUserSpacePath() string {
|
||||
if x != nil {
|
||||
return x.UserSpacePath
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *TusCreateReq) GetOverride() bool {
|
||||
if x != nil {
|
||||
return x.Override
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type TusCreateResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UploadLength int64 `protobuf:"varint,1,opt,name=uploadLength,proto3" json:"uploadLength,omitempty"`
|
||||
UploadOffset int64 `protobuf:"varint,2,opt,name=uploadOffset,proto3" json:"uploadOffset,omitempty"`
|
||||
}
|
||||
|
||||
func (x *TusCreateResp) Reset() {
|
||||
*x = TusCreateResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_files_proto_msgTypes[13]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TusCreateResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TusCreateResp) ProtoMessage() {}
|
||||
|
||||
func (x *TusCreateResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_files_proto_msgTypes[13]
|
||||
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 TusCreateResp.ProtoReflect.Descriptor instead.
|
||||
func (*TusCreateResp) Descriptor() ([]byte, []int) {
|
||||
return file_files_proto_rawDescGZIP(), []int{13}
|
||||
}
|
||||
|
||||
func (x *TusCreateResp) GetUploadLength() int64 {
|
||||
if x != nil {
|
||||
return x.UploadLength
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *TusCreateResp) GetUploadOffset() int64 {
|
||||
if x != nil {
|
||||
return x.UploadOffset
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type TusUploadReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
|
||||
UserSpacePath string `protobuf:"bytes,2,opt,name=userSpacePath,proto3" json:"userSpacePath,omitempty"`
|
||||
UploadOffset int64 `protobuf:"varint,3,opt,name=uploadOffset,proto3" json:"uploadOffset,omitempty"`
|
||||
Content []byte `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) Reset() {
|
||||
*x = TusUploadReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_files_proto_msgTypes[14]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TusUploadReq) ProtoMessage() {}
|
||||
|
||||
func (x *TusUploadReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_files_proto_msgTypes[14]
|
||||
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 TusUploadReq.ProtoReflect.Descriptor instead.
|
||||
func (*TusUploadReq) Descriptor() ([]byte, []int) {
|
||||
return file_files_proto_rawDescGZIP(), []int{14}
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) GetPath() string {
|
||||
if x != nil {
|
||||
return x.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) GetUserSpacePath() string {
|
||||
if x != nil {
|
||||
return x.UserSpacePath
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) GetUploadOffset() int64 {
|
||||
if x != nil {
|
||||
return x.UploadOffset
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *TusUploadReq) GetContent() []byte {
|
||||
if x != nil {
|
||||
return x.Content
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type TusUploadResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UploadOffset int64 `protobuf:"varint,1,opt,name=uploadOffset,proto3" json:"uploadOffset,omitempty"`
|
||||
}
|
||||
|
||||
func (x *TusUploadResp) Reset() {
|
||||
*x = TusUploadResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_files_proto_msgTypes[15]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *TusUploadResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TusUploadResp) ProtoMessage() {}
|
||||
|
||||
func (x *TusUploadResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_files_proto_msgTypes[15]
|
||||
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 TusUploadResp.ProtoReflect.Descriptor instead.
|
||||
func (*TusUploadResp) Descriptor() ([]byte, []int) {
|
||||
return file_files_proto_rawDescGZIP(), []int{15}
|
||||
}
|
||||
|
||||
func (x *TusUploadResp) GetUploadOffset() int64 {
|
||||
if x != nil {
|
||||
return x.UploadOffset
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type SearchResp_Nested struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -801,7 +1037,7 @@ type SearchResp_Nested struct {
|
||||
func (x *SearchResp_Nested) Reset() {
|
||||
*x = SearchResp_Nested{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_files_proto_msgTypes[12]
|
||||
mi := &file_files_proto_msgTypes[16]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@ -814,7 +1050,7 @@ func (x *SearchResp_Nested) String() string {
|
||||
func (*SearchResp_Nested) ProtoMessage() {}
|
||||
|
||||
func (x *SearchResp_Nested) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_files_proto_msgTypes[12]
|
||||
mi := &file_files_proto_msgTypes[16]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@ -924,24 +1160,55 @@ var file_files_proto_rawDesc = []byte{
|
||||
0x73, 0x74, 0x65, 0x64, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x1a, 0x2e, 0x0a, 0x06, 0x4e,
|
||||
0x65, 0x73, 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x64, 0x69, 0x72, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x08, 0x52, 0x03, 0x64, 0x69, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x32, 0xfd, 0x01, 0x0a, 0x04,
|
||||
0x46, 0x69, 0x6c, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x2e, 0x66,
|
||||
0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71,
|
||||
0x1a, 0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||
0x65, 0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61,
|
||||
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65,
|
||||
0x74, 0x65, 0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c,
|
||||
0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x55, 0x70, 0x6c,
|
||||
0x6f, 0x61, 0x64, 0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x6c, 0x6f,
|
||||
0x61, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x55, 0x70,
|
||||
0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x53, 0x65,
|
||||
0x61, 0x72, 0x63, 0x68, 0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61,
|
||||
0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x73,
|
||||
0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e,
|
||||
0x2f, 0x3b, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0x64, 0x0a, 0x0c, 0x54,
|
||||
0x75, 0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x70,
|
||||
0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12,
|
||||
0x24, 0x0a, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x74, 0x68,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63,
|
||||
0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64,
|
||||
0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64,
|
||||
0x65, 0x22, 0x57, 0x0a, 0x0d, 0x54, 0x75, 0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65,
|
||||
0x73, 0x70, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4c, 0x65, 0x6e, 0x67,
|
||||
0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x75, 0x70,
|
||||
0x6c, 0x6f, 0x61, 0x64, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x22, 0x86, 0x01, 0x0a, 0x0c, 0x54,
|
||||
0x75, 0x73, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x70,
|
||||
0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12,
|
||||
0x24, 0x0a, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x74, 0x68,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63,
|
||||
0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4f,
|
||||
0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x75, 0x70, 0x6c,
|
||||
0x6f, 0x61, 0x64, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
|
||||
0x74, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x74, 0x22, 0x33, 0x0a, 0x0d, 0x54, 0x75, 0x73, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x4f, 0x66,
|
||||
0x66, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x75, 0x70, 0x6c, 0x6f,
|
||||
0x61, 0x64, 0x4f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x32, 0xf1, 0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c,
|
||||
0x65, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65,
|
||||
0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x13, 0x2e,
|
||||
0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
|
||||
0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x10,
|
||||
0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71,
|
||||
0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52,
|
||||
0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12,
|
||||
0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65,
|
||||
0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
|
||||
0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68,
|
||||
0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52,
|
||||
0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61, 0x72, 0x63,
|
||||
0x68, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61,
|
||||
0x64, 0x12, 0x10, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64,
|
||||
0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x6c, 0x6f,
|
||||
0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x09, 0x54, 0x75, 0x73, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x54, 0x75,
|
||||
0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x73, 0x2e, 0x54, 0x75, 0x73, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70,
|
||||
0x22, 0x00, 0x12, 0x38, 0x0a, 0x09, 0x54, 0x75, 0x73, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12,
|
||||
0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x54, 0x75, 0x73, 0x55, 0x70, 0x6c, 0x6f, 0x61,
|
||||
0x64, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x54, 0x75, 0x73,
|
||||
0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08,
|
||||
0x2e, 0x2f, 0x3b, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -956,7 +1223,7 @@ func file_files_proto_rawDescGZIP() []byte {
|
||||
return file_files_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_files_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
|
||||
var file_files_proto_msgTypes = make([]protoimpl.MessageInfo, 17)
|
||||
var file_files_proto_goTypes = []interface{}{
|
||||
(*FileListReq)(nil), // 0: files.FileListReq
|
||||
(*Items)(nil), // 1: files.Items
|
||||
@ -970,25 +1237,33 @@ var file_files_proto_goTypes = []interface{}{
|
||||
(*UploadResp)(nil), // 9: files.UploadResp
|
||||
(*SearchReq)(nil), // 10: files.searchReq
|
||||
(*SearchResp)(nil), // 11: files.searchResp
|
||||
(*SearchResp_Nested)(nil), // 12: files.searchResp.Nested
|
||||
(*TusCreateReq)(nil), // 12: files.TusCreateReq
|
||||
(*TusCreateResp)(nil), // 13: files.TusCreateResp
|
||||
(*TusUploadReq)(nil), // 14: files.TusUploadReq
|
||||
(*TusUploadResp)(nil), // 15: files.TusUploadResp
|
||||
(*SearchResp_Nested)(nil), // 16: files.searchResp.Nested
|
||||
}
|
||||
var file_files_proto_depIdxs = []int32{
|
||||
2, // 0: files.FileListReq.sorting:type_name -> files.Sorting
|
||||
1, // 1: files.FileListResp.items:type_name -> files.Items
|
||||
2, // 2: files.FileListResp.sorting:type_name -> files.Sorting
|
||||
12, // 3: files.searchResp.items:type_name -> files.searchResp.Nested
|
||||
16, // 3: files.searchResp.items:type_name -> files.searchResp.Nested
|
||||
0, // 4: files.File.List:input_type -> files.FileListReq
|
||||
4, // 5: files.File.Create:input_type -> files.CreateReq
|
||||
6, // 6: files.File.Delete:input_type -> files.DeleteReq
|
||||
8, // 7: files.File.Upload:input_type -> files.UploadReq
|
||||
10, // 8: files.File.Search:input_type -> files.searchReq
|
||||
3, // 9: files.File.List:output_type -> files.FileListResp
|
||||
5, // 10: files.File.Create:output_type -> files.CreateResp
|
||||
7, // 11: files.File.Delete:output_type -> files.DeleteResp
|
||||
9, // 12: files.File.Upload:output_type -> files.UploadResp
|
||||
11, // 13: files.File.Search:output_type -> files.searchResp
|
||||
9, // [9:14] is the sub-list for method output_type
|
||||
4, // [4:9] is the sub-list for method input_type
|
||||
10, // 7: files.File.Search:input_type -> files.searchReq
|
||||
8, // 8: files.File.Upload:input_type -> files.UploadReq
|
||||
12, // 9: files.File.TusCreate:input_type -> files.TusCreateReq
|
||||
14, // 10: files.File.TusUpload:input_type -> files.TusUploadReq
|
||||
3, // 11: files.File.List:output_type -> files.FileListResp
|
||||
5, // 12: files.File.Create:output_type -> files.CreateResp
|
||||
7, // 13: files.File.Delete:output_type -> files.DeleteResp
|
||||
11, // 14: files.File.Search:output_type -> files.searchResp
|
||||
9, // 15: files.File.Upload:output_type -> files.UploadResp
|
||||
13, // 16: files.File.TusCreate:output_type -> files.TusCreateResp
|
||||
15, // 17: files.File.TusUpload:output_type -> files.TusUploadResp
|
||||
11, // [11:18] is the sub-list for method output_type
|
||||
4, // [4:11] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
@ -1145,6 +1420,54 @@ func file_files_proto_init() {
|
||||
}
|
||||
}
|
||||
file_files_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TusCreateReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_files_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TusCreateResp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_files_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TusUploadReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_files_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*TusUploadResp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_files_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SearchResp_Nested); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1163,7 +1486,7 @@ func file_files_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_files_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 13,
|
||||
NumMessages: 17,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
@ -8,8 +8,10 @@ service File{
|
||||
rpc List(FileListReq) returns (FileListResp) {} // 获取当前路径下的文件列表
|
||||
rpc Create(CreateReq) returns (CreateResp) {} // 创建文件夹
|
||||
rpc Delete(DeleteReq) returns (DeleteResp) {} // 删除文件或文件夹
|
||||
rpc Upload(UploadReq) returns (UploadResp) {} // 上传文件
|
||||
rpc Search(searchReq) returns (searchResp) {} // 搜索
|
||||
rpc Upload(UploadReq) returns (UploadResp) {} // 文件上传
|
||||
rpc TusCreate(TusCreateReq) returns(TusCreateResp) {} // 分块文件上传:创建文件
|
||||
rpc TusUpload(TusUploadReq) returns(TusUploadResp) {} // 分块文件上传:上传文件块
|
||||
}
|
||||
|
||||
message FileListReq{
|
||||
@ -96,4 +98,27 @@ message searchResp{
|
||||
}
|
||||
|
||||
repeated Nested items = 1;
|
||||
}
|
||||
|
||||
|
||||
message TusCreateReq{
|
||||
string path = 1;
|
||||
string userSpacePath = 2;
|
||||
bool override =3 ;
|
||||
}
|
||||
|
||||
message TusCreateResp{
|
||||
int64 uploadLength = 1;
|
||||
int64 uploadOffset = 2;
|
||||
}
|
||||
|
||||
message TusUploadReq{
|
||||
string path = 1;
|
||||
string userSpacePath = 2;
|
||||
int64 uploadOffset = 3;
|
||||
bytes content = 4;
|
||||
}
|
||||
|
||||
message TusUploadResp{
|
||||
int64 uploadOffset = 1;
|
||||
}
|
@ -78,3 +78,15 @@ func (this *SearchResp) Validate() error {
|
||||
func (this *SearchResp_Nested) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *TusCreateReq) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *TusCreateResp) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *TusUploadReq) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *TusUploadResp) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
@ -31,8 +31,10 @@ type FileClient interface {
|
||||
List(ctx context.Context, in *FileListReq, opts ...grpc_go.CallOption) (*FileListResp, common.ErrorWithAttachment)
|
||||
Create(ctx context.Context, in *CreateReq, opts ...grpc_go.CallOption) (*CreateResp, common.ErrorWithAttachment)
|
||||
Delete(ctx context.Context, in *DeleteReq, opts ...grpc_go.CallOption) (*DeleteResp, common.ErrorWithAttachment)
|
||||
Upload(ctx context.Context, in *UploadReq, opts ...grpc_go.CallOption) (*UploadResp, common.ErrorWithAttachment)
|
||||
Search(ctx context.Context, in *SearchReq, opts ...grpc_go.CallOption) (*SearchResp, common.ErrorWithAttachment)
|
||||
Upload(ctx context.Context, in *UploadReq, opts ...grpc_go.CallOption) (*UploadResp, common.ErrorWithAttachment)
|
||||
TusCreate(ctx context.Context, in *TusCreateReq, opts ...grpc_go.CallOption) (*TusCreateResp, common.ErrorWithAttachment)
|
||||
TusUpload(ctx context.Context, in *TusUploadReq, opts ...grpc_go.CallOption) (*TusUploadResp, common.ErrorWithAttachment)
|
||||
}
|
||||
|
||||
type fileClient struct {
|
||||
@ -40,11 +42,13 @@ type fileClient struct {
|
||||
}
|
||||
|
||||
type FileClientImpl struct {
|
||||
List func(ctx context.Context, in *FileListReq) (*FileListResp, error)
|
||||
Create func(ctx context.Context, in *CreateReq) (*CreateResp, error)
|
||||
Delete func(ctx context.Context, in *DeleteReq) (*DeleteResp, error)
|
||||
Upload func(ctx context.Context, in *UploadReq) (*UploadResp, error)
|
||||
Search func(ctx context.Context, in *SearchReq) (*SearchResp, error)
|
||||
List func(ctx context.Context, in *FileListReq) (*FileListResp, error)
|
||||
Create func(ctx context.Context, in *CreateReq) (*CreateResp, error)
|
||||
Delete func(ctx context.Context, in *DeleteReq) (*DeleteResp, error)
|
||||
Search func(ctx context.Context, in *SearchReq) (*SearchResp, error)
|
||||
Upload func(ctx context.Context, in *UploadReq) (*UploadResp, error)
|
||||
TusCreate func(ctx context.Context, in *TusCreateReq) (*TusCreateResp, error)
|
||||
TusUpload func(ctx context.Context, in *TusUploadReq) (*TusUploadResp, error)
|
||||
}
|
||||
|
||||
func (c *FileClientImpl) GetDubboStub(cc *triple.TripleConn) FileClient {
|
||||
@ -77,16 +81,28 @@ func (c *fileClient) Delete(ctx context.Context, in *DeleteReq, opts ...grpc_go.
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Delete", in, out)
|
||||
}
|
||||
|
||||
func (c *fileClient) Search(ctx context.Context, in *SearchReq, opts ...grpc_go.CallOption) (*SearchResp, common.ErrorWithAttachment) {
|
||||
out := new(SearchResp)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Search", in, out)
|
||||
}
|
||||
|
||||
func (c *fileClient) Upload(ctx context.Context, in *UploadReq, opts ...grpc_go.CallOption) (*UploadResp, common.ErrorWithAttachment) {
|
||||
out := new(UploadResp)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Upload", in, out)
|
||||
}
|
||||
|
||||
func (c *fileClient) Search(ctx context.Context, in *SearchReq, opts ...grpc_go.CallOption) (*SearchResp, common.ErrorWithAttachment) {
|
||||
out := new(SearchResp)
|
||||
func (c *fileClient) TusCreate(ctx context.Context, in *TusCreateReq, opts ...grpc_go.CallOption) (*TusCreateResp, common.ErrorWithAttachment) {
|
||||
out := new(TusCreateResp)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Search", in, out)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/TusCreate", in, out)
|
||||
}
|
||||
|
||||
func (c *fileClient) TusUpload(ctx context.Context, in *TusUploadReq, opts ...grpc_go.CallOption) (*TusUploadResp, common.ErrorWithAttachment) {
|
||||
out := new(TusUploadResp)
|
||||
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
|
||||
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/TusUpload", in, out)
|
||||
}
|
||||
|
||||
// FileServer is the server API for File service.
|
||||
@ -96,8 +112,10 @@ type FileServer interface {
|
||||
List(context.Context, *FileListReq) (*FileListResp, error)
|
||||
Create(context.Context, *CreateReq) (*CreateResp, error)
|
||||
Delete(context.Context, *DeleteReq) (*DeleteResp, error)
|
||||
Upload(context.Context, *UploadReq) (*UploadResp, error)
|
||||
Search(context.Context, *SearchReq) (*SearchResp, error)
|
||||
Upload(context.Context, *UploadReq) (*UploadResp, error)
|
||||
TusCreate(context.Context, *TusCreateReq) (*TusCreateResp, error)
|
||||
TusUpload(context.Context, *TusUploadReq) (*TusUploadResp, error)
|
||||
mustEmbedUnimplementedFileServer()
|
||||
}
|
||||
|
||||
@ -115,11 +133,17 @@ func (UnimplementedFileServer) Create(context.Context, *CreateReq) (*CreateResp,
|
||||
func (UnimplementedFileServer) Delete(context.Context, *DeleteReq) (*DeleteResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
|
||||
}
|
||||
func (UnimplementedFileServer) Search(context.Context, *SearchReq) (*SearchResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
|
||||
}
|
||||
func (UnimplementedFileServer) Upload(context.Context, *UploadReq) (*UploadResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Upload not implemented")
|
||||
}
|
||||
func (UnimplementedFileServer) Search(context.Context, *SearchReq) (*SearchResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
|
||||
func (UnimplementedFileServer) TusCreate(context.Context, *TusCreateReq) (*TusCreateResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method TusCreate not implemented")
|
||||
}
|
||||
func (UnimplementedFileServer) TusUpload(context.Context, *TusUploadReq) (*TusUploadResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method TusUpload not implemented")
|
||||
}
|
||||
func (s *UnimplementedFileServer) XXX_SetProxyImpl(impl protocol.Invoker) {
|
||||
s.proxyImpl = impl
|
||||
@ -236,6 +260,35 @@ func _File_Delete_Handler(srv interface{}, ctx context.Context, dec func(interfa
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _File_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("Search", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _File_Upload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UploadReq)
|
||||
if err := dec(in); err != nil {
|
||||
@ -265,8 +318,8 @@ func _File_Upload_Handler(srv interface{}, ctx context.Context, dec func(interfa
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _File_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchReq)
|
||||
func _File_TusCreate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(TusCreateReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -278,7 +331,36 @@ func _File_Search_Handler(srv interface{}, ctx context.Context, dec func(interfa
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("Search", args, invAttachment)
|
||||
invo := invocation.NewRPCInvocation("TusCreate", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
info := &grpc_go.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _File_TusUpload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(TusUploadReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := srv.(dubbo3.Dubbo3GrpcService)
|
||||
args := []interface{}{}
|
||||
args = append(args, in)
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
invAttachment := make(map[string]interface{}, len(md))
|
||||
for k, v := range md {
|
||||
invAttachment[k] = v
|
||||
}
|
||||
invo := invocation.NewRPCInvocation("TusUpload", args, invAttachment)
|
||||
if interceptor == nil {
|
||||
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
|
||||
return result, result.Error()
|
||||
@ -313,13 +395,21 @@ var File_ServiceDesc = grpc_go.ServiceDesc{
|
||||
MethodName: "Delete",
|
||||
Handler: _File_Delete_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Search",
|
||||
Handler: _File_Search_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Upload",
|
||||
Handler: _File_Upload_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Search",
|
||||
Handler: _File_Search_Handler,
|
||||
MethodName: "TusCreate",
|
||||
Handler: _File_TusCreate_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "TusUpload",
|
||||
Handler: _File_TusUpload_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc_go.StreamDesc{},
|
||||
|
100
service/files.go
100
service/files.go
@ -1,8 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -87,11 +90,11 @@ func (f *FilesProvider) Upload(ctx context.Context, req *filesApi.UploadReq) (*f
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer fi.Close()
|
||||
_, err = fi.Write(req.Content)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fi.Close()
|
||||
return new(filesApi.UploadResp), nil
|
||||
}
|
||||
|
||||
@ -110,7 +113,100 @@ func (f *FilesProvider) Search(ctx context.Context, req *filesApi.SearchReq) (*f
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (f *FilesProvider) TusCreate(ctx context.Context, req *filesApi.TusCreateReq) (*filesApi.TusCreateResp, error) {
|
||||
fs := getFs(req.UserSpacePath)
|
||||
file, err := files.NewFileInfo(&files.FileOptions{
|
||||
Fs: fs,
|
||||
Path: req.Path,
|
||||
Modify: true,
|
||||
Expand: false,
|
||||
ReadHeader: true,
|
||||
Checker: rules.EmptyChecker,
|
||||
})
|
||||
switch {
|
||||
case errors.Is(err, afero.ErrFileNotFound):
|
||||
dirPath := filepath.Dir(req.Path)
|
||||
if _, statErr := fs.Stat(dirPath); os.IsNotExist(statErr) {
|
||||
if mkdirErr := fs.MkdirAll(dirPath, files.PermDir); mkdirErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
case err != nil:
|
||||
return nil, err
|
||||
}
|
||||
fileFlags := os.O_CREATE | os.O_WRONLY
|
||||
if req.Override {
|
||||
fileFlags |= os.O_TRUNC
|
||||
}
|
||||
|
||||
// if file exists
|
||||
if file != nil {
|
||||
if file.IsDir {
|
||||
return nil, fmt.Errorf("上传路径不能是文件夹 %s", file.RealPath())
|
||||
}
|
||||
}
|
||||
|
||||
openFile, err := fs.OpenFile(req.Path, fileFlags, files.PermFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := openFile.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &filesApi.TusCreateResp{
|
||||
UploadLength: -1,
|
||||
UploadOffset: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *FilesProvider) TusUpload(ctx context.Context, req *filesApi.TusUploadReq) (*filesApi.TusUploadResp, error) {
|
||||
fs := getFs(req.UserSpacePath)
|
||||
file, err := files.NewFileInfo(&files.FileOptions{
|
||||
Fs: fs,
|
||||
Path: req.Path,
|
||||
Modify: true,
|
||||
Expand: false,
|
||||
ReadHeader: true,
|
||||
Checker: rules.EmptyChecker,
|
||||
})
|
||||
switch {
|
||||
case errors.Is(err, afero.ErrFileNotFound):
|
||||
return nil, errors.New("未找到文件")
|
||||
case err != nil:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case file.IsDir:
|
||||
return nil, fmt.Errorf("上传路径不能是文件夹 %s", file.RealPath())
|
||||
case file.Size != req.UploadOffset:
|
||||
return nil, fmt.Errorf(
|
||||
"%s 文件大小符合: %d",
|
||||
file.RealPath(),
|
||||
req.UploadOffset,
|
||||
)
|
||||
}
|
||||
openFile, err := fs.OpenFile(req.Path, os.O_WRONLY|os.O_APPEND, files.PermFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open file: %w", err)
|
||||
}
|
||||
defer openFile.Close()
|
||||
|
||||
_, err = openFile.Seek(req.UploadOffset, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not seek file: %w", err)
|
||||
}
|
||||
|
||||
bytesWritten, err := io.Copy(openFile, bytes.NewBuffer(req.Content))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not write to file: %w", err)
|
||||
}
|
||||
return &filesApi.TusUploadResp{
|
||||
UploadOffset: bytesWritten,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getFs(UserSpacePath string) afero.Fs {
|
||||
|
Loading…
Reference in New Issue
Block a user