We no longer manage favorites via arbitrary metadata

This commit is contained in:
André Duffeck
2026-03-11 10:18:48 +01:00
parent bfba4ec671
commit cd0831aa10
2 changed files with 40 additions and 4 deletions

View File

@@ -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)
}
}

View File

@@ -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))
})
})
})