mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-08 05:47:07 +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
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue