1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 09:35:00 +09:00

GO-5329 Stream spaces with guest keys

This commit is contained in:
Roman Khafizianov 2025-03-20 12:04:47 +01:00
parent f3b9ae4908
commit 826650aae5
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
49 changed files with 5005 additions and 2714 deletions

View file

@ -63,6 +63,9 @@ type widgetParameters struct {
isObjectIDChanged bool
}
//go:embed data/start_guide.zip
var startGuideZip []byte
//go:embed data/get_started.zip
var getStartedZip []byte
@ -77,6 +80,7 @@ var (
archives = map[pb.RpcObjectImportUseCaseRequestUseCase][]byte{
pb.RpcObjectImportUseCaseRequest_GET_STARTED: getStartedZip,
pb.RpcObjectImportUseCaseRequest_GUIDE_ONLY: startGuideZip,
pb.RpcObjectImportUseCaseRequest_EMPTY: emptyZip,
}
)

Binary file not shown.

View file

@ -151,3 +151,30 @@ func GetFileNameFromURLAndContentType(u *url.URL, contentType string) string {
}
return res.String()
}
func ParseInviteUrl(inviteUrl string) (inviteId string, inviteKey string, spaceId string, networkId string, err error) {
// e.g. anytype://invite/?cid=ba&key=AbCd
if inviteUrl == "" {
return "", "", "", "", nil
}
u, err := url.Parse(inviteUrl)
if err != nil {
return "", "", "", "", err
}
if u.Scheme == "anytype" {
inviteId = u.Query().Get("cid")
inviteKey = u.Query().Get("key")
spaceId = u.Query().Get("spaceId")
networkId = u.Query().Get("networkId")
return inviteId, inviteKey, spaceId, networkId, nil
}
if u.Scheme == "" {
return "", "", "", "", fmt.Errorf("invalid invite url: %s", inviteUrl)
}
u.Fragment = strings.TrimPrefix(u.Fragment, "#")
inviteId = u.Path
return inviteId, u.Fragment, "", "", nil
}

View file

@ -230,3 +230,81 @@ func TestGetFileNameFromURLWithContentTypeAndMime(t *testing.T) {
})
}
}
func TestParseInviteUrl(t *testing.T) {
tests := []struct {
name string
inviteUrl string
inviteId string
inviteKey string
spaceId string
networkId string
expectErr bool
}{
{
name: "Empty URL",
inviteUrl: "",
inviteId: "",
inviteKey: "",
spaceId: "",
networkId: "",
},
{
name: "Valid anytype scheme with cid and key",
inviteUrl: "anytype://invite/?cid=123&key=abc",
inviteId: "123",
inviteKey: "abc",
spaceId: "",
networkId: "",
},
{
name: "Valid anytype scheme with all params",
inviteUrl: "anytype://invite/?cid=123&key=abc&spaceId=space1&networkId=net1",
inviteId: "123",
inviteKey: "abc",
spaceId: "space1",
networkId: "net1",
},
{
name: "Invalid URL with no scheme",
inviteUrl: "invite/?cid=123&key=abc",
expectErr: true,
},
{
name: "Malformed URL",
inviteUrl: "::://invalid-url",
expectErr: true,
},
{
name: "Non-anytype scheme with path and fragment",
inviteUrl: "https://example.com/inviteId#inviteKey",
inviteId: "/inviteId",
inviteKey: "inviteKey",
spaceId: "",
networkId: "",
},
{
name: "Non-anytype scheme with path and no fragment",
inviteUrl: "https://example.com/inviteId",
inviteId: "/inviteId",
inviteKey: "",
spaceId: "",
networkId: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inviteId, inviteKey, spaceId, networkId, err := ParseInviteUrl(tt.inviteUrl)
if (err != nil) != tt.expectErr {
t.Errorf("Expected error: %v, got: %v", tt.expectErr, err)
return
}
if inviteId != tt.inviteId || inviteKey != tt.inviteKey || spaceId != tt.spaceId || networkId != tt.networkId {
t.Errorf("Got inviteId=%q, inviteKey=%q, spaceId=%q, networkId=%q; want inviteId=%q, inviteKey=%q, spaceId=%q, networkId=%q",
inviteId, inviteKey, spaceId, networkId,
tt.inviteId, tt.inviteKey, tt.spaceId, tt.networkId)
}
})
}
}