mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Files fixes, remove id (#126)
This commit is contained in:
@@ -22,7 +22,7 @@ func NewFile() *File {
|
||||
db := model.New(
|
||||
file.Record{},
|
||||
&model.Options{
|
||||
Key: "Id",
|
||||
Key: "Path",
|
||||
Indexes: []model.Index{i},
|
||||
},
|
||||
)
|
||||
@@ -58,8 +58,8 @@ func (e *File) Read(ctx context.Context, req *file.ReadRequest, rsp *file.ReadRe
|
||||
for _, file := range files {
|
||||
if file.Path == req.Path && file.Name == req.Name {
|
||||
// strip the tenant id
|
||||
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
|
||||
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||
file.Path = strings.TrimPrefix(file.Path, req.Project)
|
||||
rsp.File = file
|
||||
}
|
||||
}
|
||||
@@ -76,8 +76,8 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
|
||||
log.Info("Received File.Save request")
|
||||
|
||||
// prefix the tenant
|
||||
req.File.Id = tenantId + "/" + req.File.Id
|
||||
req.File.Project = tenantId + "/" + req.File.Project
|
||||
req.File.Path = req.File.Project + "/"
|
||||
|
||||
// create the file
|
||||
err := e.db.Create(req.File)
|
||||
@@ -97,10 +97,12 @@ func (e *File) BatchSave(ctx context.Context, req *file.BatchSaveRequest, rsp *f
|
||||
log.Info("Received File.BatchSave request")
|
||||
|
||||
for _, reqFile := range req.Files {
|
||||
// prefix the tenant
|
||||
reqFile.Id = tenantId + "/" + reqFile.Id
|
||||
reqFile.Project = tenantId + "/" + reqFile.Project
|
||||
|
||||
// prefix the tenant
|
||||
reqFile.Project = tenantId + "/" + reqFile.Project
|
||||
reqFile.Path = reqFile.Project + "/"
|
||||
|
||||
// create the file
|
||||
err := e.db.Create(reqFile)
|
||||
if err != nil {
|
||||
@@ -111,7 +113,6 @@ func (e *File) BatchSave(ctx context.Context, req *file.BatchSaveRequest, rsp *f
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error {
|
||||
log.Info("Received File.List request")
|
||||
|
||||
@@ -133,10 +134,10 @@ func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListRe
|
||||
// @todo funnily while this is the archetypical
|
||||
// query for the KV store interface, it's not supported by the model
|
||||
// so we do client side filtering here
|
||||
for _, file := range rsp.Files {
|
||||
for _, file := range files {
|
||||
// strip the prefixes
|
||||
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
|
||||
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||
file.Path = strings.TrimPrefix(file.Path, req.Project)
|
||||
|
||||
// strip the file contents
|
||||
// no file listing ever contains it
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.15.6
|
||||
// protoc v3.6.1
|
||||
// source: proto/file.proto
|
||||
|
||||
package file
|
||||
@@ -25,16 +25,14 @@ type Record struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// id of the record
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// A custom project to group files
|
||||
// eg. file-of-mywebsite.com
|
||||
Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"`
|
||||
// Name of folder or file.
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// Path. Default is '/', ie. top level
|
||||
// Path eg. '/documents/text-files'. Default is '/', ie. top level
|
||||
Path string `protobuf:"bytes,4,opt,name=path,proto3" json:"path,omitempty"`
|
||||
// whether its a directory
|
||||
// Is it a directory (true) or a file (false)
|
||||
IsDirectory bool `protobuf:"varint,5,opt,name=is_directory,json=isDirectory,proto3" json:"is_directory,omitempty"`
|
||||
// File contents. Empty for directories.
|
||||
Data string `protobuf:"bytes,6,opt,name=data,proto3" json:"data,omitempty"`
|
||||
@@ -80,13 +78,6 @@ func (*Record) Descriptor() ([]byte, []int) {
|
||||
return file_proto_file_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Record) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Record) GetProject() string {
|
||||
if x != nil {
|
||||
return x.Project
|
||||
@@ -549,9 +540,8 @@ var File_proto_file_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_file_proto_rawDesc = []byte{
|
||||
0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x12, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0xd0, 0x02, 0x0a, 0x06, 0x52, 0x65, 0x63,
|
||||
0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02,
|
||||
0x74, 0x6f, 0x12, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0xc0, 0x02, 0x0a, 0x06, 0x52, 0x65, 0x63,
|
||||
0x6f, 0x72, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
|
||||
0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
|
||||
@@ -12,26 +12,24 @@ service File {
|
||||
}
|
||||
|
||||
message Record {
|
||||
// id of the record
|
||||
string id = 1;
|
||||
// A custom project to group files
|
||||
// eg. file-of-mywebsite.com
|
||||
string project = 2;
|
||||
// Name of folder or file.
|
||||
string name = 3;
|
||||
// Path. Default is '/', ie. top level
|
||||
// Path eg. '/documents/text-files'. Default is '/', ie. top level
|
||||
string path = 4;
|
||||
// whether its a directory
|
||||
// Is it a directory (true) or a file (false)
|
||||
bool is_directory = 5;
|
||||
// File contents. Empty for directories.
|
||||
string data = 6;
|
||||
// time the file was created
|
||||
// Time the file was created, number of seconds since Unix epoch
|
||||
int64 created = 7;
|
||||
// time the file was updated
|
||||
// Time the file was updated, number of seconds since Unix epoch
|
||||
int64 updated = 8;
|
||||
// owner of the file e.g alice
|
||||
// Owner of the file e.g alice
|
||||
string owner = 9;
|
||||
// any other associated metadata
|
||||
// Any other associated metadata
|
||||
map<string,string> metadata = 10;
|
||||
}
|
||||
|
||||
@@ -45,11 +43,11 @@ message BatchSaveResponse {
|
||||
|
||||
// Read a file by path
|
||||
message ReadRequest {
|
||||
// project name
|
||||
// Project name
|
||||
string project = 1;
|
||||
// path to the file
|
||||
// Path to the file
|
||||
string path = 2;
|
||||
// file name
|
||||
// File name
|
||||
string name = 3;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user