More file fixes, example (#127)

This commit is contained in:
Janos Dobronszki
2021-05-26 13:12:50 +01:00
committed by GitHub
parent 24ff482bab
commit a01311eec6
2 changed files with 32 additions and 3 deletions

29
file/examples.json Normal file
View File

@@ -0,0 +1,29 @@
{
"save": [{
"title": "Save file",
"request": {
"file": {
"data": "file content example",
"name": "file.txt",
"path": "/document/text-files",
"project": "myproject"
}
},
"response": {
}
}, {
"title": "List files",
"request": {
"project": "myproject"
},
"response": {
"files": [
{
"project": "myproject",
"name": "file.txt",
"path": "/document/text-files"
}
]
}
}]
}

View File

@@ -59,7 +59,7 @@ func (e *File) Read(ctx context.Context, req *file.ReadRequest, rsp *file.ReadRe
if file.Path == req.Path && file.Name == req.Name { if file.Path == req.Path && file.Name == req.Name {
// strip the tenant id // strip the tenant id
file.Project = strings.TrimPrefix(file.Project, tenantId+"/") file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
file.Path = strings.TrimPrefix(file.Path, req.Project) file.Path = strings.TrimPrefix(file.Path, req.Project+"/")
rsp.File = file rsp.File = file
} }
} }
@@ -77,7 +77,7 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
// prefix the tenant // prefix the tenant
req.File.Project = tenantId + "/" + req.File.Project req.File.Project = tenantId + "/" + req.File.Project
req.File.Path = req.File.Project + "/" req.File.Path = req.File.Project + "/" + req.File.Path
// create the file // create the file
err := e.db.Create(req.File) err := e.db.Create(req.File)
@@ -137,7 +137,7 @@ func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListRe
for _, file := range files { for _, file := range files {
// strip the prefixes // strip the prefixes
file.Project = strings.TrimPrefix(file.Project, tenantId+"/") file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
file.Path = strings.TrimPrefix(file.Path, req.Project) file.Path = strings.TrimPrefix(file.Path, req.Project+"/")
// strip the file contents // strip the file contents
// no file listing ever contains it // no file listing ever contains it