mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
More file fixes, example (#127)
This commit is contained in:
29
file/examples.json
Normal file
29
file/examples.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
||||
@@ -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 {
|
||||
// strip the tenant id
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
|
||||
|
||||
// prefix the tenant
|
||||
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
|
||||
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 {
|
||||
// strip the prefixes
|
||||
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
|
||||
// no file listing ever contains it
|
||||
|
||||
Reference in New Issue
Block a user