From a01311eec6937138aea463179a63f3035b5bc768 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 26 May 2021 13:12:50 +0100 Subject: [PATCH] More file fixes, example (#127) --- file/examples.json | 29 +++++++++++++++++++++++++++++ file/handler/files.go | 6 +++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 file/examples.json diff --git a/file/examples.json b/file/examples.json new file mode 100644 index 0000000..2ba6f9a --- /dev/null +++ b/file/examples.json @@ -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" + } + ] + } + }] +} \ No newline at end of file diff --git a/file/handler/files.go b/file/handler/files.go index e428128..3d91c60 100644 --- a/file/handler/files.go +++ b/file/handler/files.go @@ -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