mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-5409 fixes for get started
This commit is contained in:
parent
0e092fc5ee
commit
648ec017f7
9 changed files with 1206 additions and 1148 deletions
|
@ -66,7 +66,7 @@ func (s *Service) CreateWorkspace(ctx context.Context, req *pb.RpcWorkspaceCreat
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("set details for space %s: %w", newSpace.Id(), err)
|
||||
}
|
||||
_, err = s.builtinObjectService.CreateObjectsForUseCase(nil, newSpace.Id(), req.UseCase)
|
||||
_, _, err = s.builtinObjectService.CreateObjectsForUseCase(nil, newSpace.Id(), req.UseCase)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("import use-case: %w", err)
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ type Service struct {
|
|||
}
|
||||
|
||||
type builtinObjects interface {
|
||||
CreateObjectsForUseCase(ctx session.Context, spaceID string, req pb.RpcObjectImportUseCaseRequestUseCase) (code pb.RpcObjectImportUseCaseResponseErrorCode, err error)
|
||||
CreateObjectsForUseCase(ctx session.Context, spaceID string, req pb.RpcObjectImportUseCaseRequestUseCase) (dashboardId string, code pb.RpcObjectImportUseCaseResponseErrorCode, err error)
|
||||
}
|
||||
|
||||
type openedObjects struct {
|
||||
|
|
|
@ -693,8 +693,9 @@ func (mw *Middleware) ObjectImportNotionValidateToken(ctx context.Context,
|
|||
func (mw *Middleware) ObjectImportUseCase(cctx context.Context, req *pb.RpcObjectImportUseCaseRequest) *pb.RpcObjectImportUseCaseResponse {
|
||||
ctx := mw.newContext(cctx)
|
||||
|
||||
response := func(code pb.RpcObjectImportUseCaseResponseErrorCode, err error) *pb.RpcObjectImportUseCaseResponse {
|
||||
response := func(dashboardId string, code pb.RpcObjectImportUseCaseResponseErrorCode, err error) *pb.RpcObjectImportUseCaseResponse {
|
||||
resp := &pb.RpcObjectImportUseCaseResponse{
|
||||
DashboardId: dashboardId,
|
||||
Error: &pb.RpcObjectImportUseCaseResponseError{
|
||||
Code: code,
|
||||
},
|
||||
|
|
|
@ -16179,6 +16179,7 @@ DEPRECATED, GO-1926 |
|
|||
| ----- | ---- | ----- | ----------- |
|
||||
| error | [Rpc.Object.ImportUseCase.Response.Error](#anytype-Rpc-Object-ImportUseCase-Response-Error) | | |
|
||||
| event | [ResponseEvent](#anytype-ResponseEvent) | | |
|
||||
| dashboardId | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
|
2314
pb/commands.pb.go
2314
pb/commands.pb.go
File diff suppressed because it is too large
Load diff
|
@ -3111,6 +3111,7 @@ message Rpc {
|
|||
message Response {
|
||||
Error error = 1;
|
||||
ResponseEvent event = 2;
|
||||
string dashboardId = 3;
|
||||
|
||||
message Error {
|
||||
Code code = 1;
|
||||
|
|
|
@ -87,7 +87,7 @@ func createAccountAndStartApp(t *testing.T, defaultUsecase pb.RpcObjectImportUse
|
|||
eventQueue: eventQueue,
|
||||
}
|
||||
objCreator := getService[builtinobjects.BuiltinObjects](testApp)
|
||||
_, err = objCreator.CreateObjectsForUseCase(session.NewContext(), acc.Info.AccountSpaceId, defaultUsecase)
|
||||
_, _, err = objCreator.CreateObjectsForUseCase(session.NewContext(), acc.Info.AccountSpaceId, defaultUsecase)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
|
|
|
@ -87,7 +87,7 @@ var (
|
|||
type BuiltinObjects interface {
|
||||
app.Component
|
||||
|
||||
CreateObjectsForUseCase(ctx session.Context, spaceID string, req pb.RpcObjectImportUseCaseRequestUseCase) (code pb.RpcObjectImportUseCaseResponseErrorCode, err error)
|
||||
CreateObjectsForUseCase(ctx session.Context, spaceID string, req pb.RpcObjectImportUseCaseRequestUseCase) (dashboardId string, code pb.RpcObjectImportUseCaseResponseErrorCode, err error)
|
||||
CreateObjectsForExperience(ctx context.Context, spaceID, url, title string, newSpace bool) (err error)
|
||||
InjectMigrationDashboard(spaceID string) error
|
||||
}
|
||||
|
@ -127,21 +127,21 @@ func (b *builtinObjects) CreateObjectsForUseCase(
|
|||
ctx session.Context,
|
||||
spaceID string,
|
||||
useCase pb.RpcObjectImportUseCaseRequestUseCase,
|
||||
) (code pb.RpcObjectImportUseCaseResponseErrorCode, err error) {
|
||||
) (dashboardId string, code pb.RpcObjectImportUseCaseResponseErrorCode, err error) {
|
||||
if useCase == pb.RpcObjectImportUseCaseRequest_NONE {
|
||||
return pb.RpcObjectImportUseCaseResponseError_NULL, nil
|
||||
return "", pb.RpcObjectImportUseCaseResponseError_NULL, nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
archive, found := archives[useCase]
|
||||
if !found {
|
||||
return pb.RpcObjectImportUseCaseResponseError_BAD_INPUT,
|
||||
return "", pb.RpcObjectImportUseCaseResponseError_BAD_INPUT,
|
||||
fmt.Errorf("failed to import builtinObjects: invalid Use Case value: %v", useCase)
|
||||
}
|
||||
|
||||
if err = b.inject(ctx, spaceID, useCase, archive); err != nil {
|
||||
return pb.RpcObjectImportUseCaseResponseError_UNKNOWN_ERROR,
|
||||
if dashboardId, err = b.inject(ctx, spaceID, useCase, archive); err != nil {
|
||||
return "", pb.RpcObjectImportUseCaseResponseError_UNKNOWN_ERROR,
|
||||
fmt.Errorf("failed to import builtinObjects for Use Case %s: %w",
|
||||
pb.RpcObjectImportUseCaseRequestUseCase_name[int32(useCase)], err)
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func (b *builtinObjects) CreateObjectsForUseCase(
|
|||
log.Debugf("built-in objects injection time exceeded timeout of %s and is %s", injectionTimeout.String(), spent.String())
|
||||
}
|
||||
|
||||
return pb.RpcObjectImportUseCaseResponseError_NULL, nil
|
||||
return dashboardId, pb.RpcObjectImportUseCaseResponseError_NULL, nil
|
||||
}
|
||||
|
||||
func (b *builtinObjects) CreateObjectsForExperience(ctx context.Context, spaceID, url, title string, isNewSpace bool) (err error) {
|
||||
|
@ -223,21 +223,22 @@ func (b *builtinObjects) provideNotification(spaceID string, progress process.Pr
|
|||
}
|
||||
|
||||
func (b *builtinObjects) InjectMigrationDashboard(spaceID string) error {
|
||||
return b.inject(nil, spaceID, migrationUseCase, migrationDashboardZip)
|
||||
_, err := b.inject(nil, spaceID, migrationUseCase, migrationDashboardZip)
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *builtinObjects) inject(ctx session.Context, spaceID string, useCase pb.RpcObjectImportUseCaseRequestUseCase, archive []byte) (err error) {
|
||||
func (b *builtinObjects) inject(ctx session.Context, spaceID string, useCase pb.RpcObjectImportUseCaseRequestUseCase, archive []byte) (dashboardId string, err error) {
|
||||
path := filepath.Join(b.tempDirService.TempDir(), time.Now().Format("tmp.20060102.150405.99")+".zip")
|
||||
if err = os.WriteFile(path, archive, 0644); err != nil {
|
||||
return fmt.Errorf("failed to save use case archive to temporary file: %w", err)
|
||||
return "", fmt.Errorf("failed to save use case archive to temporary file: %w", err)
|
||||
}
|
||||
|
||||
if err = b.importArchive(context.Background(), spaceID, path, "", pb.RpcObjectImportRequestPbParams_SPACE, nil, false); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
// TODO: GO-2627 Home page handling should be moved to importer
|
||||
b.handleHomePage(path, spaceID, func() {
|
||||
dashboardId = b.handleHomePage(path, spaceID, func() {
|
||||
if rmErr := os.Remove(path); rmErr != nil {
|
||||
log.Errorf("failed to remove temporary file: %v", anyerror.CleanupError(rmErr))
|
||||
}
|
||||
|
@ -282,7 +283,7 @@ func (b *builtinObjects) importArchive(
|
|||
return res.Err
|
||||
}
|
||||
|
||||
func (b *builtinObjects) handleHomePage(path, spaceId string, removeFunc func(), isMigration bool) {
|
||||
func (b *builtinObjects) handleHomePage(path, spaceId string, removeFunc func(), isMigration bool) (dashboardId string) {
|
||||
defer removeFunc()
|
||||
oldID := migrationDashboardName
|
||||
if !isMigration {
|
||||
|
@ -311,7 +312,9 @@ func (b *builtinObjects) handleHomePage(path, spaceId string, removeFunc func(),
|
|||
log.Errorf("failed to get space: %w", err)
|
||||
return
|
||||
}
|
||||
dashboardId = newID
|
||||
b.setHomePageIdToWorkspace(spc, newID)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *builtinObjects) getOldHomePageId(zipReader *zip.Reader) (id string, err error) {
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue