fix file timestamps

This commit is contained in:
Asim Aslam
2021-06-03 14:50:39 +01:00
parent b802791518
commit b379f1711e
3 changed files with 24 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/micro/micro/v3/service/errors" "github.com/micro/micro/v3/service/errors"
log "github.com/micro/micro/v3/service/logger" log "github.com/micro/micro/v3/service/logger"
@@ -128,6 +129,13 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
req.File.Project = filepath.Join(tenantId, req.File.Project) req.File.Project = filepath.Join(tenantId, req.File.Project)
req.File.Path = filepath.Join(req.File.Project, req.File.Path) req.File.Path = filepath.Join(req.File.Project, req.File.Path)
if len(req.File.Created) == 0 {
req.File.Created = time.Now().Format(time.RFC3339Nano)
}
// set updated time
req.File.Updated = time.Now().Format(time.RFC3339Nano)
// create the file // create the file
err := e.db.Create(req.File) err := e.db.Create(req.File)
if err != nil { if err != nil {

View File

@@ -30,12 +30,12 @@ type Record struct {
Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"` Project string `protobuf:"bytes,1,opt,name=project,proto3" json:"project,omitempty"`
// Path to file or folder eg. '/documents/text-files/file.txt'. // Path to file or folder eg. '/documents/text-files/file.txt'.
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
// File contents. Empty for directories. // File contents
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
// Time the file was created, number of seconds since Unix epoch // Time the file was created e.g 2021-05-20T13:37:21Z
Created int64 `protobuf:"varint,4,opt,name=created,proto3" json:"created,omitempty"` Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,omitempty"`
// Time the file was updated, number of seconds since Unix epoch // Time the file was updated e.g 2021-05-20T13:37:21Z
Updated int64 `protobuf:"varint,5,opt,name=updated,proto3" json:"updated,omitempty"` Updated string `protobuf:"bytes,5,opt,name=updated,proto3" json:"updated,omitempty"`
// Any other associated metadata // Any other associated metadata
Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
} }
@@ -93,18 +93,18 @@ func (x *Record) GetContent() string {
return "" return ""
} }
func (x *Record) GetCreated() int64 { func (x *Record) GetCreated() string {
if x != nil { if x != nil {
return x.Created return x.Created
} }
return 0 return ""
} }
func (x *Record) GetUpdated() int64 { func (x *Record) GetUpdated() string {
if x != nil { if x != nil {
return x.Updated return x.Updated
} }
return 0 return ""
} }
func (x *Record) GetMetadata() map[string]string { func (x *Record) GetMetadata() map[string]string {
@@ -606,9 +606,9 @@ var file_proto_file_proto_rawDesc = []byte{
0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74,
0x68, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x68, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63,
0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x72,
0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x12,
0x36, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x03, 0x28, 0x36, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x03, 0x28,
0x0b, 0x32, 0x1a, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x0b, 0x32, 0x1a, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e,
0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d,

View File

@@ -17,12 +17,12 @@ message Record {
string project = 1; string project = 1;
// Path to file or folder eg. '/documents/text-files/file.txt'. // Path to file or folder eg. '/documents/text-files/file.txt'.
string path = 2; string path = 2;
// File contents. Empty for directories. // File contents
string content = 3; string content = 3;
// Time the file was created, number of seconds since Unix epoch // Time the file was created e.g 2021-05-20T13:37:21Z
int64 created = 4; string created = 4;
// Time the file was updated, number of seconds since Unix epoch // Time the file was updated e.g 2021-05-20T13:37:21Z
int64 updated = 5; string updated = 5;
// Any other associated metadata // Any other associated metadata
map<string,string> metadata = 6; map<string,string> metadata = 6;
} }