feat: add file info and update list response

This commit is contained in:
dukai 2025-05-21 12:22:49 +08:00
parent fc2cf48f65
commit fcb1689bb8
6 changed files with 37 additions and 234 deletions

View File

@ -11,8 +11,6 @@ LDFLAGS := -X 'gosvc.setVersionNumber=$(VERSION)' \
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
BINARY_NAME := robotfs BINARY_NAME := robotfs
BINARY_MAC := $(BINARY_NAME)-darwin
BINARY_LINUX := $(BINARY_NAME)-linux
.PHONY: all .PHONY: all
all: proto build all: proto build
@ -26,15 +24,15 @@ proto:
build: build:
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
@echo "Building for MacOS..." @echo "Building for MacOS..."
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_MAC) ./ GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./
else else
@echo "Building for Linux..." @echo "Building for Linux..."
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_LINUX) ./ GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./
endif endif
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(BINARY_NAME) $(BINARY_MAC) $(BINARY_LINUX) rm -f $(BINARY_NAME)
rm -f pb/*.pb.go rm -f pb/*.pb.go
.PHONY: help .PHONY: help

View File

@ -10,8 +10,12 @@ import (
) )
type Entry struct { type Entry struct {
Name string `json:"name"` Name string `json:"name"`
IsDir bool `json:"is_dir"` IsDir bool `json:"is_dir"`
Size uint64 `json:"size"`
ContentType string `json:"content_type"`
CreateTime int64 `json:"create_time"`
S3Key string `json:"s3key"`
} }
type ListResult struct { type ListResult struct {
@ -79,8 +83,12 @@ func (s *Service) HandleListDirectory(
entries := make([]Entry, len(rawEntries)) entries := make([]Entry, len(rawEntries))
for i, e := range rawEntries { for i, e := range rawEntries {
entries[i] = Entry{ entries[i] = Entry{
Name: e.FullPath.Name(), Name: e.FullPath.Name(),
IsDir: e.IsDir, IsDir: e.IsDir,
Size: e.Size,
ContentType: e.ContentType,
CreateTime: e.CreateTime,
S3Key: e.S3Key,
} }
} }
result.Entries = entries result.Entries = entries

View File

@ -71,7 +71,16 @@ func (s *Service) HandleInfoFile(
req *httpserver.Request, req *httpserver.Request,
resp *httpserver.Response, resp *httpserver.Response,
) *httpserver.Response { ) *httpserver.Response {
return resp.NoContent() path := req.QueryString("path")
newPath := utils.NormalizePath(path)
entry, err := s.FileSystemManager.FindEntry(req.Context(), utils.FullPath(newPath))
if err != nil {
logger.Error("info %s: %v", path, err)
return resp.InternalServerError("info file failed, " + err.Error())
}
return resp.OK(entry).JSON()
} }
func (s *Service) HandleDownloadFile( func (s *Service) HandleDownloadFile(

View File

@ -1,212 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.6
// protoc v5.29.3
// source: pb/metadata.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type FileEntry struct {
state protoimpl.MessageState `protogen:"open.v1"`
FullPath string `protobuf:"bytes,1,opt,name=full_path,json=fullPath,proto3" json:"full_path,omitempty"`
IsDir bool `protobuf:"varint,2,opt,name=is_dir,json=isDir,proto3" json:"is_dir,omitempty"`
Size uint64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"`
CreateTime int64 `protobuf:"varint,4,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
S3Key string `protobuf:"bytes,5,opt,name=s3_key,json=s3Key,proto3" json:"s3_key,omitempty"`
ContentType string `protobuf:"bytes,6,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"`
Etag string `protobuf:"bytes,7,opt,name=etag,proto3" json:"etag,omitempty"`
VersionId string `protobuf:"bytes,8,opt,name=version_id,json=versionId,proto3" json:"version_id,omitempty"`
LastModificationTime int64 `protobuf:"varint,9,opt,name=last_modification_time,json=lastModificationTime,proto3" json:"last_modification_time,omitempty"`
Extended map[string][]byte `protobuf:"bytes,10,rep,name=extended,proto3" json:"extended,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *FileEntry) Reset() {
*x = FileEntry{}
mi := &file_pb_metadata_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *FileEntry) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FileEntry) ProtoMessage() {}
func (x *FileEntry) ProtoReflect() protoreflect.Message {
mi := &file_pb_metadata_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use FileEntry.ProtoReflect.Descriptor instead.
func (*FileEntry) Descriptor() ([]byte, []int) {
return file_pb_metadata_proto_rawDescGZIP(), []int{0}
}
func (x *FileEntry) GetFullPath() string {
if x != nil {
return x.FullPath
}
return ""
}
func (x *FileEntry) GetIsDir() bool {
if x != nil {
return x.IsDir
}
return false
}
func (x *FileEntry) GetSize() uint64 {
if x != nil {
return x.Size
}
return 0
}
func (x *FileEntry) GetCreateTime() int64 {
if x != nil {
return x.CreateTime
}
return 0
}
func (x *FileEntry) GetS3Key() string {
if x != nil {
return x.S3Key
}
return ""
}
func (x *FileEntry) GetContentType() string {
if x != nil {
return x.ContentType
}
return ""
}
func (x *FileEntry) GetEtag() string {
if x != nil {
return x.Etag
}
return ""
}
func (x *FileEntry) GetVersionId() string {
if x != nil {
return x.VersionId
}
return ""
}
func (x *FileEntry) GetLastModificationTime() int64 {
if x != nil {
return x.LastModificationTime
}
return 0
}
func (x *FileEntry) GetExtended() map[string][]byte {
if x != nil {
return x.Extended
}
return nil
}
var File_pb_metadata_proto protoreflect.FileDescriptor
const file_pb_metadata_proto_rawDesc = "" +
"\n" +
"\x11pb/metadata.proto\x12\arobotfs\"\x92\x03\n" +
"\tFileEntry\x12\x1b\n" +
"\tfull_path\x18\x01 \x01(\tR\bfullPath\x12\x15\n" +
"\x06is_dir\x18\x02 \x01(\bR\x05isDir\x12\x12\n" +
"\x04size\x18\x03 \x01(\x04R\x04size\x12\x1f\n" +
"\vcreate_time\x18\x04 \x01(\x03R\n" +
"createTime\x12\x15\n" +
"\x06s3_key\x18\x05 \x01(\tR\x05s3Key\x12!\n" +
"\fcontent_type\x18\x06 \x01(\tR\vcontentType\x12\x12\n" +
"\x04etag\x18\a \x01(\tR\x04etag\x12\x1d\n" +
"\n" +
"version_id\x18\b \x01(\tR\tversionId\x124\n" +
"\x16last_modification_time\x18\t \x01(\x03R\x14lastModificationTime\x12<\n" +
"\bextended\x18\n" +
" \x03(\v2 .robotfs.FileEntry.ExtendedEntryR\bextended\x1a;\n" +
"\rExtendedEntry\x12\x10\n" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
"\x05value\x18\x02 \x01(\fR\x05value:\x028\x01B\fZ\n" +
"robotfs/pbb\x06proto3"
var (
file_pb_metadata_proto_rawDescOnce sync.Once
file_pb_metadata_proto_rawDescData []byte
)
func file_pb_metadata_proto_rawDescGZIP() []byte {
file_pb_metadata_proto_rawDescOnce.Do(func() {
file_pb_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_pb_metadata_proto_rawDesc), len(file_pb_metadata_proto_rawDesc)))
})
return file_pb_metadata_proto_rawDescData
}
var file_pb_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_pb_metadata_proto_goTypes = []any{
(*FileEntry)(nil), // 0: robotfs.FileEntry
nil, // 1: robotfs.FileEntry.ExtendedEntry
}
var file_pb_metadata_proto_depIdxs = []int32{
1, // 0: robotfs.FileEntry.extended:type_name -> robotfs.FileEntry.ExtendedEntry
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_pb_metadata_proto_init() }
func file_pb_metadata_proto_init() {
if File_pb_metadata_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_pb_metadata_proto_rawDesc), len(file_pb_metadata_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_pb_metadata_proto_goTypes,
DependencyIndexes: file_pb_metadata_proto_depIdxs,
MessageInfos: file_pb_metadata_proto_msgTypes,
}.Build()
File_pb_metadata_proto = out.File
file_pb_metadata_proto_goTypes = nil
file_pb_metadata_proto_depIdxs = nil
}

View File

@ -83,7 +83,7 @@ func (s *Service) RegisterRouteRules() {
}, },
}, },
{ {
Path: "/info", Path: "/file/info",
Method: http.MethodGet, Method: http.MethodGet,
Handler: s.HandleInfoFile, Handler: s.HandleInfoFile,
QueryRules: []*httpserver.QueryRule{ QueryRules: []*httpserver.QueryRule{

View File

@ -10,16 +10,16 @@ import (
) )
type Entry struct { type Entry struct {
FullPath FullPath FullPath FullPath `json:"fullPath"`
IsDir bool IsDir bool `json:"is_dir"`
Size uint64 Size uint64 `json:"size"`
CreateTime int64 CreateTime int64 `json:"create_time"`
S3Key string S3Key string `json:"s3key"`
ContentType string ContentType string `json:"content_type"`
Etag string Etag string `json:"etag"`
VersionID string VersionID string `json:"versionID"`
LastModificationTime int64 LastModificationTime int64 `json:"modify_time"`
Extended map[string][]byte Extended map[string][]byte `json:"extended"`
} }
func NewDirEntry(fullPath FullPath) *Entry { func NewDirEntry(fullPath FullPath) *Entry {