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

resolve conflicts / remove linkPreview command

This commit is contained in:
Sergey Cherepanov 2019-11-06 20:30:41 +03:00
commit 5cda2cd59c
No known key found for this signature in database
GPG key ID: 085319C64294F576
43 changed files with 31527 additions and 24150 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
node_modules
package-lock.json
/jsaddon/build
.vscode

View file

@ -54,10 +54,12 @@ build-android:
mkdir -p dist/android/ && mv mobile.aar mobile/dist/android/
setup-protoc:
rm -rf $(GOPATH)/src/github.com/gogo/protobuf
rm -rf $(GOPATH)/src/github.com/gogo
mkdir -p $(GOPATH)/src/github.com/gogo
cd $(GOPATH)/src/github.com/gogo; git clone https://github.com/anytypeio/protobuf
cd $(GOPATH)/src/github.com/gogo/protobuf; go install github.com/gogo/protobuf/protoc-gen-gogofaster
cd $(GOPATH)/src/github.com/gogo/protobuf; go install github.com/gogo/protobuf/protoc-gen-gogofast
cd $(GOPATH); go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
export PATH=$(PATH):$(GOROOT)/bin:$(GOPATH)/bin
# protos: # libprotoc 3.9.1
@ -66,5 +68,6 @@ setup-protoc:
protos:
$(eval P_STRUCT := Mgoogle/protobuf/struct.proto=github.com/golang/protobuf/ptypes/struct)
cd pb/protos; protoc --gogofaster_out=$(P_STRUCT):.. *.proto
cd pb/protos/service; PACKAGE_PATH=github.com/anytypeio/go-anytype-middleware/pb protoc -I=.. -I=. --gogofast_out=plugins=gomobile:../../../lib service.proto
cd pb/protos; GOGO_NO_UNDERSCORE=1 protoc --gogofaster_out=$(P_STRUCT):.. *.proto
cd pb/protos/service; GOGO_NO_UNDERSCORE=1 PACKAGE_PATH=github.com/anytypeio/go-anytype-middleware/pb protoc -I=.. -I=. --gogofaster_out=plugins=gomobile:../../../lib service.proto
cd pb/protos; GOGO_NO_UNDERSCORE=1 protoc --doc_out=../../docs --doc_opt=markdown,proto.md service/*.proto *.proto

View file

@ -11,11 +11,11 @@ import (
"github.com/anytypeio/go-anytype-middleware/pb"
)
var avatarSizes = []pb.ImageSize{pb.ImageSize_SMALL, pb.ImageSize_LARGE}
var avatarSizes = []pb.ModelImageSize{pb.ModelImage_SMALL, pb.ModelImage_LARGE}
func (mw *Middleware) AccountCreate(req *pb.AccountCreateRequest) *pb.AccountCreateResponse {
response := func(account *pb.Account, code pb.AccountCreateResponse_Error_Code, err error) *pb.AccountCreateResponse {
m := &pb.AccountCreateResponse{Account: account, Error: &pb.AccountCreateResponse_Error{Code: code}}
func (mw *Middleware) AccountCreate(req *pb.RpcAccountCreateRequest) *pb.RpcAccountCreateResponse {
response := func(account *pb.ModelAccount, code pb.RpcAccountCreateResponseErrorCode, err error) *pb.RpcAccountCreateResponse {
m := &pb.RpcAccountCreateResponse{Account: account, Error: &pb.RpcAccountCreateResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -30,61 +30,61 @@ func (mw *Middleware) AccountCreate(req *pb.AccountCreateRequest) *pb.AccountCre
account, err := core.WalletAccountAt(mw.mnemonic, len(mw.localAccounts), "")
if err != nil {
return response(nil, pb.AccountCreateResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcAccountCreateResponseError_UNKNOWN_ERROR, err)
}
err = core.WalletInitRepo(mw.rootPath, account.Seed())
if err != nil {
return response(nil, pb.AccountCreateResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcAccountCreateResponseError_UNKNOWN_ERROR, err)
}
anytype, err := core.New(mw.rootPath, account.Address())
if err != nil {
return response(nil, pb.AccountCreateResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcAccountCreateResponseError_UNKNOWN_ERROR, err)
}
mw.Anytype = anytype
newAcc := &pb.Account{Id: account.Address()}
newAcc := &pb.ModelAccount{Id: account.Address()}
err = mw.Run()
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE, err)
}
err = mw.AccountSetName(req.Name)
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME, err)
}
newAcc.Name, err = mw.Textile.Name()
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME, err)
}
if req.GetAvatarLocalPath() != "" {
_, err := mw.AccountSetAvatar(req.GetAvatarLocalPath())
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
}
hash, err := mw.Textile.Avatar()
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
}
newAcc.Avatar = &pb.Avatar{Avatar: &pb.Avatar_Image{Image: &pb.Image{hash, avatarSizes}}}
newAcc.Avatar = &pb.ModelAccountAvatar{Avatar: &pb.ModelAccountAvatarAvatarOfImage{Image: &pb.ModelImage{hash, avatarSizes}}}
} else if req.GetAvatarColor() != "" {
err := mw.AccountSetAvatarColor(req.GetAvatarColor())
if err != nil {
return response(newAcc, pb.AccountCreateResponse_Error_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
return response(newAcc, pb.RpcAccountCreateResponseError_ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR, err)
}
}
mw.localAccounts = append(mw.localAccounts, newAcc)
return response(newAcc, pb.AccountCreateResponse_Error_NULL, nil)
return response(newAcc, pb.RpcAccountCreateResponseError_NULL, nil)
}
func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRecoverResponse {
response := func(code pb.AccountRecoverResponse_Error_Code, err error) *pb.AccountRecoverResponse {
m := &pb.AccountRecoverResponse{Error: &pb.AccountRecoverResponse_Error{Code: code}}
func (mw *Middleware) AccountRecover(_ *pb.RpcAccountRecoverRequest) *pb.RpcAccountRecoverResponse {
response := func(code pb.RpcAccountRecoverResponseErrorCode, err error) *pb.RpcAccountRecoverResponse {
m := &pb.RpcAccountRecoverResponse{Error: &pb.RpcAccountRecoverResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -92,15 +92,15 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
return m
}
sendAccountAddEvent := func(index int, account *pb.Account) {
m := &pb.Event{Message: &pb.Event_AccountShow{AccountShow: &pb.AccountShow{Index: int64(index), Account: account}}}
sendAccountAddEvent := func(index int, account *pb.ModelAccount) {
m := &pb.Event{Message: &pb.EventMessageOfAccountShow{AccountShow: &pb.EventAccountShow{Index: int64(index), Account: account}}}
if mw.SendEvent != nil {
mw.SendEvent(m)
}
}
if mw.mnemonic == "" {
return response(pb.AccountRecoverResponse_Error_NEED_TO_RECOVER_WALLET_FIRST, nil)
return response(pb.RpcAccountRecoverResponseError_NEED_TO_RECOVER_WALLET_FIRST, nil)
}
shouldCancel := false
@ -129,32 +129,32 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
sendAccountAddEvent(index, mw.localAccounts[index])
index++
if shouldCancel {
return response(pb.AccountRecoverResponse_Error_NULL, nil)
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
}
}
// now let's start the first account to perform cafe contacts search queries
account, err := core.WalletAccountAt(mw.mnemonic, 0, "")
if err != nil {
return response(pb.AccountRecoverResponse_Error_BAD_INPUT, err)
return response(pb.RpcAccountRecoverResponseError_WALLET_RECOVER_NOT_PERFORMED, err)
}
err = core.WalletInitRepo(mw.rootPath, account.Seed())
if err != nil && err != core.ErrRepoExists {
return response(pb.AccountRecoverResponse_Error_FAILED_TO_CREATE_LOCAL_REPO, err)
return response(pb.RpcAccountRecoverResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
}
anytype, err := core.New(mw.rootPath, account.Address())
if err != nil {
return response(pb.AccountRecoverResponse_Error_UNKNOWN_ERROR, err)
return response(pb.RpcAccountRecoverResponseError_UNKNOWN_ERROR, err)
}
err = anytype.Run()
if err != nil {
if err == core.ErrRepoCorrupted {
return response(pb.AccountRecoverResponse_Error_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
return response(pb.RpcAccountRecoverResponseError_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
}
return response(pb.AccountRecoverResponse_Error_FAILED_TO_RUN_NODE, err)
return response(pb.RpcAccountRecoverResponseError_FAILED_TO_RUN_NODE, err)
}
defer func() {
@ -165,7 +165,7 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
}()
if shouldCancel {
return response(pb.AccountRecoverResponse_Error_NULL, nil)
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
}
for {
@ -190,7 +190,7 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
// todo: add goroutine to query multiple accounts at once
account, err := core.WalletAccountAt(mw.mnemonic, index, "")
if err != nil {
return response(pb.AccountRecoverResponse_Error_BAD_INPUT, err)
return response(pb.RpcAccountRecoverResponseError_WALLET_RECOVER_NOT_PERFORMED, err)
}
var ctx context.Context
@ -199,20 +199,20 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
if err != nil || contact == nil {
if index == 0 {
return response(pb.AccountRecoverResponse_Error_NO_ACCOUNTS_FOUND, err)
return response(pb.RpcAccountRecoverResponseError_NO_ACCOUNTS_FOUND, err)
}
return response(pb.AccountRecoverResponse_Error_NULL, nil)
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
}
if contact.Name == "" {
if index == 0 {
return response(pb.AccountRecoverResponse_Error_NO_ACCOUNTS_FOUND, err)
return response(pb.RpcAccountRecoverResponseError_NO_ACCOUNTS_FOUND, err)
}
return response(pb.AccountRecoverResponse_Error_NULL, nil)
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
}
newAcc := &pb.Account{Id: account.Address(), Name: contact.Name}
newAcc := &pb.ModelAccount{Id: account.Address(), Name: contact.Name}
if contact.Avatar != "" {
newAcc.Avatar = getAvatarFromString(contact.Avatar)
@ -222,15 +222,15 @@ func (mw *Middleware) AccountRecover(_ *pb.AccountRecoverRequest) *pb.AccountRec
mw.localAccounts = append(mw.localAccounts, newAcc)
if shouldCancel {
return response(pb.AccountRecoverResponse_Error_NULL, nil)
return response(pb.RpcAccountRecoverResponseError_NULL, nil)
}
index++
}
}
func (mw *Middleware) AccountSelect(req *pb.AccountSelectRequest) *pb.AccountSelectResponse {
response := func(account *pb.Account, code pb.AccountSelectResponse_Error_Code, err error) *pb.AccountSelectResponse {
m := &pb.AccountSelectResponse{Account: account, Error: &pb.AccountSelectResponse_Error{Code: code}}
func (mw *Middleware) AccountSelect(req *pb.RpcAccountSelectRequest) *pb.RpcAccountSelectResponse {
response := func(account *pb.ModelAccount, code pb.RpcAccountSelectResponseErrorCode, err error) *pb.RpcAccountSelectResponse {
m := &pb.RpcAccountSelectResponse{Account: account, Error: &pb.RpcAccountSelectResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -249,23 +249,23 @@ func (mw *Middleware) AccountSelect(req *pb.AccountSelectRequest) *pb.AccountSel
if _, err := os.Stat(filepath.Join(mw.rootPath, req.Id)); os.IsNotExist(err) {
if mw.mnemonic == "" {
return response(nil, pb.AccountSelectResponse_Error_LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET, err)
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET, err)
}
account, err := core.WalletAccountAt(mw.mnemonic, len(mw.localAccounts), "")
if err != nil {
return response(nil, pb.AccountSelectResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
}
err = core.WalletInitRepo(mw.rootPath, account.Seed())
if err != nil {
return response(nil, pb.AccountSelectResponse_Error_FAILED_TO_CREATE_LOCAL_REPO, err)
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
}
}
anytype, err := core.New(mw.rootPath, req.Id)
if err != nil {
return response(nil, pb.AccountSelectResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcAccountSelectResponseError_UNKNOWN_ERROR, err)
}
mw.Anytype = anytype
@ -273,22 +273,22 @@ func (mw *Middleware) AccountSelect(req *pb.AccountSelectRequest) *pb.AccountSel
err = mw.Run()
if err != nil {
if err == core.ErrRepoCorrupted {
return response(nil, pb.AccountSelectResponse_Error_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
return response(nil, pb.RpcAccountSelectResponseError_LOCAL_REPO_EXISTS_BUT_CORRUPTED, err)
}
return response(nil, pb.AccountSelectResponse_Error_FAILED_TO_RUN_NODE, err)
return response(nil, pb.RpcAccountSelectResponseError_FAILED_TO_RUN_NODE, err)
}
acc := &pb.Account{Id: req.Id}
acc := &pb.ModelAccount{Id: req.Id}
acc.Name, err = mw.Anytype.Textile.Name()
if err != nil {
return response(acc, pb.AccountSelectResponse_Error_FAILED_TO_FIND_ACCOUNT_INFO, err)
return response(acc, pb.RpcAccountSelectResponseError_FAILED_TO_FIND_ACCOUNT_INFO, err)
}
avatarHashOrColor, err := mw.Anytype.Textile.Avatar()
if err != nil {
return response(acc, pb.AccountSelectResponse_Error_FAILED_TO_FIND_ACCOUNT_INFO, err)
return response(acc, pb.RpcAccountSelectResponseError_FAILED_TO_FIND_ACCOUNT_INFO, err)
}
if acc.Name == "" && avatarHashOrColor == "" {
@ -304,7 +304,7 @@ func (mw *Middleware) AccountSelect(req *pb.AccountSelectRequest) *pb.AccountSel
contact, err := anytype.AccountRequestStoredContact(context.Background(), req.Id)
if err != nil {
return response(acc, pb.AccountSelectResponse_Error_FAILED_TO_FIND_ACCOUNT_INFO, err)
return response(acc, pb.RpcAccountSelectResponseError_FAILED_TO_FIND_ACCOUNT_INFO, err)
}
acc.Name = contact.Name
avatarHashOrColor = contact.Avatar
@ -314,13 +314,13 @@ func (mw *Middleware) AccountSelect(req *pb.AccountSelectRequest) *pb.AccountSel
acc.Avatar = getAvatarFromString(avatarHashOrColor)
}
return response(acc, pb.AccountSelectResponse_Error_NULL, nil)
return response(acc, pb.RpcAccountSelectResponseError_NULL, nil)
}
func getAvatarFromString(avatarHashOrColor string) *pb.Avatar {
func getAvatarFromString(avatarHashOrColor string) *pb.ModelAccountAvatar {
if strings.HasPrefix(avatarHashOrColor, "#") {
return &pb.Avatar{&pb.Avatar_Color{avatarHashOrColor}}
return &pb.ModelAccountAvatar{&pb.ModelAccountAvatarAvatarOfColor{avatarHashOrColor}}
} else {
return &pb.Avatar{&pb.Avatar_Image{&pb.Image{avatarHashOrColor, avatarSizes}}}
return &pb.ModelAccountAvatar{&pb.ModelAccountAvatarAvatarOfImage{&pb.ModelImage{avatarHashOrColor, avatarSizes}}}
}
}

View file

@ -13,8 +13,8 @@ import (
func createWallet(t *testing.T) *Middleware {
mw := &Middleware{}
rootPath := os.TempDir()
resp := mw.WalletCreate(&pb.WalletCreateRequest{RootPath: rootPath})
require.Equal(t, pb.WalletCreateResponse_Error_NULL, resp.Error.Code, resp.Error.Code, "WalletCreate error should be 0")
resp := mw.WalletCreate(&pb.RpcWalletCreateRequest{RootPath: rootPath})
require.Equal(t, pb.RpcWalletCreateResponseError_NULL, resp.Error.Code, resp.Error.Code, "WalletCreate error should be 0")
require.Equal(t, 12, len(strings.Split(resp.Mnemonic, " ")), "WalletCreate should return 12 words")
return mw
}
@ -22,37 +22,37 @@ func createWallet(t *testing.T) *Middleware {
func recoverWallet(t *testing.T, mnemonic string) *Middleware {
mw := &Middleware{}
rootPath := os.TempDir()
resp := mw.WalletRecover(&pb.WalletRecoverRequest{RootPath: rootPath, Mnemonic: mnemonic})
require.Equal(t, pb.WalletRecoverResponse_Error_NULL, resp.Error.Code, "WalletRecover error should be 0")
resp := mw.WalletRecover(&pb.RpcWalletRecoverRequest{RootPath: rootPath, Mnemonic: mnemonic})
require.Equal(t, pb.RpcWalletRecoverResponseError_NULL, resp.Error.Code, "WalletRecover error should be 0")
return mw
}
func Test_AccountCreate(t *testing.T) {
func TestAccountCreate(t *testing.T) {
mw := createWallet(t)
accountCreateResp := mw.AccountCreate(&pb.AccountCreateRequest{Name: "name_test", Avatar: &pb.AccountCreateRequest_AvatarLocalPath{"testdata/pic1.jpg"}})
accountCreateResp := mw.AccountCreate(&pb.RpcAccountCreateRequest{Name: "name_test", Avatar: &pb.RpcAccountCreateRequestAvatarOfAvatarLocalPath{"testdata/pic1.jpg"}})
require.Equal(t, "name_test", accountCreateResp.Account.Name, "AccountCreateResponse has account with wrong name '%s'", accountCreateResp.Account.Name)
imageGetBlobResp := mw.ImageGetBlob(&pb.ImageGetBlobRequest{Id: accountCreateResp.Account.Avatar.GetImage().Id, Size_: pb.ImageSize_SMALL})
require.Equal(t, pb.ImageGetBlobResponse_Error_NULL, imageGetBlobResp.Error.Code, "ImageGetBlobResponse contains error: %+v", imageGetBlobResp.Error)
imageGetBlobResp := mw.ImageGetBlob(&pb.RpcImageGetBlobRequest{Id: accountCreateResp.Account.Avatar.GetImage().Id, Size_: pb.ModelImage_SMALL})
require.Equal(t, pb.RpcImageGetBlobResponseError_NULL, imageGetBlobResp.Error.Code, "ImageGetBlobResponse contains error: %+v", imageGetBlobResp.Error)
require.True(t, len(imageGetBlobResp.Blob) > 0, "ava size should be greater than 0")
err := mw.Stop()
require.NoError(t, err, "failed to stop mw")
}
func Test_AccountRecover_LocalWithoutRestart(t *testing.T) {
func TestAccountRecoverLocalWithoutRestart(t *testing.T) {
mw := createWallet(t)
accountCreateResp := mw.AccountCreate(&pb.AccountCreateRequest{Name: "name_to_test_recover", Avatar: &pb.AccountCreateRequest_AvatarLocalPath{"testdata/pic1.jpg"}})
accountCreateResp := mw.AccountCreate(&pb.RpcAccountCreateRequest{Name: "name_to_test_recover", Avatar: &pb.RpcAccountCreateRequestAvatarOfAvatarLocalPath{"testdata/pic1.jpg"}})
require.Equal(t, "name_to_test_recover", accountCreateResp.Account.Name, "AccountCreateResponse has account with wrong name '%s'", accountCreateResp.Account.Name)
err := mw.Stop()
require.NoError(t, err, "failed to stop node")
var accountCh = make(chan *pb.Account, 10)
var accountCh = make(chan *pb.ModelAccount, 10)
mw.SendEvent = func(event *pb.Event) {
if aa, ok := event.Message.(*pb.Event_AccountShow); ok {
if aa, ok := event.Message.(*pb.EventMessageOfAccountShow); ok {
if aa.AccountShow.Index != 0 {
return
}
@ -61,13 +61,13 @@ func Test_AccountRecover_LocalWithoutRestart(t *testing.T) {
}
}
walletRecoverResp := mw.WalletRecover(&pb.WalletRecoverRequest{RootPath: mw.rootPath, Mnemonic: mw.mnemonic})
require.Equal(t, pb.WalletRecoverResponse_Error_NULL, walletRecoverResp.Error.Code, "WalletRecoverResponse contains error: %+v", walletRecoverResp.Error)
walletRecoverResp := mw.WalletRecover(&pb.RpcWalletRecoverRequest{RootPath: mw.rootPath, Mnemonic: mw.mnemonic})
require.Equal(t, pb.RpcWalletRecoverResponseError_NULL, walletRecoverResp.Error.Code, "WalletRecoverResponse contains error: %+v", walletRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.AccountRecoverRequest{})
require.Equal(t, pb.AccountRecoverResponse_Error_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.RpcAccountRecoverRequest{})
require.Equal(t, pb.RpcAccountRecoverResponseError_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
var account *pb.Account
var account *pb.ModelAccount
select {
case account = <-accountCh:
break
@ -80,10 +80,10 @@ func Test_AccountRecover_LocalWithoutRestart(t *testing.T) {
require.NoError(t, err, "failed to stop mw")
}
func Test_AccountRecover_LocalAfterRestart(t *testing.T) {
func TestAccountRecoverLocalAfterRestart(t *testing.T) {
mw := createWallet(t)
accountCreateResp := mw.AccountCreate(&pb.AccountCreateRequest{Name: "name_to_test_recover", Avatar: &pb.AccountCreateRequest_AvatarLocalPath{"testdata/pic1.jpg"}})
accountCreateResp := mw.AccountCreate(&pb.RpcAccountCreateRequest{Name: "name_to_test_recover", Avatar: &pb.RpcAccountCreateRequestAvatarOfAvatarLocalPath{"testdata/pic1.jpg"}})
require.Equal(t, "name_to_test_recover", accountCreateResp.Account.Name, "AccountCreateResponse has account with wrong name '%s'", accountCreateResp.Account.Name)
err := mw.Stop()
@ -94,9 +94,9 @@ func Test_AccountRecover_LocalAfterRestart(t *testing.T) {
// reset singleton to emulate restart
mw = &Middleware{}
var accountCh = make(chan *pb.Account, 10)
var accountCh = make(chan *pb.ModelAccount, 10)
mw.SendEvent = func(event *pb.Event) {
if aa, ok := event.Message.(*pb.Event_AccountShow); ok {
if aa, ok := event.Message.(*pb.EventMessageOfAccountShow); ok {
if aa.AccountShow.Index != 0 {
return
}
@ -105,13 +105,13 @@ func Test_AccountRecover_LocalAfterRestart(t *testing.T) {
}
}
walletRecoverResp := mw.WalletRecover(&pb.WalletRecoverRequest{RootPath: rootPath, Mnemonic: mnemonic})
require.Equal(t, pb.WalletRecoverResponse_Error_NULL, walletRecoverResp.Error.Code, "WalletRecoverResponse contains error: %+v", walletRecoverResp.Error)
walletRecoverResp := mw.WalletRecover(&pb.RpcWalletRecoverRequest{RootPath: rootPath, Mnemonic: mnemonic})
require.Equal(t, pb.RpcWalletRecoverResponseError_NULL, walletRecoverResp.Error.Code, "WalletRecoverResponse contains error: %+v", walletRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.AccountRecoverRequest{})
require.Equal(t, pb.AccountRecoverResponse_Error_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.RpcAccountRecoverRequest{})
require.Equal(t, pb.RpcAccountRecoverResponseError_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
var account *pb.Account
var account *pb.ModelAccount
select {
case account = <-accountCh:
break
@ -124,19 +124,19 @@ func Test_AccountRecover_LocalAfterRestart(t *testing.T) {
err = mw.Stop()
}
func Test_AccountRecover_RemoteNotExisting(t *testing.T) {
func TestAccountRecoverRemoteNotExisting(t *testing.T) {
mw := recoverWallet(t, "limit oxygen february destroy subway toddler umbrella nose praise shield afford eager")
require.Equal(t, len(mw.localAccounts), 0, "localAccounts should be empty, instead got length = %d", len(mw.localAccounts))
var account *pb.Account
var account *pb.ModelAccount
mw.SendEvent = func(event *pb.Event) {
if aa, ok := event.Message.(*pb.Event_AccountShow); ok {
if aa, ok := event.Message.(*pb.EventMessageOfAccountShow); ok {
account = aa.AccountShow.Account
}
}
accountRecoverResp := mw.AccountRecover(&pb.AccountRecoverRequest{})
require.Equal(t, pb.AccountRecoverResponse_Error_NO_ACCOUNTS_FOUND, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.RpcAccountRecoverRequest{})
require.Equal(t, pb.RpcAccountRecoverResponseError_NO_ACCOUNTS_FOUND, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
require.Nil(t, account, "account shouldn't be recovered")
@ -144,13 +144,13 @@ func Test_AccountRecover_RemoteNotExisting(t *testing.T) {
require.NoError(t, err, "failed to stop mw")
}
func Test_RecoverRemoteExisting(t *testing.T) {
func TestRecoverRemoteExisting(t *testing.T) {
mw := recoverWallet(t, "input blame switch simple fatigue fragile grab goose unusual identify abuse use")
require.Equal(t, len(mw.localAccounts), 0, "localAccounts should be empty, instead got length = %d", len(mw.localAccounts))
var accountCh = make(chan *pb.Account, 10)
var accountCh = make(chan *pb.ModelAccount, 10)
mw.SendEvent = func(event *pb.Event) {
if aa, ok := event.Message.(*pb.Event_AccountShow); ok {
if aa, ok := event.Message.(*pb.EventMessageOfAccountShow); ok {
if aa.AccountShow.Index != 0 {
return
}
@ -159,10 +159,10 @@ func Test_RecoverRemoteExisting(t *testing.T) {
}
}
accountRecoverResp := mw.AccountRecover(&pb.AccountRecoverRequest{})
require.Equal(t, pb.AccountRecoverResponse_Error_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
accountRecoverResp := mw.AccountRecover(&pb.RpcAccountRecoverRequest{})
require.Equal(t, pb.RpcAccountRecoverResponseError_NULL, accountRecoverResp.Error.Code, "AccountRecoverResponse contains error: %+v", accountRecoverResp.Error)
var account *pb.Account
var account *pb.ModelAccount
select {
case account = <-accountCh:
break

View file

@ -4,9 +4,9 @@ import (
"github.com/anytypeio/go-anytype-middleware/pb"
)
func (mw *Middleware) BlockCreate(req *pb.BlockCreateRequest) *pb.BlockCreateResponse {
response := func(code pb.BlockCreateResponse_Error_Code, err error) *pb.BlockCreateResponse {
m := &pb.BlockCreateResponse{Error: &pb.BlockCreateResponse_Error{Code: code}}
func (mw *Middleware) BlockCreate(req *pb.RpcBlockCreateRequest) *pb.RpcBlockCreateResponse {
response := func(code pb.RpcBlockCreateResponseErrorCode, err error) *pb.RpcBlockCreateResponse {
m := &pb.RpcBlockCreateResponse{Error: &pb.RpcBlockCreateResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -14,20 +14,20 @@ func (mw *Middleware) BlockCreate(req *pb.BlockCreateRequest) *pb.BlockCreateRes
return m
}
block := &pb.Block{} // TODO
/*block := &pb.ModelBlock{} // TODO
m := &pb.Event{Message: &pb.Event_BlockCreate{&pb.BlockCreate{Block: block}}}
m := &pb.Event{Message: &pb.EventBlockCreate{&pb.RpcBlockCreate{Block: block}}}
if mw.SendEvent != nil {
mw.SendEvent(m)
}
}*/
return response(pb.BlockCreateResponse_Error_NULL, nil)
return response(pb.RpcBlockCreateResponseError_NULL, nil)
}
func (mw *Middleware) BlockOpen(req *pb.BlockOpenRequest) *pb.BlockOpenResponse {
response := func(code pb.BlockOpenResponse_Error_Code, err error) *pb.BlockOpenResponse {
m := &pb.BlockOpenResponse{Error: &pb.BlockOpenResponse_Error{Code: code}}
func (mw *Middleware) BlockOpen(req *pb.RpcBlockOpenRequest) *pb.RpcBlockOpenResponse {
response := func(code pb.RpcBlockOpenResponseErrorCode, err error) *pb.RpcBlockOpenResponse {
m := &pb.RpcBlockOpenResponse{Error: &pb.RpcBlockOpenResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -35,20 +35,20 @@ func (mw *Middleware) BlockOpen(req *pb.BlockOpenRequest) *pb.BlockOpenResponse
return m
}
block := &pb.Block{} // TODO
/*block := &pb.ModelBlock{} // TODO
m := &pb.Event{Message: &pb.Event_BlockShow{&pb.BlockShow{Block: block}}}
m := &pb.Event{Message: &pb.EventBlockShow{&pb.RpcBlockShow{Block: block}}}
if mw.SendEvent != nil {
mw.SendEvent(m)
}
}*/
return response(pb.BlockOpenResponse_Error_NULL, nil)
return response(pb.RpcBlockOpenResponseError_NULL, nil)
}
func (mw *Middleware) BlockUpdate(req *pb.BlockUpdateRequest) *pb.BlockUpdateResponse {
response := func(code pb.BlockUpdateResponse_Error_Code, err error) *pb.BlockUpdateResponse {
m := &pb.BlockUpdateResponse{Error: &pb.BlockUpdateResponse_Error{Code: code}}
func (mw *Middleware) BlockUpdate(req *pb.RpcBlockUpdateRequest) *pb.RpcBlockUpdateResponse {
response := func(code pb.RpcBlockUpdateResponseErrorCode, err error) *pb.RpcBlockUpdateResponse {
m := &pb.RpcBlockUpdateResponse{Error: &pb.RpcBlockUpdateResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -56,13 +56,14 @@ func (mw *Middleware) BlockUpdate(req *pb.BlockUpdateRequest) *pb.BlockUpdateRes
return m
}
changes := &pb.BlockChanges{} // TODO
/*
changes := &pb.RpcBlockChanges{} // TODO
m := &pb.Event{Message: &pb.Event_BlockUpdate{&pb.BlockUpdate{changes}}}
m := &pb.Event{Message: &pb.EventBlockUpdate{&pb.RpcBlockUpdate{changes}}}
if mw.SendEvent != nil {
mw.SendEvent(m)
}
if mw.SendEvent != nil {
mw.SendEvent(m)
}*/
return response(pb.BlockUpdateResponse_Error_NULL, nil)
return response(pb.RpcBlockUpdateResponseError_NULL, nil)
}

View file

@ -30,7 +30,7 @@ type Middleware struct {
pin string
mnemonic string
accountSearchCancel context.CancelFunc
localAccounts []*pb.Account
localAccounts []*pb.ModelAccount
SendEvent func(event *pb.Event)
linkPreview linkpreview.LinkPreview
*libCore.Anytype

20
core/history.go Normal file
View file

@ -0,0 +1,20 @@
package core
import (
"github.com/anytypeio/go-anytype-middleware/pb"
)
func (mw *Middleware) BlockHistoryMove(req *pb.RpcBlockHistoryMoveRequest) *pb.RpcBlockHistoryMoveResponse {
response := func(code pb.RpcBlockHistoryMoveResponseErrorCode, err error) *pb.RpcBlockHistoryMoveResponse {
m := &pb.RpcBlockHistoryMoveResponse{Error: &pb.RpcBlockHistoryMoveResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
return m
}
// TODO
return response(pb.RpcBlockHistoryMoveResponseError_NULL, nil)
}

View file

@ -9,9 +9,9 @@ import (
"github.com/textileio/go-textile/ipfs"
)
func (mw *Middleware) IpfsGetFile(req *pb.IpfsGetFileRequest) *pb.IpfsGetFileResponse {
response := func(data []byte, media string, name string, code pb.IpfsGetFileResponse_Error_Code, err error) *pb.IpfsGetFileResponse {
m := &pb.IpfsGetFileResponse{Data: data, Media: media, Error: &pb.IpfsGetFileResponse_Error{Code: code}}
func (mw *Middleware) IpfsGetFile(req *pb.RpcIpfsGetFileRequest) *pb.RpcIpfsGetFileResponse {
response := func(data []byte, media string, name string, code pb.RpcIpfsGetFileResponseErrorCode, err error) *pb.RpcIpfsGetFileResponse {
m := &pb.RpcIpfsGetFileResponse{Data: data, Media: media, Error: &pb.RpcIpfsGetFileResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -22,25 +22,25 @@ func (mw *Middleware) IpfsGetFile(req *pb.IpfsGetFileRequest) *pb.IpfsGetFileRes
reader, info, err := mw.Anytype.Textile.Node().FileContent(req.Id)
if err != nil {
if err == core2.ErrFileNotFound {
return response(nil, "", "", pb.IpfsGetFileResponse_Error_NOT_FOUND, err)
return response(nil, "", "", pb.RpcIpfsGetFileResponseError_NOT_FOUND, err)
}
return response(nil, "", "", pb.IpfsGetFileResponse_Error_UNKNOWN_ERROR, err)
return response(nil, "", "", pb.RpcIpfsGetFileResponseError_UNKNOWN_ERROR, err)
}
data, err := ioutil.ReadAll(reader)
if err != nil {
return response(nil, "", "", pb.IpfsGetFileResponse_Error_UNKNOWN_ERROR, err)
return response(nil, "", "", pb.RpcIpfsGetFileResponseError_UNKNOWN_ERROR, err)
}
return response(data, info.Media, info.Name, pb.IpfsGetFileResponse_Error_NULL, nil)
return response(data, info.Media, info.Name, pb.RpcIpfsGetFileResponseError_NULL, nil)
}
/*
//exportMobile IpfsGetData
func IpfsGetData(b []byte) []byte {
response := func(data []byte, code pb.IpfsGetDataResponse_Error_Code, err error) []byte {
m := &pb.IpfsGetDataResponse{Data: data, Error: &pb.IpfsGetDataResponse_Error{Code: code}}
response := func(data []byte, code pb.RpcIpfsGetDataResponseErrorCode, err error) []byte {
m := &pb.RpcIpfsGetDataResponse{Data: data, Error: &pb.RpcIpfsGetDataResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -48,29 +48,29 @@ func IpfsGetData(b []byte) []byte {
return Marshal(m)
}
var q pb.IpfsGetDataRequest
var q pb.RpcIpfsGetDataRequest
err := proto.Unmarshal(b, &q)
if err != nil {
return response(nil, pb.IpfsGetDataResponse_Error_BAD_INPUT, err)
return response(nil, pb.RpcIpfsGetDataResponseError_BAD_INPUT, err)
}
data, err := ipfs.DataAtPath(mw.Anytype.Textile.Node().Ipfs(), q.Id)
if err != nil {
if err == core2.ErrFileNotFound {
return response(nil, pb.IpfsGetDataResponse_Error_NOT_FOUND, err)
return response(nil, pb.RpcIpfsGetDataResponseError_NOT_FOUND, err)
}
return response(nil, pb.IpfsGetDataResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcIpfsGetDataResponseError_UNKNOWN_ERROR, err)
}
return response(data, pb.IpfsGetDataResponse_Error_NULL, nil)
return response(data, pb.RpcIpfsGetDataResponseError_NULL, nil)
}
*/
func (mw *Middleware) ImageGetBlob(req *pb.ImageGetBlobRequest) *pb.ImageGetBlobResponse {
response := func(blob []byte, code pb.ImageGetBlobResponse_Error_Code, err error) *pb.ImageGetBlobResponse {
m := &pb.ImageGetBlobResponse{Blob: blob, Error: &pb.ImageGetBlobResponse_Error{Code: code}}
func (mw *Middleware) ImageGetBlob(req *pb.RpcImageGetBlobRequest) *pb.RpcImageGetBlobResponse {
response := func(blob []byte, code pb.RpcImageGetBlobResponseErrorCode, err error) *pb.RpcImageGetBlobResponse {
m := &pb.RpcImageGetBlobResponse{Blob: blob, Error: &pb.RpcImageGetBlobResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -81,11 +81,11 @@ func (mw *Middleware) ImageGetBlob(req *pb.ImageGetBlobRequest) *pb.ImageGetBlob
data, err := ipfs.DataAtPath(mw.Anytype.Textile.Node().Ipfs(), req.Id+"/0/"+strings.ToLower(req.GetSize_().String())+"/content")
if err != nil {
if err == core2.ErrFileNotFound {
return response(nil, pb.ImageGetBlobResponse_Error_NOT_FOUND, err)
return response(nil, pb.RpcImageGetBlobResponseError_NOT_FOUND, err)
}
return response(nil, pb.ImageGetBlobResponse_Error_UNKNOWN_ERROR, err)
return response(nil, pb.RpcImageGetBlobResponseError_UNKNOWN_ERROR, err)
}
return response(data, pb.ImageGetBlobResponse_Error_NULL, nil)
return response(data, pb.RpcImageGetBlobResponseError_NULL, nil)
}

View file

@ -1,29 +0,0 @@
package core
import (
"context"
"time"
"github.com/anytypeio/go-anytype-middleware/pb"
)
var (
linkPreviewTimeout = time.Second * 5
)
func (mw *Middleware) LinkPreview(req *pb.LinkPreviewRequest) *pb.LinkPreviewResponse {
ctx, cancel := context.WithTimeout(context.Background(), linkPreviewTimeout)
defer cancel()
resp, err := mw.linkPreview.Fetch(ctx, req.Url)
if err != nil {
if err == context.DeadlineExceeded {
return &pb.LinkPreviewResponse{Error: &pb.LinkPreviewResponse_Error{
Code: pb.LinkPreviewResponse_Error_TIMEOUT,
}}
}
return &pb.LinkPreviewResponse{Error: &pb.LinkPreviewResponse_Error{
Code: pb.LinkPreviewResponse_Error_UNKNOWN_ERROR,
}}
}
return &resp
}

View file

@ -4,9 +4,9 @@ import (
"github.com/anytypeio/go-anytype-middleware/pb"
)
func (mw *Middleware) LogSend(req *pb.LogSendRequest) *pb.LogSendResponse {
response := func(code pb.LogSendResponse_Error_Code, err error) *pb.LogSendResponse {
m := &pb.LogSendResponse{Error: &pb.LogSendResponse_Error{Code: code}}
func (mw *Middleware) LogSend(req *pb.RpcLogSendRequest) *pb.RpcLogSendResponse {
response := func(code pb.RpcLogSendResponseErrorCode, err error) *pb.RpcLogSendResponse {
m := &pb.RpcLogSendResponse{Error: &pb.RpcLogSendResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -15,19 +15,19 @@ func (mw *Middleware) LogSend(req *pb.LogSendRequest) *pb.LogSendResponse {
}
switch req.Level {
case pb.LogSendRequest_FATAL:
case pb.RpcLogSendRequest_FATAL:
log.Fatal(req.Message)
case pb.LogSendRequest_PANIC:
case pb.RpcLogSendRequest_PANIC:
log.Panic(req.Message)
case pb.LogSendRequest_DEBUG:
case pb.RpcLogSendRequest_DEBUG:
log.Debug(req.Message)
case pb.LogSendRequest_INFO:
case pb.RpcLogSendRequest_INFO:
log.Info(req.Message)
case pb.LogSendRequest_WARNING:
case pb.RpcLogSendRequest_WARNING:
log.Warning(req.Message)
case pb.LogSendRequest_ERROR:
case pb.RpcLogSendRequest_ERROR:
log.Error(req.Message)
}
return response(pb.LogSendResponse_Error_NULL, nil)
return response(pb.RpcLogSendResponseError_NULL, nil)
}

View file

@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)
func Test_Log(t *testing.T) {
func TestLog(t *testing.T) {
mw := Middleware{}
file, err := ioutil.TempFile("", "testlog")
require.NoError(t, err)
@ -21,13 +21,13 @@ func Test_Log(t *testing.T) {
os.Setenv("GOLOG_FILE", file.Name())
logger.SetupLogging()
logger.SetDebugLogging()
for level, levelText := range map[pb.LogSendRequest_Level]string{
pb.LogSendRequest_ERROR: "[31mERROR",
pb.LogSendRequest_WARNING: "[33mWARNI",
for level, levelText := range map[pb.RpcLogSendRequestLevel]string{
pb.RpcLogSendRequest_ERROR: "[31mERROR",
pb.RpcLogSendRequest_WARNING: "[33mWARNI",
} {
text := fmt.Sprintf("test_log_%s", time.Now().String())
resp := mw.LogSend(&pb.LogSendRequest{Message: text, Level: level})
require.Equal(t, pb.LogSendResponse_Error_NULL, resp.Error.Code, "LogSendResponse contains error: %+v", resp.Error)
resp := mw.LogSend(&pb.RpcLogSendRequest{Message: text, Level: level})
require.Equal(t, pb.RpcLogSendResponseError_NULL, resp.Error.Code, "LogSendResponse contains error: %+v", resp.Error)
b, err := ioutil.ReadFile(file.Name())
require.NoError(t, err)

View file

@ -9,9 +9,9 @@ import (
// Set by ldflags
var GitCommit, GitBranch, GitState, GitSummary, BuildDate string
func (mw *Middleware) VersionGet(req *pb.VersionGetRequest) *pb.VersionGetResponse {
response := func(version, details string, code pb.VersionGetResponse_Error_Code, err error) *pb.VersionGetResponse {
m := &pb.VersionGetResponse{Version: version, Error: &pb.VersionGetResponse_Error{Code: code}}
func (mw *Middleware) VersionGet(req *pb.RpcVersionGetRequest) *pb.RpcVersionGetResponse {
response := func(version, details string, code pb.RpcVersionGetResponseErrorCode, err error) *pb.RpcVersionGetResponse {
m := &pb.RpcVersionGetResponse{Version: version, Error: &pb.RpcVersionGetResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -20,10 +20,10 @@ func (mw *Middleware) VersionGet(req *pb.VersionGetRequest) *pb.VersionGetRespon
}
if len(GitSummary) == 0 {
return response("", "", pb.VersionGetResponse_Error_VERSION_IS_EMPTY, nil)
return response("", "", pb.RpcVersionGetResponseError_VERSION_IS_EMPTY, nil)
}
details := fmt.Sprintf("build on %s from %s at #%s(%s)", BuildDate, GitCommit, GitBranch, GitState)
return response(GitSummary, details, pb.VersionGetResponse_Error_NULL, nil)
return response(GitSummary, details, pb.RpcVersionGetResponseError_NULL, nil)
}

View file

@ -9,9 +9,9 @@ import (
const wordCount int = 12
func (mw *Middleware) WalletCreate(req *pb.WalletCreateRequest) *pb.WalletCreateResponse {
response := func(mnemonic string, code pb.WalletCreateResponse_Error_Code, err error) *pb.WalletCreateResponse {
m := &pb.WalletCreateResponse{Mnemonic: mnemonic, Error: &pb.WalletCreateResponse_Error{Code: code}}
func (mw *Middleware) WalletCreate(req *pb.RpcWalletCreateRequest) *pb.RpcWalletCreateResponse {
response := func(mnemonic string, code pb.RpcWalletCreateResponseErrorCode, err error) *pb.RpcWalletCreateResponse {
m := &pb.RpcWalletCreateResponse{Mnemonic: mnemonic, Error: &pb.RpcWalletCreateResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -24,22 +24,22 @@ func (mw *Middleware) WalletCreate(req *pb.WalletCreateRequest) *pb.WalletCreate
err := os.MkdirAll(mw.rootPath, 0700)
if err != nil {
return response("", pb.WalletCreateResponse_Error_FAILED_TO_CREATE_LOCAL_REPO, err)
return response("", pb.RpcWalletCreateResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
}
mnemonic, err := core.WalletGenerateMnemonic(wordCount)
if err != nil {
return response("", pb.WalletCreateResponse_Error_UNKNOWN_ERROR, err)
return response("", pb.RpcWalletCreateResponseError_UNKNOWN_ERROR, err)
}
mw.mnemonic = mnemonic
return response(mnemonic, pb.WalletCreateResponse_Error_NULL, nil)
return response(mnemonic, pb.RpcWalletCreateResponseError_NULL, nil)
}
func (mw *Middleware) WalletRecover(req *pb.WalletRecoverRequest) *pb.WalletRecoverResponse {
response := func(code pb.WalletRecoverResponse_Error_Code, err error) *pb.WalletRecoverResponse {
m := &pb.WalletRecoverResponse{Error: &pb.WalletRecoverResponse_Error{Code: code}}
func (mw *Middleware) WalletRecover(req *pb.RpcWalletRecoverRequest) *pb.RpcWalletRecoverResponse {
response := func(code pb.RpcWalletRecoverResponseErrorCode, err error) *pb.RpcWalletRecoverResponse {
m := &pb.RpcWalletRecoverResponse{Error: &pb.RpcWalletRecoverResponseError{Code: code}}
if err != nil {
m.Error.Description = err.Error()
}
@ -56,14 +56,14 @@ func (mw *Middleware) WalletRecover(req *pb.WalletRecoverRequest) *pb.WalletReco
err := os.MkdirAll(mw.rootPath, 0700)
if err != nil {
return response(pb.WalletRecoverResponse_Error_FAILED_TO_CREATE_LOCAL_REPO, err)
return response(pb.RpcWalletRecoverResponseError_FAILED_TO_CREATE_LOCAL_REPO, err)
}
// test if mnemonic is correct
_, err = core.WalletAccountAt(req.Mnemonic, 0, "")
if err != nil {
return response(pb.WalletRecoverResponse_Error_BAD_INPUT, err)
return response(pb.RpcWalletRecoverResponseError_BAD_INPUT, err)
}
return response(pb.WalletRecoverResponse_Error_NULL, nil)
return response(pb.RpcWalletRecoverResponseError_NULL, nil)
}

2446
docs/proto.md Normal file

File diff suppressed because it is too large Load diff

10
go.mod
View file

@ -3,14 +3,24 @@ module github.com/anytypeio/go-anytype-middleware
go 1.12
require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/PuerkitoBio/goquery v1.5.0 // indirect
github.com/anytypeio/go-anytype-library v0.0.0-20191019100520-f545fa654778
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.2
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/ipfs/go-log v0.0.1
github.com/lyft/protoc-gen-validate v0.1.0 // indirect
github.com/mauidude/go-readability v0.0.0-20141216012317-2f30b1a346f1
github.com/microcosm-cc/bluemonday v1.0.2
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mwitkow/go-proto-validators v0.2.0 // indirect
github.com/otiai10/opengraph v1.1.0
github.com/pseudomuto/protoc-gen-doc v1.3.0 // indirect
github.com/pseudomuto/protokit v0.2.0 // indirect
github.com/stretchr/testify v1.3.0
github.com/textileio/go-textile v0.7.2-0.20190907000013-95a885123536
)

24
go.sum
View file

@ -10,6 +10,12 @@ github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETF
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd/go.mod h1:bqoB8kInrTeEtYAwaIXoSRqdwnjQmFhsfusnzyui6yY=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OpenPeeDeeP/depguard v0.0.0-20180806142446-a69c782687b2/go.mod h1:7/4sitnI9YlQgTLLk734QlzXT8DuHVnAyztLplQjk+o=
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
@ -154,6 +160,7 @@ github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJA
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@ -211,10 +218,14 @@ github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/huin/goupnp v0.0.0-20180415215157-1395d1447324/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag=
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipfs/bbloom v0.0.1 h1:s7KkiBPfxCeDVo47KySjK0ACPc5GJRUxFpdyWEuDjhw=
github.com/ipfs/bbloom v0.0.1/go.mod h1:oqo8CVWsJFMOZqTglBG4wydCE4IQA/G2/SEofB0rjUI=
@ -567,6 +578,8 @@ github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQ
github.com/lucas-clemente/quic-go v0.11.1/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw=
github.com/lucas-clemente/quic-go v0.11.2 h1:Mop0ac3zALaBR3wGs6j8OYe/tcFvFsxTUFMkE/7yUOI=
github.com/lucas-clemente/quic-go v0.11.2/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw=
github.com/lyft/protoc-gen-validate v0.1.0 h1:NytKd9K7UW7Szxn+9PYNsaJ/98TL/WsDq4ro4ZVuh5o=
github.com/lyft/protoc-gen-validate v0.1.0/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@ -602,12 +615,16 @@ github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+
github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM=
github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
@ -643,6 +660,8 @@ github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wS
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f h1:hd3r+uv9DNLScbOrnlj82rBldHQf3XWmCeXAWbw8euQ=
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f/go.mod h1:MyUWrZlB1aI5bs7j9/pJ8ckLLZ4QcCYcNiSbsAW32D4=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-proto-validators v0.2.0 h1:F6LFfmgVnfULfaRsQWBbe7F7ocuHCr9+7m+GAeDzNbQ=
github.com/mwitkow/go-proto-validators v0.2.0/go.mod h1:ZfA1hW+UH/2ZHOWvQ3HnQaU0DtnpXu850MZiy+YUgcc=
github.com/nbutton23/zxcvbn-go v0.0.0-20160627004424-a22cb81b2ecd/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/nbutton23/zxcvbn-go v0.0.0-20171102151520-eafdab6b0663/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
@ -692,6 +711,10 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.0-20190519111021-9935e8e0588d/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pseudomuto/protoc-gen-doc v1.3.0 h1:wpwmaSCWY2lGwkzAxAaqYcGyoklZjZmeXrJ/X7IskJM=
github.com/pseudomuto/protoc-gen-doc v1.3.0/go.mod h1:fwtQAY9erXp3mC92O8OTECnDlJT2r0Ff4KSEKbGEmy0=
github.com/pseudomuto/protokit v0.2.0 h1:hlnBDcy3YEDXH7kc9gV+NLaN0cDzhDvD1s7Y6FZ8RpM=
github.com/pseudomuto/protokit v0.2.0/go.mod h1:2PdH30hxVHsup8KpBTOXTBeMVhJZVio3Q8ViKSAXT0Q=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
@ -918,6 +941,7 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 h1:Lj2SnHtxkRGJDqnGaSjo+CCdIieEnwVazbOXILwQemk=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=

View file

@ -10,24 +10,24 @@ import (
"github.com/stretchr/testify/require"
)
func Test_Unpack(t *testing.T) {
b, _ := proto.Marshal(&pb.WalletRecoverResponse{})
func TestUnpack(t *testing.T) {
b, _ := proto.Marshal(&pb.RpcWalletRecoverResponse{})
var msg pb.WalletRecoverResponse
var msg pb.RpcWalletRecoverResponse
err := proto.Unmarshal(b, &msg)
if err != nil {
fmt.Println(err.Error())
}
}
func Test_EventHandler(t *testing.T) {
func TestEventHandler(t *testing.T) {
var eventReceived *pb.Event
mw = &core.Middleware{}
SetEventHandler(func(event *pb.Event) {
eventReceived = event
})
eventSent := &pb.Event{Message: &pb.Event_AccountShow{AccountShow: &pb.AccountShow{Index: 0, Account: &pb.Account{Id: "1", Name: "name"}}}}
eventSent := &pb.Event{Message: &pb.EventMessageOfAccountShow{AccountShow: &pb.EventAccountShow{Index: 0, Account: &pb.ModelAccount{Id: "1", Name: "name"}}}}
mw.SendEvent(eventSent)
require.Equal(t, eventSent, eventReceived, "eventReceived not equal to eventSent: %s %s", eventSent, eventReceived)

View file

@ -24,31 +24,32 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
func init() { proto.RegisterFile("service.proto", fileDescriptor_a0b84a42fa06f626) }
var fileDescriptor_a0b84a42fa06f626 = []byte{
// 369 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x4b, 0x4e, 0xc3, 0x30,
0x10, 0x86, 0x55, 0x21, 0x51, 0xe1, 0x3e, 0x24, 0xbc, 0x01, 0xd2, 0x36, 0xdc, 0xa0, 0x0b, 0xd8,
0xb2, 0x21, 0x15, 0x2a, 0xa8, 0x15, 0x8f, 0x56, 0x80, 0xc4, 0x2e, 0x71, 0x87, 0xca, 0xaa, 0x63,
0x87, 0xd8, 0x2d, 0xea, 0x3d, 0x38, 0x14, 0x4b, 0x8e, 0x80, 0x7a, 0x12, 0x44, 0x6d, 0xe7, 0x9d,
0x9d, 0xf3, 0x7f, 0x33, 0x5f, 0x32, 0x9a, 0x18, 0x75, 0x24, 0xc4, 0x1b, 0x4a, 0x60, 0x18, 0xc5,
0x42, 0x09, 0xdc, 0xf4, 0xf9, 0x56, 0x6d, 0x23, 0x70, 0x3a, 0x3e, 0x21, 0x62, 0xcd, 0x95, 0xce,
0x1d, 0xf4, 0x4e, 0x19, 0xd8, 0x73, 0x48, 0x25, 0x31, 0xe7, 0x56, 0xc0, 0x04, 0x59, 0xe9, 0x87,
0x8b, 0xaf, 0x26, 0xea, 0x8e, 0x18, 0x05, 0xae, 0x46, 0x22, 0x0c, 0x7d, 0xbe, 0x90, 0x78, 0x82,
0xda, 0xaf, 0x3e, 0x63, 0xa0, 0x46, 0x31, 0xf8, 0x0a, 0x70, 0x7f, 0x68, 0x5e, 0x30, 0xcc, 0xc6,
0x33, 0xf8, 0x58, 0x83, 0x54, 0xce, 0xa0, 0x86, 0xca, 0x48, 0x70, 0x09, 0xf8, 0x1e, 0x75, 0x74,
0x3e, 0x03, 0x22, 0x36, 0x10, 0xe3, 0x62, 0xbd, 0xc9, 0xad, 0xce, 0xad, 0xc3, 0xc6, 0xf7, 0x84,
0xba, 0xd7, 0x7a, 0x4a, 0x2b, 0x4c, 0x3b, 0xf2, 0xc0, 0x1a, 0xcf, 0x6b, 0x79, 0xfa, 0x89, 0x86,
0x98, 0x81, 0x07, 0xc5, 0x8e, 0xfc, 0xc4, 0x6e, 0x1d, 0x2e, 0xf9, 0xe6, 0xc0, 0x80, 0xa8, 0xb2,
0x4f, 0xe7, 0xb5, 0x3e, 0x8b, 0x8d, 0x6f, 0x82, 0xda, 0x77, 0xa1, 0xbf, 0x84, 0x31, 0x28, 0x8f,
0x89, 0x20, 0xb3, 0x8f, 0x6c, 0x5c, 0xde, 0x47, 0x9e, 0x1a, 0xd9, 0x0d, 0x42, 0x2f, 0x10, 0x4b,
0x2a, 0xf8, 0x18, 0x14, 0x76, 0x92, 0xe2, 0x34, 0xb4, 0xa2, 0x5e, 0x25, 0x33, 0x9a, 0x2b, 0xd4,
0x9c, 0x8a, 0xe5, 0x1c, 0xf8, 0x02, 0x9f, 0x24, 0x75, 0x26, 0xb1, 0x82, 0xd3, 0x32, 0x30, 0xdd,
0x1e, 0x3a, 0xf2, 0xfe, 0xff, 0xc1, 0x87, 0x08, 0x38, 0x3e, 0x4b, 0xca, 0x92, 0xcc, 0x1a, 0x9c,
0x2a, 0x64, 0x1c, 0xb7, 0xa8, 0xb5, 0x0f, 0xcd, 0xce, 0x7a, 0xf9, 0xd2, 0xfc, 0xc6, 0xfa, 0xd5,
0xb0, 0x60, 0x7a, 0x8e, 0x16, 0x15, 0x26, 0x9d, 0xd6, 0x98, 0x2c, 0x4c, 0x4d, 0x53, 0xca, 0x57,
0x8f, 0x31, 0x6c, 0x28, 0x7c, 0x66, 0x4c, 0x99, 0xb4, 0x6c, 0xca, 0x41, 0x6d, 0xf2, 0x8e, 0xbf,
0x77, 0x6e, 0xe3, 0x67, 0xe7, 0x36, 0x7e, 0x77, 0x6e, 0xe3, 0xed, 0x80, 0xd1, 0x20, 0x38, 0xdc,
0x5f, 0xd8, 0xcb, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x82, 0x8a, 0xe6, 0xfe, 0x03, 0x00,
0x00,
// 396 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x94, 0x4f, 0x4e, 0xf2, 0x40,
0x18, 0x87, 0x21, 0x5f, 0xf2, 0xa1, 0x23, 0x10, 0x33, 0x4b, 0x12, 0x2a, 0xff, 0x8c, 0xae, 0x66,
0xa1, 0x27, 0x10, 0x16, 0x60, 0x82, 0x1a, 0x41, 0x25, 0x92, 0xb8, 0x28, 0xc3, 0x1b, 0xd2, 0x58,
0x66, 0x6a, 0x3b, 0x90, 0x70, 0x0b, 0x6f, 0xe3, 0x15, 0x5c, 0xb2, 0x74, 0x69, 0xe0, 0x22, 0xa6,
0xed, 0xeb, 0x98, 0x96, 0xb6, 0x6c, 0xe7, 0x79, 0x7e, 0x4f, 0xc9, 0x4c, 0x02, 0x29, 0x79, 0xe0,
0x2e, 0x2d, 0x0e, 0xcc, 0x71, 0xa5, 0x92, 0xb4, 0x60, 0x8a, 0x95, 0x5a, 0x39, 0x50, 0x29, 0x73,
0x39, 0x9f, 0x9b, 0x62, 0xea, 0x85, 0xe0, 0xe2, 0xe3, 0x80, 0x94, 0x3b, 0xb6, 0x05, 0x42, 0x75,
0x10, 0xd0, 0x11, 0x29, 0x8e, 0x4c, 0xdb, 0x06, 0xd5, 0x71, 0xc1, 0x54, 0x40, 0x1b, 0x0c, 0xc7,
0x6c, 0xe0, 0x70, 0x16, 0x22, 0x16, 0x32, 0x36, 0x80, 0xb7, 0x05, 0x78, 0xaa, 0xd2, 0xcc, 0x74,
0x3c, 0x47, 0x0a, 0x0f, 0xe8, 0x98, 0x94, 0x42, 0x32, 0x00, 0x2e, 0x97, 0xe0, 0xd2, 0xc4, 0x15,
0x42, 0x9d, 0x6e, 0x65, 0x4b, 0xd8, 0x7e, 0x21, 0xe5, 0x2b, 0xce, 0xe5, 0x42, 0xe8, 0x78, 0x74,
0x87, 0x70, 0xa7, 0x7e, 0xba, 0xc7, 0xfa, 0xfb, 0xe9, 0xc8, 0xf0, 0x52, 0x9a, 0x89, 0xbb, 0xd8,
0xad, 0xb4, 0xb2, 0xa5, 0x9d, 0xf6, 0x10, 0x6c, 0xe0, 0x2a, 0xa5, 0x1d, 0xc2, 0x3d, 0x6d, 0x2d,
0x61, 0xfb, 0x99, 0x14, 0xaf, 0xe7, 0xe6, 0x0c, 0xba, 0xa0, 0xda, 0xb6, 0x9c, 0xc4, 0xd2, 0x01,
0x62, 0x5d, 0x50, 0xcc, 0x87, 0x29, 0xe9, 0x1d, 0x09, 0xd3, 0xf7, 0x84, 0x3c, 0x81, 0xeb, 0x59,
0x52, 0x74, 0x41, 0xd1, 0x5a, 0x64, 0x83, 0x20, 0x58, 0xfd, 0x56, 0xeb, 0x19, 0x06, 0x26, 0x7b,
0xa4, 0xd0, 0x97, 0xb3, 0x21, 0x88, 0x29, 0xad, 0x46, 0xec, 0xbe, 0x9c, 0x31, 0xff, 0x58, 0xc7,
0x8c, 0x34, 0x8c, 0xa5, 0x5b, 0x72, 0xd8, 0xb6, 0x25, 0x7f, 0xbd, 0x73, 0x40, 0xd0, 0x93, 0x88,
0x1c, 0x9c, 0x33, 0x1f, 0xe8, 0x5a, 0x2d, 0x5d, 0xc0, 0xde, 0x03, 0x39, 0x0a, 0x8e, 0xf1, 0xf5,
0xeb, 0x09, 0x83, 0xd8, 0xdb, 0x37, 0xb2, 0x94, 0x58, 0xf5, 0xd1, 0x99, 0xa6, 0x55, 0x43, 0x94,
0x59, 0xd5, 0x0a, 0x56, 0x81, 0x1c, 0x07, 0xa0, 0x67, 0x79, 0x4a, 0xba, 0xab, 0x1b, 0xb9, 0x04,
0x7a, 0x96, 0xb0, 0x43, 0xce, 0x7c, 0x41, 0x7f, 0xe0, 0x7c, 0xbf, 0x18, 0x7e, 0xa6, 0x5d, 0xfd,
0xdc, 0x18, 0xf9, 0xf5, 0xc6, 0xc8, 0x7f, 0x6f, 0x8c, 0xfc, 0xfb, 0xd6, 0xc8, 0xad, 0xb7, 0x46,
0xee, 0x6b, 0x6b, 0xe4, 0xc6, 0xff, 0x6c, 0x6b, 0x32, 0xf9, 0x1f, 0xfc, 0xbf, 0x5c, 0xfe, 0x04,
0x00, 0x00, 0xff, 0xff, 0xfc, 0x61, 0x96, 0x16, 0x89, 0x04, 0x00, 0x00,
}
// This is a compile-time assertion to ensure that this generated file
@ -58,18 +59,18 @@ var fileDescriptor_a0b84a42fa06f626 = []byte{
var clientCommandsHandler ClientCommandsHandler
type ClientCommandsHandler interface {
WalletCreate(*pb.WalletCreateRequest) *pb.WalletCreateResponse
WalletRecover(*pb.WalletRecoverRequest) *pb.WalletRecoverResponse
AccountRecover(*pb.AccountRecoverRequest) *pb.AccountRecoverResponse
AccountCreate(*pb.AccountCreateRequest) *pb.AccountCreateResponse
AccountSelect(*pb.AccountSelectRequest) *pb.AccountSelectResponse
ImageGetBlob(*pb.ImageGetBlobRequest) *pb.ImageGetBlobResponse
VersionGet(*pb.VersionGetRequest) *pb.VersionGetResponse
LogSend(*pb.LogSendRequest) *pb.LogSendResponse
BlockOpen(*pb.BlockOpenRequest) *pb.BlockOpenResponse
BlockCreate(*pb.BlockCreateRequest) *pb.BlockCreateResponse
BlockUpdate(*pb.BlockUpdateRequest) *pb.BlockUpdateResponse
LinkPreview(*pb.LinkPreviewRequest) *pb.LinkPreviewResponse
WalletCreate(*pb.RpcWalletCreateRequest) *pb.RpcWalletCreateResponse
WalletRecover(*pb.RpcWalletRecoverRequest) *pb.RpcWalletRecoverResponse
AccountRecover(*pb.RpcAccountRecoverRequest) *pb.RpcAccountRecoverResponse
AccountCreate(*pb.RpcAccountCreateRequest) *pb.RpcAccountCreateResponse
AccountSelect(*pb.RpcAccountSelectRequest) *pb.RpcAccountSelectResponse
ImageGetBlob(*pb.RpcImageGetBlobRequest) *pb.RpcImageGetBlobResponse
VersionGet(*pb.RpcVersionGetRequest) *pb.RpcVersionGetResponse
LogSend(*pb.RpcLogSendRequest) *pb.RpcLogSendResponse
BlockOpen(*pb.RpcBlockOpenRequest) *pb.RpcBlockOpenResponse
BlockCreate(*pb.RpcBlockCreateRequest) *pb.RpcBlockCreateResponse
BlockUpdate(*pb.RpcBlockUpdateRequest) *pb.RpcBlockUpdateResponse
BlockHistoryMove(*pb.RpcBlockHistoryMoveRequest) *pb.RpcBlockHistoryMoveResponse
}
func registerClientCommandsHandler(srv ClientCommandsHandler) {
@ -77,9 +78,9 @@ func registerClientCommandsHandler(srv ClientCommandsHandler) {
}
func WalletCreate(b []byte) []byte {
in := new(pb.WalletCreateRequest)
in := new(pb.RpcWalletCreateRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.WalletCreateResponse{Error: &pb.WalletCreateResponse_Error{Code: pb.WalletCreateResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcWalletCreateResponse{Error: &pb.RpcWalletCreateResponseError{Code: pb.RpcWalletCreateResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.WalletCreate(in).Marshal()
@ -87,9 +88,9 @@ func WalletCreate(b []byte) []byte {
}
func WalletRecover(b []byte) []byte {
in := new(pb.WalletRecoverRequest)
in := new(pb.RpcWalletRecoverRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.WalletRecoverResponse{Error: &pb.WalletRecoverResponse_Error{Code: pb.WalletRecoverResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcWalletRecoverResponse{Error: &pb.RpcWalletRecoverResponseError{Code: pb.RpcWalletRecoverResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.WalletRecover(in).Marshal()
@ -97,9 +98,9 @@ func WalletRecover(b []byte) []byte {
}
func AccountRecover(b []byte) []byte {
in := new(pb.AccountRecoverRequest)
in := new(pb.RpcAccountRecoverRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.AccountRecoverResponse{Error: &pb.AccountRecoverResponse_Error{Code: pb.AccountRecoverResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcAccountRecoverResponse{Error: &pb.RpcAccountRecoverResponseError{Code: pb.RpcAccountRecoverResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.AccountRecover(in).Marshal()
@ -107,9 +108,9 @@ func AccountRecover(b []byte) []byte {
}
func AccountCreate(b []byte) []byte {
in := new(pb.AccountCreateRequest)
in := new(pb.RpcAccountCreateRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.AccountCreateResponse{Error: &pb.AccountCreateResponse_Error{Code: pb.AccountCreateResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcAccountCreateResponse{Error: &pb.RpcAccountCreateResponseError{Code: pb.RpcAccountCreateResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.AccountCreate(in).Marshal()
@ -117,9 +118,9 @@ func AccountCreate(b []byte) []byte {
}
func AccountSelect(b []byte) []byte {
in := new(pb.AccountSelectRequest)
in := new(pb.RpcAccountSelectRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.AccountSelectResponse{Error: &pb.AccountSelectResponse_Error{Code: pb.AccountSelectResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcAccountSelectResponse{Error: &pb.RpcAccountSelectResponseError{Code: pb.RpcAccountSelectResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.AccountSelect(in).Marshal()
@ -127,9 +128,9 @@ func AccountSelect(b []byte) []byte {
}
func ImageGetBlob(b []byte) []byte {
in := new(pb.ImageGetBlobRequest)
in := new(pb.RpcImageGetBlobRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.ImageGetBlobResponse{Error: &pb.ImageGetBlobResponse_Error{Code: pb.ImageGetBlobResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcImageGetBlobResponse{Error: &pb.RpcImageGetBlobResponseError{Code: pb.RpcImageGetBlobResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.ImageGetBlob(in).Marshal()
@ -137,9 +138,9 @@ func ImageGetBlob(b []byte) []byte {
}
func VersionGet(b []byte) []byte {
in := new(pb.VersionGetRequest)
in := new(pb.RpcVersionGetRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.VersionGetResponse{Error: &pb.VersionGetResponse_Error{Code: pb.VersionGetResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcVersionGetResponse{Error: &pb.RpcVersionGetResponseError{Code: pb.RpcVersionGetResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.VersionGet(in).Marshal()
@ -147,9 +148,9 @@ func VersionGet(b []byte) []byte {
}
func LogSend(b []byte) []byte {
in := new(pb.LogSendRequest)
in := new(pb.RpcLogSendRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.LogSendResponse{Error: &pb.LogSendResponse_Error{Code: pb.LogSendResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcLogSendResponse{Error: &pb.RpcLogSendResponseError{Code: pb.RpcLogSendResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.LogSend(in).Marshal()
@ -157,9 +158,9 @@ func LogSend(b []byte) []byte {
}
func BlockOpen(b []byte) []byte {
in := new(pb.BlockOpenRequest)
in := new(pb.RpcBlockOpenRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.BlockOpenResponse{Error: &pb.BlockOpenResponse_Error{Code: pb.BlockOpenResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcBlockOpenResponse{Error: &pb.RpcBlockOpenResponseError{Code: pb.RpcBlockOpenResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.BlockOpen(in).Marshal()
@ -167,9 +168,9 @@ func BlockOpen(b []byte) []byte {
}
func BlockCreate(b []byte) []byte {
in := new(pb.BlockCreateRequest)
in := new(pb.RpcBlockCreateRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.BlockCreateResponse{Error: &pb.BlockCreateResponse_Error{Code: pb.BlockCreateResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcBlockCreateResponse{Error: &pb.RpcBlockCreateResponseError{Code: pb.RpcBlockCreateResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.BlockCreate(in).Marshal()
@ -177,22 +178,22 @@ func BlockCreate(b []byte) []byte {
}
func BlockUpdate(b []byte) []byte {
in := new(pb.BlockUpdateRequest)
in := new(pb.RpcBlockUpdateRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.BlockUpdateResponse{Error: &pb.BlockUpdateResponse_Error{Code: pb.BlockUpdateResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcBlockUpdateResponse{Error: &pb.RpcBlockUpdateResponseError{Code: pb.RpcBlockUpdateResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.BlockUpdate(in).Marshal()
return resp
}
func LinkPreview(b []byte) []byte {
in := new(pb.LinkPreviewRequest)
func BlockHistoryMove(b []byte) []byte {
in := new(pb.RpcBlockHistoryMoveRequest)
if err := in.Unmarshal(b); err != nil {
resp, _ := (&pb.LinkPreviewResponse{Error: &pb.LinkPreviewResponse_Error{Code: pb.LinkPreviewResponse_Error_BAD_INPUT, Description: err.Error()}}).Marshal()
resp, _ := (&pb.RpcBlockHistoryMoveResponse{Error: &pb.RpcBlockHistoryMoveResponseError{Code: pb.RpcBlockHistoryMoveResponseError_BAD_INPUT, Description: err.Error()}}).Marshal()
return resp
}
resp, _ := clientCommandsHandler.LinkPreview(in).Marshal()
resp, _ := clientCommandsHandler.BlockHistoryMove(in).Marshal()
return resp
}
@ -222,8 +223,8 @@ func CommandAsync(cmd string, data []byte, callback func(data []byte)) {
cd = BlockCreate(data)
case "BlockUpdate":
cd = BlockUpdate(data)
case "LinkPreview":
cd = LinkPreview(data)
case "BlockHistoryMove":
cd = BlockHistoryMove(data)
default:
log.Errorf("unknown command type: %s\n", cmd)
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

3560
pb/changes.pb.go Normal file

File diff suppressed because it is too large Load diff

12667
pb/commands.pb.go Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,630 +0,0 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: event.proto
package pb
import (
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type Event struct {
// Types that are valid to be assigned to Message:
// *Event_AccountShow
// *Event_BlockShow
// *Event_BlockUpdate
// *Event_BlockCreate
Message isEvent_Message `protobuf_oneof:"message"`
}
func (m *Event) Reset() { *m = Event{} }
func (m *Event) String() string { return proto.CompactTextString(m) }
func (*Event) ProtoMessage() {}
func (*Event) Descriptor() ([]byte, []int) {
return fileDescriptor_2d17a9d3f0ddf27e, []int{0}
}
func (m *Event) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Event.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Event) XXX_Merge(src proto.Message) {
xxx_messageInfo_Event.Merge(m, src)
}
func (m *Event) XXX_Size() int {
return m.Size()
}
func (m *Event) XXX_DiscardUnknown() {
xxx_messageInfo_Event.DiscardUnknown(m)
}
var xxx_messageInfo_Event proto.InternalMessageInfo
type isEvent_Message interface {
isEvent_Message()
MarshalTo([]byte) (int, error)
Size() int
}
type Event_AccountShow struct {
AccountShow *AccountShow `protobuf:"bytes,1,opt,name=accountShow,proto3,oneof" json:"accountShow,omitempty"`
}
type Event_BlockShow struct {
BlockShow *BlockShow `protobuf:"bytes,2,opt,name=blockShow,proto3,oneof" json:"blockShow,omitempty"`
}
type Event_BlockUpdate struct {
BlockUpdate *BlockUpdate `protobuf:"bytes,3,opt,name=blockUpdate,proto3,oneof" json:"blockUpdate,omitempty"`
}
type Event_BlockCreate struct {
BlockCreate *BlockCreate `protobuf:"bytes,4,opt,name=blockCreate,proto3,oneof" json:"blockCreate,omitempty"`
}
func (*Event_AccountShow) isEvent_Message() {}
func (*Event_BlockShow) isEvent_Message() {}
func (*Event_BlockUpdate) isEvent_Message() {}
func (*Event_BlockCreate) isEvent_Message() {}
func (m *Event) GetMessage() isEvent_Message {
if m != nil {
return m.Message
}
return nil
}
func (m *Event) GetAccountShow() *AccountShow {
if x, ok := m.GetMessage().(*Event_AccountShow); ok {
return x.AccountShow
}
return nil
}
func (m *Event) GetBlockShow() *BlockShow {
if x, ok := m.GetMessage().(*Event_BlockShow); ok {
return x.BlockShow
}
return nil
}
func (m *Event) GetBlockUpdate() *BlockUpdate {
if x, ok := m.GetMessage().(*Event_BlockUpdate); ok {
return x.BlockUpdate
}
return nil
}
func (m *Event) GetBlockCreate() *BlockCreate {
if x, ok := m.GetMessage().(*Event_BlockCreate); ok {
return x.BlockCreate
}
return nil
}
// XXX_OneofWrappers is for the internal use of the proto package.
func (*Event) XXX_OneofWrappers() []interface{} {
return []interface{}{
(*Event_AccountShow)(nil),
(*Event_BlockShow)(nil),
(*Event_BlockUpdate)(nil),
(*Event_BlockCreate)(nil),
}
}
func init() {
proto.RegisterType((*Event)(nil), "anytype.Event")
}
func init() { proto.RegisterFile("event.proto", fileDescriptor_2d17a9d3f0ddf27e) }
var fileDescriptor_2d17a9d3f0ddf27e = []byte{
// 209 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0x2d, 0x4b, 0xcd,
0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4f, 0xcc, 0xab, 0x2c, 0xa9, 0x2c, 0x48,
0x95, 0xe2, 0x4d, 0x4c, 0x4e, 0xce, 0x2f, 0x85, 0x89, 0x4b, 0x71, 0x27, 0xe5, 0xe4, 0x27, 0x67,
0x43, 0x38, 0x4a, 0x5f, 0x18, 0xb9, 0x58, 0x5d, 0x41, 0x9a, 0x84, 0x2c, 0xb8, 0xb8, 0xa1, 0xea,
0x82, 0x33, 0xf2, 0xcb, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x44, 0xf4, 0xa0, 0x86, 0xe8,
0x39, 0x22, 0xe4, 0x3c, 0x18, 0x82, 0x90, 0x95, 0x0a, 0x19, 0x71, 0x71, 0x82, 0x8d, 0x04, 0xeb,
0x63, 0x02, 0xeb, 0x13, 0x82, 0xeb, 0x73, 0x82, 0xc9, 0x78, 0x30, 0x04, 0x21, 0x94, 0x81, 0x6c,
0x03, 0x73, 0x42, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0x25, 0x98, 0xd1, 0x6c, 0x73, 0x42, 0xc8, 0x81,
0x6c, 0x43, 0x52, 0x0a, 0xd7, 0xe9, 0x5c, 0x94, 0x0a, 0xd2, 0xc9, 0x82, 0x4d, 0x27, 0x44, 0x0e,
0xae, 0x13, 0xc2, 0x75, 0xe2, 0xe4, 0x62, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f, 0x75, 0x92,
0x39, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96,
0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xa6, 0x82, 0xa4, 0x24, 0x36,
0x70, 0xd8, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x58, 0xcc, 0xa8, 0x8c, 0x4f, 0x01, 0x00,
0x00,
}
func (m *Event) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Event) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Event) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Message != nil {
{
size := m.Message.Size()
i -= size
if _, err := m.Message.MarshalTo(dAtA[i:]); err != nil {
return 0, err
}
}
}
return len(dAtA) - i, nil
}
func (m *Event_AccountShow) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Event_AccountShow) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.AccountShow != nil {
{
size, err := m.AccountShow.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintEvent(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Event_BlockShow) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Event_BlockShow) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.BlockShow != nil {
{
size, err := m.BlockShow.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintEvent(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
return len(dAtA) - i, nil
}
func (m *Event_BlockUpdate) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Event_BlockUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.BlockUpdate != nil {
{
size, err := m.BlockUpdate.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintEvent(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
}
return len(dAtA) - i, nil
}
func (m *Event_BlockCreate) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Event_BlockCreate) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
if m.BlockCreate != nil {
{
size, err := m.BlockCreate.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintEvent(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x22
}
return len(dAtA) - i, nil
}
func encodeVarintEvent(dAtA []byte, offset int, v uint64) int {
offset -= sovEvent(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *Event) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Message != nil {
n += m.Message.Size()
}
return n
}
func (m *Event_AccountShow) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.AccountShow != nil {
l = m.AccountShow.Size()
n += 1 + l + sovEvent(uint64(l))
}
return n
}
func (m *Event_BlockShow) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.BlockShow != nil {
l = m.BlockShow.Size()
n += 1 + l + sovEvent(uint64(l))
}
return n
}
func (m *Event_BlockUpdate) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.BlockUpdate != nil {
l = m.BlockUpdate.Size()
n += 1 + l + sovEvent(uint64(l))
}
return n
}
func (m *Event_BlockCreate) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.BlockCreate != nil {
l = m.BlockCreate.Size()
n += 1 + l + sovEvent(uint64(l))
}
return n
}
func sovEvent(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozEvent(x uint64) (n int) {
return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *Event) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvent
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Event: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Event: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AccountShow", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvent
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthEvent
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthEvent
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &AccountShow{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Message = &Event_AccountShow{v}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BlockShow", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvent
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthEvent
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthEvent
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &BlockShow{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Message = &Event_BlockShow{v}
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BlockUpdate", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvent
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthEvent
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthEvent
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &BlockUpdate{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Message = &Event_BlockUpdate{v}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BlockCreate", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowEvent
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthEvent
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthEvent
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &BlockCreate{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
m.Message = &Event_BlockCreate{v}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipEvent(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthEvent
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthEvent
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipEvent(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowEvent
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowEvent
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowEvent
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthEvent
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupEvent
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthEvent
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthEvent = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowEvent = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupEvent = fmt.Errorf("proto: unexpected end of group")
)

3456
pb/events.pb.go Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

8187
pb/models.pb.go Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,175 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "file.proto";
message Avatar {
oneof avatar {
Image image = 1;
string color = 2;
}
}
message Account {
string id = 1;
string name = 2;
Avatar avatar = 3;
}
message WalletCreateRequest {
string rootPath = 1;
}
message WalletCreateResponse {
Error error = 1;
string mnemonic = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
FAILED_TO_CREATE_LOCAL_REPO = 101;
// ...
}
}
}
message WalletRecoverRequest {
string rootPath = 1;
string mnemonic = 2;
}
message WalletRecoverResponse {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
FAILED_TO_CREATE_LOCAL_REPO = 101;
}
}
}
message AccountCreateRequest {
string name = 1;
oneof avatar {
string avatarLocalPath = 2;
string avatarColor = 3;
}
}
message AccountCreateResponse {
Error error = 1;
Account account = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE = 101;
ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME = 102;
ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR = 103;
}
}
}
// Start accounts search for recovered mnemonic
message AccountRecoverRequest {}
// Found accounts will come in event AccountAdd
message AccountRecoverResponse {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NO_ACCOUNTS_FOUND = 101;
NEED_TO_RECOVER_WALLET_FIRST = 102;
FAILED_TO_CREATE_LOCAL_REPO = 103;
LOCAL_REPO_EXISTS_BUT_CORRUPTED = 104;
FAILED_TO_RUN_NODE = 105;
}
}
}
message AccountSelectRequest {
string id = 1;
// optional, set if this is the first request
string rootPath = 2;
}
message AccountSelectResponse {
Error error = 1;
Account account = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
FAILED_TO_CREATE_LOCAL_REPO = 101;
LOCAL_REPO_EXISTS_BUT_CORRUPTED = 102;
FAILED_TO_RUN_NODE = 103;
FAILED_TO_FIND_ACCOUNT_INFO = 104;
LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET = 105;
}
}
}
message AccountStartRequest {
string id = 1;
}
message AccountStartResponse {
Error error = 1;
Account account = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
LOCAL_REPO_DOESNT_EXIST = 101;
LOCAL_REPO_EXISTS_BUT_CORRUPTED = 102;
FAILED_TO_RUN_NODE = 103;
FAILED_TO_FIND_ACCOUNT_INFO = 104;
}
}
}
message AccountShow {
int64 index = 1;
Account account = 2;
}

View file

@ -1,349 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "struct.proto";
// commands
//
message BlockOpenRequest {
string id = 1;
}
message BlockOpenResponse {
Error error = 1;
BlockHeader blockHeader = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
message BlockCreateRequest {
BlockType type = 1;
}
message BlockCreateResponse {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
message BlockUpdateRequest {
BlockChanges changes = 1;
}
message BlockUpdateResponse {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
// events
//
// call
message BlockShow {
Block block = 1;
}
message BlockUpdate {
BlockChanges changes = 1;
}
message BlockCreate {
Block block = 1;
}
message BlockContentTextChange {
oneof change {
string text = 1;
BlockContentText.Style style = 2;
BlockContentText.Marks marks = 3;
bool toggleable = 4;
BlockContentText.MarkerType markerType = 5;
bool checkable = 6;
bool checked = 7;
}
}
message BlockContentPageChange {
oneof change {
BlockContentPage.Style style = 1;
BlockConnectionsList structure = 2;
BlocksList blocks = 3;
}
}
message BlockHeaderChange {
oneof change {
string id = 1;
BlockType type = 2;
string name = 3;
string icon = 4;
BlockPermissions permissions = 5;
}
}
message BlockContentDashboardChange {
oneof change {
BlockContentDashboard.Style style = 1;
BlockConnectionsList structure = 2;
BlockHeadersList headers = 3;
}
}
message BlockAtomicChange {
string id = 1;
oneof change {
BlockContentTextChange text = 2;
BlockHeaderChange blockHeader = 3;
BlockContentPageChange page = 4;
BlockContentDashboardChange dashboard = 5;
}
}
message BlockChanges {
repeated BlockAtomicChange changes = 1;
}
// models
//
message Block {
BlockHeader header = 1;
oneof content {
BlockContentDashboard dashboard = 11;
BlockContentPage page = 12;
BlockContentDataview dataview = 13;
BlockContentText text = 14;
BlockContentMedia media = 15;
}
}
message BlockHeader {
string id = 1;
BlockType type = 2;
Struct fields = 3;
BlockPermissions permissions = 4;
}
message BlockPermissions {
bool read = 1;
bool edit = 2;
bool remove = 3;
bool drag = 4;
bool dropOn = 5;
}
enum BlockType {
DASHBOARD = 0;
PAGE = 1;
DATAVIEW = 2;
TEXT = 3;
FILE = 4;
PICTURE = 5;
VIDEO = 6;
}
message BlockConnections {
string id = 1;
string next = 2;
string columnBottom = 3;
string rowRight = 4;
string inner = 5;
}
message BlockConnectionsList {
repeated BlockConnections structure = 1;
}
message BlockHeadersList {
repeated BlockHeader headers = 1;
}
message BlocksList {
repeated Block blocks = 1;
}
message BlockContentPage {
enum Style {
EMPTY = 0;
TASK = 1;
BOOKMARK = 2;
SET = 3;
// ...
}
Style style = 1;
BlockConnectionsList structure = 2;
BlocksList blocks = 3;
}
message BlockContentDashboard {
enum Style {
MAIN_SCREEN = 0;
// ...
}
Style style = 1;
BlockConnectionsList structure = 2;
BlockHeadersList headers = 3;
}
message BlockContentDataview {
// ...
}
message BlockContentText {
enum Style {
p = 0;
h1 = 1;
h2 = 2;
h3 = 3;
h4 = 4;
quote = 5;
}
enum MarkerType {
none = 0;
number = 1;
bullet = 2;
}
message Marks {
repeated Mark marks = 1;
}
message Mark {
enum Type {
STRIKETHROUGH = 0;
KEYBOARD = 1;
ITALIC = 2;
BOLD = 3;
LINK = 4;
}
Range range = 1;
Type type = 2;
string param = 3; // link, color, etc
}
string text = 1;
Style style = 2;
Marks marksList = 3;
bool toggleable = 4;
MarkerType markerType = 5;
bool checkable = 6;
bool checked = 7;
}
message BlockContentMedia {
string link = 1;
}
message Range {
int32 from = 1;
int32 to = 2;
}
/*
message Scheme {
oneof scheme {
PageScheme pageScheme = 1;
DataviewScheme dataviewScheme = 2;
}
}
message DataviewScheme {
// ...
}
message PageScheme {
BlockHeader header = 1;
BlockConnectionsList structure = 2;
BlockHeadersList headers = 3;
}
message BlockContentPreview {
oneof preview {
bool noPreview = 1;
ImagePreview imagePreview = 2;
VideoPreview videoPreview = 3;
FilePreview filePreview = 4;
TextPreview textPreview = 5;
EmptyPagePreview emptyPagePreview = 6;
TaskPagePreview taskPagePreview = 7;
}
}
message ImagePreview {
string name = 1;
int32 height = 2;
int32 width = 3;
}
message VideoPreview {
string name = 1;
int32 height = 2;
int32 width = 3;
}
message FilePreview {
string name = 1;
string icon = 2;
}
message TextPreview {
int32 symblos = 1;
BlockContentText.Style style = 2;
}
message EmptyPagePreview {
string name = 1;
string icon = 2;
}
message TaskPagePreview {
string header = 1;
string assignee = 2;
// ...
}
*/

78
pb/protos/changes.proto Normal file
View file

@ -0,0 +1,78 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "models.proto";
message Change {
message Block {
message Header {
oneof change {
string id = 1;
Model.Block.Header.Type type = 2;
string name = 3;
string icon = 4;
Model.Block.Header.Permissions permissions = 5;
}
}
message Children {
repeated string children = 1;
}
message Content {
message Page {
oneof change {
Model.Block.Content.Page.Style style = 1;
Model.Block block = 2;
}
}
message Dashboard {
oneof change {
Model.Block.Content.Dashboard.Style style = 1;
Model.Block.Header header = 2; // not a dashboard header  one of children
}
}
message Media {
oneof change {
string link = 1;
Model.Block.Content.Media.State state = 2;
}
}
message Text {
oneof change {
string text = 1;
Model.Block.Content.Text.Style style = 2;
Model.Block.Content.Text.Marks marks = 3;
bool toggleable = 4;
Model.Block.Content.Text.MarkerType markerType = 5;
bool checkable = 6;
bool checked = 7;
}
}
}
}
}
message BlocksListSingleChange {
repeated string id = 1;
oneof change {
Change.Block.Content.Text text = 2;
Change.Block.Header blockHeader = 3;
Change.Block.Children blockChildren = 4;
Change.Block.Content.Page page = 5;
Change.Block.Content.Dashboard dashboard = 6;
Change.Block.Content.Media media = 7;
}
}
message BlockChanges {
repeated BlocksListSingleChange changes = 1;
}

424
pb/protos/commands.proto Normal file
View file

@ -0,0 +1,424 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "models.proto";
import "changes.proto";
message Rpc {
message Block {
message History {
message Move {
message Request {
string id = 1;
string contextBlockId = 2;
bool moveForward = 3;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
CAN_NOT_MOVE = 3;
// ...
}
}
}
}
}
message Open {
message Request {
string id = 1;
}
message Response {
Error error = 1;
Model.Block.Header blockHeader = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message Create {
message Request {
Model.Block.Header.Type type = 1;
string contextBlockId = 2;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message Update {
message Request {
BlockChanges changes = 1;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
}
message Wallet {
message Create {
/**
* Front-end-to-middleware request to create a new wallet
*/
message Request {
string rootPath = 1; // Path to a wallet directory
}
/**
* Middleware-to-front-end response, that can contain mnemonic of a created account and a NULL error or an empty mnemonic and a non-NULL error
*/
message Response {
Error error = 1;
string mnemonic = 2; // Mnemonic of a new account (sequence of words, divided by spaces)
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0; // No error; mnemonic should be non-empty
UNKNOWN_ERROR = 1; // Any other errors
BAD_INPUT = 2; // Root path is wrong
FAILED_TO_CREATE_LOCAL_REPO = 101;
// ...
}
}
}
}
message Recover {
/**
* Front end to middleware request-to-recover-a wallet with this mnemonic and a rootPath
*/
message Request {
string rootPath = 1; // Path to a wallet directory
string mnemonic = 2; // Mnemonic of a wallet to recover
}
/**
* Middleware-to-front-end response, that can contain a NULL error or a non-NULL error
*/
message Response {
Error error = 1; // Error while trying to recover a wallet
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0; // No error; wallet successfully recovered
UNKNOWN_ERROR = 1; // Any other errors
BAD_INPUT = 2; // Root path or mnemonic is wrong
FAILED_TO_CREATE_LOCAL_REPO = 101;
}
}
}
}
}
message Account {
message Create {
/**
* Front end to middleware request-to-create-an account
*/
message Request {
string name = 1; // Account name
oneof avatar {
string avatarLocalPath = 2; // Path to an image, that will be used as an avatar of this account
string avatarColor = 3; // Avatar color as an alternative for avatar image
}
}
/**
* Middleware-to-front-end response for an account creation request, that can contain a NULL error and created account or a non-NULL error and an empty account
*/
message Response {
Error error = 1; // Error while trying to create an account
Model.Account account = 2; // A newly created account; In case of a failure, i.e. error is non-NULL, the account model should contain empty/default-value fields
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0; // No error; Account should be non-empty
UNKNOWN_ERROR = 1; // Any other errors
BAD_INPUT = 2; // Avatar or name is not correct
ACCOUNT_CREATED_BUT_FAILED_TO_START_NODE = 101;
ACCOUNT_CREATED_BUT_FAILED_TO_SET_NAME = 102;
ACCOUNT_CREATED_BUT_FAILED_TO_SET_AVATAR = 103;
}
}
}
}
message Recover {
/**
* Front end to middleware request-to-start-search of an accounts for a recovered mnemonic.
* Each of an account that would be found will come with an AccountAdd event
*/
message Request {}
/**
* Middleware-to-front-end response to an account recover request, that can contain a NULL error and created account or a non-NULL error and an empty account
*/
message Response {
Error error = 1; // Error while trying to recover an account
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0; // No error;
UNKNOWN_ERROR = 1; // Any other errors
BAD_INPUT = 2;
NO_ACCOUNTS_FOUND = 101;
NEED_TO_RECOVER_WALLET_FIRST = 102;
FAILED_TO_CREATE_LOCAL_REPO = 103;
LOCAL_REPO_EXISTS_BUT_CORRUPTED = 104;
FAILED_TO_RUN_NODE = 105;
WALLET_RECOVER_NOT_PERFORMED = 106;
}
}
}
}
message Select {
/**
* Front end to middleware request-to-launch-a specific account using account id and a root path
* User can select an account from those, that came with an AccountAdd events
*/
message Request {
string id = 1; // Id of a selected account
string rootPath = 2; // Root path is optional, set if this is a first request
}
/**
* Middleware-to-front-end response for an account select request, that can contain a NULL error and selected account or a non-NULL error and an empty account
*/
message Response {
Error error = 1; // Error while trying to launch/select an account
Model.Account account = 2; // Selected account
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0; // No error
UNKNOWN_ERROR = 1; // Any other errors
BAD_INPUT = 2; // Id or root path is wrong
FAILED_TO_CREATE_LOCAL_REPO = 101;
LOCAL_REPO_EXISTS_BUT_CORRUPTED = 102;
FAILED_TO_RUN_NODE = 103;
FAILED_TO_FIND_ACCOUNT_INFO = 104;
LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET = 105;
}
}
}
}
}
message Version {
message Get {
message Request {}
message Response {
Error error = 1;
string version = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
VERSION_IS_EMPTY = 3;
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
}
}
message Log {
message Send {
message Request {
string message = 1;
Level level = 2;
enum Level {
DEBUG = 0;
ERROR = 1;
FATAL = 2;
INFO = 3;
PANIC = 4;
WARNING = 5;
}
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
}
}
message Ipfs {
message Get {
message File {
message Request {
string id = 1;
}
message Response {
Error error = 1;
bytes data = 2;
string media = 3;
string name = 4;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
}
}
}
message Image {
message Get {
message Blob {
message Request {
string id = 1;
Model.Image.Size size = 2;
}
message Response {
Error error = 1;
bytes blob = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
}
message File {
message Request {
string id = 1;
Model.Image.Size size = 2;
}
message Response {
Error error = 1;
string localPath = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
}
}
}
}

View file

@ -1,30 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "block.proto";
import "account.proto";
message UserBlockTextRange {
Account account = 1;
string blockId = 2;
Range range = 3;
}
message UserBlockJoin {
Account account = 1;
}
message UserBlockLeft {
Account account = 1;
}
message UserBlockSelectRange {
Account account = 1;
repeated string blockIdsArray = 2;
}
message UserBlockFocus {
Account account = 1;
string blockId = 2;
}

View file

@ -1,23 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "account.proto";
import "block.proto";
message Event {
oneof message {
// show wallet's accounts that were loaded from local or remote source
AccountShow accountShow = 1;
BlockShow blockShow = 2;
BlockUpdate blockUpdate = 3;
BlockCreate blockCreate = 4;
// unit was rearranged. Need to update the position
// UnitMoved unitMoved = 104;
// unit was renamed or icon was changed
//UnitRenamed unitRenamed = 105;
}
}

105
pb/protos/events.proto Normal file
View file

@ -0,0 +1,105 @@
syntax="proto3";
package anytype;
option go_package = "pb";
import "models.proto";
import "changes.proto";
message Event {
oneof message {
Account.Show accountShow = 1; // show wallet's accounts that were loaded from local or remote source
Block.Show blockShow = 2;
Block.Update blockUpdate = 3;
Block.Create blockCreate = 4;
User.Block.TextRange userBlockTextRange = 5;
User.Block.Join userBlockJoin = 6;
User.Block.Left userBlockLeft = 7;
User.Block.SelectRange userBlockSelectRange = 8;
Block.FilesUpload filesUpload = 9;
}
message Account {
/**
* Message, that will be sent to the front on each account found after an AccountRecoverRequest
*/
message Show {
int64 index = 1; // Number of an account in an all found accounts list
Model.Account account = 2; // An Account, that has been found for the mnemonic
}
}
message Block {
message Show {
Model.Block block = 1;
}
message Update {
BlockChanges changes = 1;
}
message Create {
Model.Block block = 1;
}
/**
* Middleware to front end event message, that will be sent on one of this scenarios:
* Precondition: user A opened a block
* 1. User A drops a set of files/pictures/videos
* 2. User A creates a MediaBlock and drops a single media, that corresponds to its type.
*/
message FilesUpload {
repeated string filePath = 1; // filepaths to the files
string blockId = 2; // if empty => create new blocks
}
}
message User {
message Block {
/**
* Middleware to front end event message, that will be sent in this scenario:
* Precondition: user A opened a block
* 1. User B opens the same block
* 2. User A receives a message about p.1
*/
message Join {
Account account = 1; // Account of the user, that opened a block
}
/**
* Middleware to front end event message, that will be sent in this scenario:
* Precondition: user A and user B opened the same block
* 1. User B closes the block
* 2. User A receives a message about p.1
*/
message Left {
Account account = 1; // Account of the user, that left the block
}
/**
* Middleware to front end event message, that will be sent in this scenario:
* Precondition: user A and user B opened the same block
* 1. User B sets cursor or selects a text region into a text block
* 2. User A receives a message about p.1
*/
message TextRange {
Account account = 1; // Account of the user, that selected a text
string blockId = 2; // Id of the text block, that have a selection
Model.Range range = 3; // Range of the selection
}
/**
* Middleware to front end event message, that will be sent in this scenario:
* Precondition: user A and user B opened the same block
* 1. User B selects some inner blocks
* 2. User A receives a message about p.1
*/
message SelectRange {
Account account = 1; // Account of the user, that selected blocks
repeated string blockIdsArray = 2; // Ids of selected blocks.
}
}
}
}

View file

@ -1,103 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
enum ImageSize {
LARGE = 0;
SMALL = 1;
THUMB = 2;
}
message Image {
string id = 1;
repeated ImageSize sizes = 2;
}
enum VideoSize {
SD_360p = 0;
SD_480p = 1;
HD_720p = 2;
HD_1080p = 3;
UHD_1440p = 4;
UHD_2160p = 5;
}
message Video {
string id = 1;
repeated VideoSize sizes = 2;
}
message IpfsGetFileRequest {
string id = 1;
}
message IpfsGetFileResponse {
Error error = 1;
bytes data = 2;
string media = 3;
string name = 4;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
message ImageGetBlobRequest {
string id = 1;
ImageSize size = 2;
}
message ImageGetBlobResponse {
Error error = 1;
bytes blob = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
message ImageGetFileRequest {
string id = 1;
ImageSize size = 2;
}
message ImageGetFileResponse {
Error error = 1;
string localPath = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}

View file

@ -1,93 +0,0 @@
syntax = "proto3";
package anytype;
option go_package = "pb";
message VersionGetRequest {}
message VersionGetResponse {
Error error = 1;
// version is generate by git describe
string version = 2;
string details = 3;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
VERSION_IS_EMPTY = 3;
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
message LogSendRequest {
string message = 1;
Level level = 2;
enum Level {
DEBUG = 0;
ERROR = 1;
FATAL = 2;
INFO = 3;
PANIC = 4;
WARNING = 5;
}
}
message LogSendResponse {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_FOUND = 101;
TIMEOUT = 102;
}
}
}
message LinkPreviewRequest {
string url = 1;
}
message LinkPreviewResponse {
Error error = 1;
string title = 2;
string description = 3;
string imageUrl = 4;
string url = 5;
string faviconUrl = 6;
Type type = 7;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
TIMEOUT = 102;
}
}
enum Type {
PAGE = 0;
IMAGE = 1;
TEXT = 2;
UNEXPECTED = 3;
}
}

272
pb/protos/models.proto Normal file
View file

@ -0,0 +1,272 @@
syntax = "proto3";
package anytype;
option go_package = "pb";
message Model {
message Block {
Header header = 1;
repeated string children = 2;
oneof content {
Content.Dashboard dashboard = 11;
Content.Page page = 12;
Content.Dataview dataview = 13;
Content.Text text = 14;
Content.Media media = 15;
Content.Layout layout = 16;
Content.Div div = 17;
}
message Header {
string id = 1;
Type type = 2;
Struct fields = 3;
Permissions permissions = 4;
message Permissions {
bool read = 1;
bool edit = 2;
bool remove = 3;
bool drag = 4;
bool dropOn = 5;
}
enum Type {
DASHBOARD = 0;
PAGE = 1;
DATAVIEW = 2;
TEXT = 3;
FILE = 4;
PICTURE = 5;
VIDEO = 6;
BOOKMARK = 7;
LAYOUT = 8;
DIV = 9;
}
}
message Content {
message Layout {
Style style = 1;
enum Style {
ROW = 0;
COLUMN = 1;
}
}
message Div {
}
message Dashboard {
enum Style {
MAIN_SCREEN = 0;
// ...
}
Style style = 1;
repeated Header headers = 2;
}
message Dataview {
// ...
}
message Text {
enum Style {
p = 0;
h1 = 1;
h2 = 2;
h3 = 3;
h4 = 4;
quote = 5;
code = 6;
}
enum MarkerType {
none = 0;
number = 1;
bullet = 2;
}
message Marks {
repeated Mark marks = 1;
}
message Mark {
enum Type {
STRIKETHROUGH = 0;
KEYBOARD = 1;
ITALIC = 2;
BOLD = 3;
LINK = 4;
}
Range range = 1;
Type type = 2;
string param = 3; // link, color, etc
}
string text = 1;
Style style = 2;
Marks marksList = 3;
bool toggleable = 4;
MarkerType markerType = 5;
bool checkable = 6;
bool checked = 7;
}
message Media {
bytes content = 1;
State state = 2;
oneof preview {
VideoPreview video = 101;
ImagePreview image = 102;
FilePreview file = 103;
}
message VideoPreview {
bytes thumbnail = 1;
string name = 2;
int32 width = 3;
}
message ImagePreview {
bytes thumbnail = 1;
string name = 2;
int32 width = 3;
}
message FilePreview {
string name = 1;
string icon = 2;
}
enum State {
EMPTY = 0;
UPLOADING = 1;
PREVIEW = 2;
DOWNLOADING = 3;
DONE = 4;
}
}
message Page {
enum Style {
EMPTY = 0;
TASK = 1;
BOOKMARK = 2;
SET = 3;
// ...
}
Style style = 1;
}
}
}
message Range {
int32 from = 1;
int32 to = 2;
}
message Struct {
// Unordered map of dynamically typed values.
map<string, Value> fields = 1;
// `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of that
// variants, absence of any variant indicates an error.
message Value {
oneof kind { // The kind of value.
NullValue null_value = 1; // Represents a null value.
double number_value = 2; // Represents a double value.
string string_value = 3; // Represents a string value.
bool bool_value = 4; // Represents a boolean value.
Struct struct_value = 5; // Represents a structured value.
ListValue list_value = 6; // Represents a repeated `Value`.
}
}
// `NullValue` is a singleton enumeration to represent the null value for the
enum NullValue {
NULL_VALUE = 0;
}
// `ListValue` is a wrapper around a repeated field of values.
message ListValue {
repeated Value values = 1;
}
}
/**
* Contains basic information about user account
*/
message Account {
string id = 1; // User's thread id
string name = 2; // User name, that associated with this account
Avatar avatar = 3; // Avatar of a user's account
/**
* Avatar of a user's account. It could be an image or color
*/
message Avatar {
oneof avatar {
Image image = 1; // Image of the avatar. Contains hash and size
string color = 2; // Color of the avatar, if no image
}
}
}
message Image {
string id = 1;
repeated Size sizes = 2;
enum Size {
LARGE = 0;
SMALL = 1;
THUMB = 2;
}
}
message Video {
string id = 1;
repeated Size sizes = 2;
enum Size {
SD_360p = 0;
SD_480p = 1;
HD_720p = 2;
HD_1080p = 3;
UHD_1440p = 4;
UHD_2160p = 5;
}
}
message Preview {
message Link {
string title = 1;
string description = 2;
string imageUrl = 3;
string url = 4;
string faviconUrl = 5;
Type type = 6;
enum Type {
PAGE = 0;
IMAGE = 1;
TEXT = 2;
UNEXPECTED = 3;
}
}
}
}

View file

@ -2,26 +2,23 @@ syntax="proto3";
package anytype;
option go_package = "lib";
import "account.proto";
import "file.proto";
import "misc.proto";
import "block.proto";
import "commands.proto";
service ClientCommands {
rpc WalletCreate (anytype.WalletCreateRequest) returns (anytype.WalletCreateResponse);
rpc WalletRecover (anytype.WalletRecoverRequest) returns (anytype.WalletRecoverResponse);
rpc AccountRecover (anytype.AccountRecoverRequest) returns (anytype.AccountRecoverResponse);
rpc AccountCreate (anytype.AccountCreateRequest) returns (anytype.AccountCreateResponse);
rpc AccountSelect (anytype.AccountSelectRequest) returns (anytype.AccountSelectResponse);
rpc WalletCreate (anytype.Rpc.Wallet.Create.Request) returns (anytype.Rpc.Wallet.Create.Response);
rpc WalletRecover (anytype.Rpc.Wallet.Recover.Request) returns (anytype.Rpc.Wallet.Recover.Response);
rpc AccountRecover (anytype.Rpc.Account.Recover.Request) returns (anytype.Rpc.Account.Recover.Response);
rpc AccountCreate (anytype.Rpc.Account.Create.Request) returns (anytype.Rpc.Account.Create.Response);
rpc AccountSelect (anytype.Rpc.Account.Select.Request) returns (anytype.Rpc.Account.Select.Response);
rpc ImageGetBlob (anytype.ImageGetBlobRequest) returns (anytype.ImageGetBlobResponse);
rpc ImageGetBlob (anytype.Rpc.Image.Get.Blob.Request) returns (anytype.Rpc.Image.Get.Blob.Response);
rpc VersionGet (VersionGetRequest) returns (VersionGetResponse);
rpc LogSend (LogSendRequest) returns (LogSendResponse);
rpc VersionGet (anytype.Rpc.Version.Get.Request) returns (anytype.Rpc.Version.Get.Response);
rpc LogSend (anytype.Rpc.Log.Send.Request) returns (anytype.Rpc.Log.Send.Response);
rpc BlockOpen (BlockOpenRequest) returns (BlockOpenResponse);
rpc BlockCreate (BlockCreateRequest) returns (BlockCreateResponse);
rpc BlockUpdate (BlockUpdateRequest) returns (BlockUpdateResponse);
rpc LinkPreview (LinkPreviewRequest) returns (LinkPreviewResponse);
rpc BlockOpen (anytype.Rpc.Block.Open.Request) returns (anytype.Rpc.Block.Open.Response);
rpc BlockCreate (anytype.Rpc.Block.Create.Request) returns (anytype.Rpc.Block.Create.Response);
rpc BlockUpdate (anytype.Rpc.Block.Update.Request) returns (anytype.Rpc.Block.Update.Response);
rpc BlockHistoryMove (anytype.Rpc.Block.History.Move.Request) returns (anytype.Rpc.Block.History.Move.Response);
// rpc BlockFilesUpload (Block Rpc.History.Move.Request) returns (BlockRpc..History Move.Response);
}

View file

@ -1,50 +0,0 @@
syntax="proto3";
package anytype;
option go_package = "pb";
message Struct {
// Unordered map of dynamically typed values.
map<string, Value> fields = 1;
}
// `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of that
// variants, absence of any variant indicates an error.
//
// The JSON representation for `Value` is JSON value.
message Value {
// The kind of value.
oneof kind {
// Represents a null value.
NullValue null_value = 1;
// Represents a double value.
double number_value = 2;
// Represents a string value.
string string_value = 3;
// Represents a boolean value.
bool bool_value = 4;
// Represents a structured value.
Struct struct_value = 5;
// Represents a repeated `Value`.
ListValue list_value = 6;
}
}
// `NullValue` is a singleton enumeration to represent the null value for the
// `Value` type union.
//
// The JSON representation for `NullValue` is JSON `null`.
enum NullValue {
// Null value.
NULL_VALUE = 0;
}
// `ListValue` is a wrapper around a repeated field of values.
//
// The JSON representation for `ListValue` is JSON array.
message ListValue {
// Repeated field of dynamically typed values.
repeated Value values = 1;
}

File diff suppressed because it is too large Load diff

View file

@ -27,14 +27,14 @@ const (
)
type LinkPreview interface {
Fetch(ctx context.Context, url string) (pb.LinkPreviewResponse, error)
Fetch(ctx context.Context, url string) (pb.ModelPreviewLink, error)
}
type linkPreview struct {
bmPolicy *bluemonday.Policy
}
func (l *linkPreview) Fetch(ctx context.Context, url string) (pb.LinkPreviewResponse, error) {
func (l *linkPreview) Fetch(ctx context.Context, url string) (pb.ModelPreviewLink, error) {
rt := &proxyRoundTripper{RoundTripper: http.DefaultTransport}
client := &http.Client{Transport: rt}
og, err := opengraph.FetchWithContext(ctx, url, client)
@ -42,7 +42,7 @@ func (l *linkPreview) Fetch(ctx context.Context, url string) (pb.LinkPreviewResp
if resp := rt.lastResponse; resp != nil && resp.StatusCode == http.StatusOK {
return l.makeNonHtml(url, resp)
}
return pb.LinkPreviewResponse{}, err
return pb.ModelPreviewLink{}, err
}
res := l.convertOGToInfo(og)
if len(res.Description) == 0 {
@ -51,13 +51,13 @@ func (l *linkPreview) Fetch(ctx context.Context, url string) (pb.LinkPreviewResp
return res, nil
}
func (l *linkPreview) convertOGToInfo(og *opengraph.OpenGraph) (i pb.LinkPreviewResponse) {
func (l *linkPreview) convertOGToInfo(og *opengraph.OpenGraph) (i pb.ModelPreviewLink) {
og.ToAbsURL()
i = pb.LinkPreviewResponse{
i = pb.ModelPreviewLink{
Url: og.URL.String(),
Title: og.Title,
Description: og.Description,
Type: pb.LinkPreviewResponse_PAGE,
Type: pb.ModelPreviewLink_PAGE,
FaviconUrl: og.Favicon,
}
if len(og.Image) != 0 {
@ -85,17 +85,17 @@ func (l *linkPreview) findContent(data []byte) (content string) {
return
}
func (l *linkPreview) makeNonHtml(url string, resp *http.Response) (i pb.LinkPreviewResponse, err error) {
func (l *linkPreview) makeNonHtml(url string, resp *http.Response) (i pb.ModelPreviewLink, err error) {
ct := resp.Header.Get("Content-Type")
i.Url = url
i.Title = filepath.Base(url)
if strings.HasPrefix(ct, "image/") {
i.Type = pb.LinkPreviewResponse_IMAGE
i.Type = pb.ModelPreviewLink_IMAGE
i.ImageUrl = url
} else if strings.HasPrefix(ct, "text/") {
i.Type = pb.LinkPreviewResponse_TEXT
i.Type = pb.ModelPreviewLink_TEXT
} else {
i.Type = pb.LinkPreviewResponse_UNEXPECTED
i.Type = pb.ModelPreviewLink_UNEXPECTED
}
return
}

View file

@ -23,13 +23,13 @@ func TestLinkPreview_Fetch(t *testing.T) {
info, err := lp.Fetch(ctx, ts.URL)
require.NoError(t, err)
assert.Equal(t, pb.LinkPreviewResponse{
assert.Equal(t, pb.ModelPreviewLink{
Url: ts.URL,
FaviconUrl: ts.URL + "/favicon.ico",
Title: "Title",
Description: "Description",
ImageUrl: "http://site.com/images/example.jpg",
Type: pb.LinkPreviewResponse_PAGE,
Type: pb.ModelPreviewLink_PAGE,
}, info)
})
@ -40,13 +40,13 @@ func TestLinkPreview_Fetch(t *testing.T) {
info, err := lp.Fetch(ctx, ts.URL)
require.NoError(t, err)
assert.Equal(t, pb.LinkPreviewResponse{
assert.Equal(t, pb.ModelPreviewLink{
Url: ts.URL,
FaviconUrl: ts.URL + "/favicon.ico",
Title: "Title",
Description: "Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta...",
ImageUrl: "http://site.com/images/example.jpg",
Type: pb.LinkPreviewResponse_PAGE,
Type: pb.ModelPreviewLink_PAGE,
}, info)
})
@ -58,11 +58,11 @@ func TestLinkPreview_Fetch(t *testing.T) {
lp := New()
info, err := lp.Fetch(ctx, url)
require.NoError(t, err)
assert.Equal(t, pb.LinkPreviewResponse{
assert.Equal(t, pb.ModelPreviewLink{
Url: url,
Title: "filename.jpg",
ImageUrl: url,
Type: pb.LinkPreviewResponse_IMAGE,
Type: pb.ModelPreviewLink_IMAGE,
}, info)
})
@ -74,10 +74,10 @@ func TestLinkPreview_Fetch(t *testing.T) {
lp := New()
info, err := lp.Fetch(ctx, url)
require.NoError(t, err)
assert.Equal(t, pb.LinkPreviewResponse{
assert.Equal(t, pb.ModelPreviewLink{
Url: url,
Title: "filename.jpg",
Type: pb.LinkPreviewResponse_UNEXPECTED,
Type: pb.ModelPreviewLink_UNEXPECTED,
}, info)
})
}