mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-22 07:15:25 +00:00
fix reading
This commit is contained in:
@@ -83,30 +83,29 @@ func (e *File) Read(ctx context.Context, req *file.ReadRequest, rsp *file.ReadRe
|
|||||||
|
|
||||||
path := filepath.Join("file", tenantId, req.Project, req.Path)
|
path := filepath.Join("file", tenantId, req.Project, req.Path)
|
||||||
|
|
||||||
var opts []store.ReadOption
|
records, err := store.Read(path)
|
||||||
|
|
||||||
if strings.HasSuffix(req.Path, "/") {
|
|
||||||
opts = append(opts, store.ReadPrefix())
|
|
||||||
}
|
|
||||||
|
|
||||||
records, err := store.Read(path, opts...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter the file
|
if len(records) == 0 {
|
||||||
for _, rec := range records {
|
return errors.NotFound("file.read", "file not found")
|
||||||
file := new(file.Record)
|
|
||||||
|
|
||||||
if err := rec.Decode(file); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip the tenant id
|
|
||||||
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
|
||||||
file.Path = strings.TrimPrefix(file.Path, filepath.Join(tenantId, req.Project))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filter the file
|
||||||
|
rec := records[0]
|
||||||
|
file := new(file.Record)
|
||||||
|
|
||||||
|
if err := rec.Decode(file); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip the tenant id
|
||||||
|
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
|
||||||
|
file.Path = strings.TrimPrefix(file.Path, filepath.Join(tenantId, req.Project))
|
||||||
|
|
||||||
|
rsp.File = file
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user