添加图片预览接口

This commit is contained in:
lzh 2025-05-26 11:03:37 +08:00
parent 91fce0e24e
commit 6a178f96cc
5 changed files with 329 additions and 51 deletions

View File

@ -1309,6 +1309,116 @@ func (x *FileInfoResp) GetType() string {
return ""
}
type PreviewReq 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"`
Size uint32 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` // 预览大小 0256x256, 1:1080x1080
}
func (x *PreviewReq) Reset() {
*x = PreviewReq{}
if protoimpl.UnsafeEnabled {
mi := &file_files_proto_msgTypes[20]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PreviewReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PreviewReq) ProtoMessage() {}
func (x *PreviewReq) ProtoReflect() protoreflect.Message {
mi := &file_files_proto_msgTypes[20]
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 PreviewReq.ProtoReflect.Descriptor instead.
func (*PreviewReq) Descriptor() ([]byte, []int) {
return file_files_proto_rawDescGZIP(), []int{20}
}
func (x *PreviewReq) GetPath() string {
if x != nil {
return x.Path
}
return ""
}
func (x *PreviewReq) GetUserSpacePath() string {
if x != nil {
return x.UserSpacePath
}
return ""
}
func (x *PreviewReq) GetSize() uint32 {
if x != nil {
return x.Size
}
return 0
}
type PreviewResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Content []byte `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
}
func (x *PreviewResp) Reset() {
*x = PreviewResp{}
if protoimpl.UnsafeEnabled {
mi := &file_files_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PreviewResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PreviewResp) ProtoMessage() {}
func (x *PreviewResp) ProtoReflect() protoreflect.Message {
mi := &file_files_proto_msgTypes[21]
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 PreviewResp.ProtoReflect.Descriptor instead.
func (*PreviewResp) Descriptor() ([]byte, []int) {
return file_files_proto_rawDescGZIP(), []int{21}
}
func (x *PreviewResp) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
type SearchResp_Nested struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1321,7 +1431,7 @@ type SearchResp_Nested struct {
func (x *SearchResp_Nested) Reset() {
*x = SearchResp_Nested{}
if protoimpl.UnsafeEnabled {
mi := &file_files_proto_msgTypes[20]
mi := &file_files_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1334,7 +1444,7 @@ func (x *SearchResp_Nested) String() string {
func (*SearchResp_Nested) ProtoMessage() {}
func (x *SearchResp_Nested) ProtoReflect() protoreflect.Message {
mi := &file_files_proto_msgTypes[20]
mi := &file_files_proto_msgTypes[22]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1498,40 +1608,51 @@ var file_files_proto_rawDesc = []byte{
0x08, 0x52, 0x05, 0x69, 0x73, 0x44, 0x69, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x53, 0x79,
0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x53,
0x79, 0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x09,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x32, 0xf6, 0x03, 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, 0x31, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x12,
0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x65, 0x71, 0x1a, 0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49,
0x6e, 0x66, 0x6f, 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, 0x12, 0x50, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x72,
0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52,
0x65, 0x73, 0x75, 0x6d, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72,
0x52, 0x65, 0x71, 0x1a, 0x1c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x73, 0x75,
0x6d, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 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,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x5a, 0x0a, 0x0a, 0x50, 0x72,
0x65, 0x76, 0x69, 0x65, 0x77, 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, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x22, 0x27, 0x0a, 0x0b, 0x50, 0x72, 0x65, 0x76, 0x69, 0x65,
0x77, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x32,
0xaa, 0x04, 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, 0x31, 0x0a, 0x04, 0x49,
0x6e, 0x66, 0x6f, 0x12, 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x13, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e,
0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 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, 0x12, 0x50, 0x0a, 0x11, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x61,
0x62, 0x6c, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x66, 0x69,
0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x72, 0x61,
0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x1c, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73,
0x2e, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x61, 0x62, 0x6c, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66,
0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x32, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x76,
0x69, 0x65, 0x77, 0x12, 0x11, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x50, 0x72, 0x65, 0x76,
0x69, 0x65, 0x77, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x50,
0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 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 (
@ -1546,7 +1667,7 @@ func file_files_proto_rawDescGZIP() []byte {
return file_files_proto_rawDescData
}
var file_files_proto_msgTypes = make([]protoimpl.MessageInfo, 21)
var file_files_proto_msgTypes = make([]protoimpl.MessageInfo, 23)
var file_files_proto_goTypes = []interface{}{
(*FileListReq)(nil), // 0: files.FileListReq
(*Items)(nil), // 1: files.Items
@ -1568,13 +1689,15 @@ var file_files_proto_goTypes = []interface{}{
(*ResumableTransferResp)(nil), // 17: files.ResumableTransferResp
(*FileInfoReq)(nil), // 18: files.FileInfoReq
(*FileInfoResp)(nil), // 19: files.FileInfoResp
(*SearchResp_Nested)(nil), // 20: files.searchResp.Nested
(*PreviewReq)(nil), // 20: files.PreviewReq
(*PreviewResp)(nil), // 21: files.PreviewResp
(*SearchResp_Nested)(nil), // 22: 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
20, // 3: files.searchResp.items:type_name -> files.searchResp.Nested
22, // 3: files.searchResp.items:type_name -> files.searchResp.Nested
0, // 4: files.File.List:input_type -> files.FileListReq
18, // 5: files.File.Info:input_type -> files.FileInfoReq
4, // 6: files.File.Create:input_type -> files.CreateReq
@ -1584,17 +1707,19 @@ var file_files_proto_depIdxs = []int32{
12, // 10: files.File.TusCreate:input_type -> files.TusCreateReq
14, // 11: files.File.TusUpload:input_type -> files.TusUploadReq
16, // 12: files.File.ResumableTransfer:input_type -> files.ResumableTransferReq
3, // 13: files.File.List:output_type -> files.FileListResp
19, // 14: files.File.Info:output_type -> files.FileInfoResp
5, // 15: files.File.Create:output_type -> files.CreateResp
7, // 16: files.File.Delete:output_type -> files.DeleteResp
11, // 17: files.File.Search:output_type -> files.searchResp
9, // 18: files.File.Upload:output_type -> files.UploadResp
13, // 19: files.File.TusCreate:output_type -> files.TusCreateResp
15, // 20: files.File.TusUpload:output_type -> files.TusUploadResp
17, // 21: files.File.ResumableTransfer:output_type -> files.ResumableTransferResp
13, // [13:22] is the sub-list for method output_type
4, // [4:13] is the sub-list for method input_type
20, // 13: files.File.Preview:input_type -> files.PreviewReq
3, // 14: files.File.List:output_type -> files.FileListResp
19, // 15: files.File.Info:output_type -> files.FileInfoResp
5, // 16: files.File.Create:output_type -> files.CreateResp
7, // 17: files.File.Delete:output_type -> files.DeleteResp
11, // 18: files.File.Search:output_type -> files.searchResp
9, // 19: files.File.Upload:output_type -> files.UploadResp
13, // 20: files.File.TusCreate:output_type -> files.TusCreateResp
15, // 21: files.File.TusUpload:output_type -> files.TusUploadResp
17, // 22: files.File.ResumableTransfer:output_type -> files.ResumableTransferResp
21, // 23: files.File.Preview:output_type -> files.PreviewResp
14, // [14:24] is the sub-list for method output_type
4, // [4:14] 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
@ -1847,6 +1972,30 @@ func file_files_proto_init() {
}
}
file_files_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PreviewReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_files_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PreviewResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_files_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SearchResp_Nested); i {
case 0:
return &v.state
@ -1865,7 +2014,7 @@ func file_files_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_files_proto_rawDesc,
NumEnums: 0,
NumMessages: 21,
NumMessages: 23,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -14,6 +14,7 @@ service File{
rpc TusCreate(TusCreateReq) returns(TusCreateResp) {} //
rpc TusUpload(TusUploadReq) returns(TusUploadResp) {} //
rpc ResumableTransfer(ResumableTransferReq) returns(ResumableTransferResp) {} // grpc实现
rpc Preview(PreviewReq) returns(PreviewResp) {} //
}
message FileListReq{
@ -150,4 +151,14 @@ message FileInfoResp{
bool isDir = 7;
bool isSymlink = 8;
string type = 9;
}
message PreviewReq{
string path = 1;
string userSpacePath = 2;
uint32 size = 3; // 0256x256, 1:1080x1080
}
message PreviewResp{
bytes content = 1;
}

View File

@ -102,3 +102,9 @@ func (this *FileInfoReq) Validate() error {
func (this *FileInfoResp) Validate() error {
return nil
}
func (this *PreviewReq) Validate() error {
return nil
}
func (this *PreviewResp) Validate() error {
return nil
}

View File

@ -37,6 +37,7 @@ type FileClient interface {
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)
ResumableTransfer(ctx context.Context, in *ResumableTransferReq, opts ...grpc_go.CallOption) (*ResumableTransferResp, common.ErrorWithAttachment)
Preview(ctx context.Context, in *PreviewReq, opts ...grpc_go.CallOption) (*PreviewResp, common.ErrorWithAttachment)
}
type fileClient struct {
@ -53,6 +54,7 @@ type FileClientImpl struct {
TusCreate func(ctx context.Context, in *TusCreateReq) (*TusCreateResp, error)
TusUpload func(ctx context.Context, in *TusUploadReq) (*TusUploadResp, error)
ResumableTransfer func(ctx context.Context, in *ResumableTransferReq) (*ResumableTransferResp, error)
Preview func(ctx context.Context, in *PreviewReq) (*PreviewResp, error)
}
func (c *FileClientImpl) GetDubboStub(cc *triple.TripleConn) FileClient {
@ -121,6 +123,12 @@ func (c *fileClient) ResumableTransfer(ctx context.Context, in *ResumableTransfe
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/ResumableTransfer", in, out)
}
func (c *fileClient) Preview(ctx context.Context, in *PreviewReq, opts ...grpc_go.CallOption) (*PreviewResp, common.ErrorWithAttachment) {
out := new(PreviewResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/Preview", in, out)
}
// FileServer is the server API for File service.
// All implementations must embed UnimplementedFileServer
// for forward compatibility
@ -134,6 +142,7 @@ type FileServer interface {
TusCreate(context.Context, *TusCreateReq) (*TusCreateResp, error)
TusUpload(context.Context, *TusUploadReq) (*TusUploadResp, error)
ResumableTransfer(context.Context, *ResumableTransferReq) (*ResumableTransferResp, error)
Preview(context.Context, *PreviewReq) (*PreviewResp, error)
mustEmbedUnimplementedFileServer()
}
@ -169,6 +178,9 @@ func (UnimplementedFileServer) TusUpload(context.Context, *TusUploadReq) (*TusUp
func (UnimplementedFileServer) ResumableTransfer(context.Context, *ResumableTransferReq) (*ResumableTransferResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method ResumableTransfer not implemented")
}
func (UnimplementedFileServer) Preview(context.Context, *PreviewReq) (*PreviewResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Preview not implemented")
}
func (s *UnimplementedFileServer) XXX_SetProxyImpl(impl protocol.Invoker) {
s.proxyImpl = impl
}
@ -458,6 +470,35 @@ func _File_ResumableTransfer_Handler(srv interface{}, ctx context.Context, dec f
return interceptor(ctx, in, info, handler)
}
func _File_Preview_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(PreviewReq)
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("Preview", 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)
}
// File_ServiceDesc is the grpc_go.ServiceDesc for File service.
// It's only intended for direct use with grpc_go.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -501,6 +542,10 @@ var File_ServiceDesc = grpc_go.ServiceDesc{
MethodName: "ResumableTransfer",
Handler: _File_ResumableTransfer_Handler,
},
{
MethodName: "Preview",
Handler: _File_Preview_Handler,
},
},
Streams: []grpc_go.StreamDesc{},
Metadata: "files.proto",

View File

@ -13,6 +13,8 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
filesApi "github.com/filebrowser/filebrowser/v2/api/files"
"github.com/filebrowser/filebrowser/v2/files"
"github.com/filebrowser/filebrowser/v2/http"
"github.com/filebrowser/filebrowser/v2/img"
"github.com/filebrowser/filebrowser/v2/rules"
"github.com/filebrowser/filebrowser/v2/search"
"github.com/spf13/afero"
@ -24,6 +26,8 @@ type FilesProvider struct {
const BASE_PATH = "../"
var imgSvc = img.New(4) // 图片预览可用协程数
func (f *FilesProvider) List(ctx context.Context, req *filesApi.FileListReq) (*filesApi.FileListResp, error) {
file, err := files.NewFileInfo(&files.FileOptions{
Fs: getFs(req.UserSpacePath),
@ -277,6 +281,69 @@ func (f *FilesProvider) ResumableTransfer(ctx context.Context, req *filesApi.Res
}, nil
}
func (f *FilesProvider) Preview(ctx context.Context, req *filesApi.PreviewReq) (*filesApi.PreviewResp, error) {
fs := getFs(req.UserSpacePath)
file, err := files.NewFileInfo(&files.FileOptions{
Fs: fs,
Path: req.Path,
Modify: true,
Expand: true,
ReadHeader: true,
Checker: rules.EmptyChecker,
})
if err != nil {
return nil, err
}
switch file.Type {
case "image":
{
b, err := f.createPreview(imgSvc, file, req.Size)
if err != nil {
return nil, err
}
return &filesApi.PreviewResp{
Content: b,
}, nil
}
default:
return nil, fmt.Errorf("目前只支持image类型的预览")
}
}
func (f *FilesProvider) createPreview(imgSvc http.ImgService,
file *files.FileInfo, previewSize uint32) ([]byte, error) {
fd, err := file.Fs.Open(file.Path)
if err != nil {
return nil, err
}
defer fd.Close()
var (
width int
height int
options []img.Option
)
switch {
case previewSize == 1:
width = 1080
height = 1080
options = append(options, img.WithMode(img.ResizeModeFit), img.WithQuality(img.QualityMedium))
case previewSize == 0:
width = 256
height = 256
options = append(options, img.WithMode(img.ResizeModeFill), img.WithQuality(img.QualityLow), img.WithFormat(img.FormatJpeg))
default:
return nil, img.ErrUnsupportedFormat
}
buf := &bytes.Buffer{}
if err := imgSvc.Resize(context.Background(), fd, width, height, buf, options...); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func getFs(UserSpacePath string) afero.Fs {
bashAbs, _ := filepath.Abs(BASE_PATH)
if !strings.HasPrefix(UserSpacePath, "/") {