mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-06 08:33:53 -04:00
We no longer manage favorites via arbitrary metadata
This commit is contained in:
@@ -2,12 +2,11 @@ package content
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
storageProvider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/opencloud-eu/opencloud/pkg/log"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/storage/pkg/decomposedfs/node"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tags"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||
)
|
||||
@@ -34,8 +33,23 @@ func (b Basic) Extract(_ context.Context, ri *storageProvider.ResourceInfo) (Doc
|
||||
if t, ok := m["tags"]; ok {
|
||||
doc.Tags = tags.New(t).AsSlice()
|
||||
}
|
||||
if t, ok := m[node.AllFavoritesKey]; ok && len(t) > 0 {
|
||||
doc.Favorites = strings.Split(t, ",")
|
||||
}
|
||||
|
||||
if m := ri.Opaque.GetMap(); m != nil && m["favorites"] != nil {
|
||||
favEntry := m["favorites"]
|
||||
|
||||
switch favEntry.Decoder {
|
||||
case "json":
|
||||
favorites := []string{}
|
||||
err := json.Unmarshal(favEntry.Value, &favorites)
|
||||
if err != nil {
|
||||
b.logger.Error().Err(err).Msg("failed to unmarshal favorites")
|
||||
break
|
||||
}
|
||||
|
||||
doc.Favorites = favorites
|
||||
default:
|
||||
b.logger.Error().Msgf("unsupported decoder for favorites: %s", favEntry.Decoder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package content_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
storageProvider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
cs3Types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
@@ -86,5 +87,26 @@ var _ = Describe("Basic", func() {
|
||||
Expect(doc.Mtime).To(Equal(data.expect))
|
||||
}
|
||||
})
|
||||
|
||||
It("extracts favorites", func() {
|
||||
favorites := []string{"foo", "bar"}
|
||||
favBytes, _ := json.Marshal(favorites)
|
||||
|
||||
ri := &storageProvider.ResourceInfo{
|
||||
Opaque: &cs3Types.Opaque{
|
||||
Map: map[string]*cs3Types.OpaqueEntry{
|
||||
"favorites": {
|
||||
Decoder: "json",
|
||||
Value: favBytes,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
doc, err := basic.Extract(ctx, ri)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(doc).ToNot(BeNil())
|
||||
Expect(doc.Favorites).To(Equal(favorites))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user