mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-08 05:47:07 +09:00
fixes
This commit is contained in:
parent
5167ab3210
commit
2b718e49e6
1 changed files with 31 additions and 35 deletions
|
@ -197,8 +197,13 @@ func (b *builtinObjects) CreateObjectsForExperience(ctx context.Context, spaceID
|
|||
}
|
||||
|
||||
if isNewSpace {
|
||||
profile, err := b.getProfile(path)
|
||||
if err != nil {
|
||||
log.Warnf("failed to profile object: %s", err)
|
||||
}
|
||||
// TODO: GO-2627 Home page handling should be moved to importer
|
||||
b.handleHomePage(path, spaceID, removeFunc, false)
|
||||
b.handleHomePage(profile, spaceID, false)
|
||||
removeFunc()
|
||||
} else {
|
||||
removeFunc()
|
||||
}
|
||||
|
@ -232,22 +237,28 @@ func (b *builtinObjects) inject(ctx session.Context, spaceID string, useCase pb.
|
|||
if err = os.WriteFile(path, archive, 0644); err != nil {
|
||||
return "", fmt.Errorf("failed to save use case archive to temporary file: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if rmErr := os.Remove(path); rmErr != nil {
|
||||
log.Errorf("failed to remove temporary file: %v", anyerror.CleanupError(rmErr))
|
||||
}
|
||||
}()
|
||||
|
||||
if err = b.importArchive(context.Background(), spaceID, path, "", pb.RpcObjectImportRequestPbParams_SPACE, nil, false); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// TODO: GO-2627 Home page handling should be moved to importer
|
||||
_ = b.handleHomePage(path, spaceID, func() {
|
||||
if rmErr := os.Remove(path); rmErr != nil {
|
||||
log.Errorf("failed to remove temporary file: %v", anyerror.CleanupError(rmErr))
|
||||
}
|
||||
}, useCase == migrationUseCase)
|
||||
profile, err := b.getProfile(path)
|
||||
if err != nil {
|
||||
log.Warnf("failed to get profile object: %s", err)
|
||||
}
|
||||
startingPageId = b.getStartingPage(profile, spaceID)
|
||||
|
||||
startingPageId = b.getStartingPage(path, spaceID)
|
||||
// TODO: GO-2627 Home page handling should be moved to importer
|
||||
_ = b.handleHomePage(profile, spaceID, useCase == migrationUseCase)
|
||||
|
||||
// TODO: GO-2627 Widgets creation should be moved to importer
|
||||
b.createWidgets(ctx, spaceID, useCase)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -285,17 +296,8 @@ func (b *builtinObjects) importArchive(
|
|||
return res.Err
|
||||
}
|
||||
|
||||
func (b *builtinObjects) getStartingPage(path, spaceId string) string {
|
||||
r, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
log.Errorf("cannot open zip file %s: %w", path, err)
|
||||
return ""
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
profile, err := b.getProfile(&r.Reader)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get old id of home page object: %s", err)
|
||||
func (b *builtinObjects) getStartingPage(profile *pb.Profile, spaceId string) string {
|
||||
if profile == nil {
|
||||
return ""
|
||||
}
|
||||
if profile.StartingPage == "" {
|
||||
|
@ -310,22 +312,9 @@ func (b *builtinObjects) getStartingPage(path, spaceId string) string {
|
|||
return newID
|
||||
}
|
||||
|
||||
func (b *builtinObjects) handleHomePage(path, spaceId string, removeFunc func(), isMigration bool) (dashboardId string) {
|
||||
defer removeFunc()
|
||||
func (b *builtinObjects) handleHomePage(profile *pb.Profile, spaceId string, isMigration bool) (dashboardId string) {
|
||||
oldID := migrationDashboardName
|
||||
if !isMigration {
|
||||
r, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
log.Errorf("cannot open zip file %s: %w", path, err)
|
||||
return
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
profile, err := b.getProfile(&r.Reader)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get old id of home page object: %s", err)
|
||||
return
|
||||
}
|
||||
if !isMigration && profile != nil {
|
||||
oldID = profile.SpaceDashboardId
|
||||
}
|
||||
|
||||
|
@ -347,7 +336,14 @@ func (b *builtinObjects) handleHomePage(path, spaceId string, removeFunc func(),
|
|||
return
|
||||
}
|
||||
|
||||
func (b *builtinObjects) getProfile(zipReader *zip.Reader) (profile *pb.Profile, err error) {
|
||||
func (b *builtinObjects) getProfile(path string) (profile *pb.Profile, err error) {
|
||||
zipReader, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
log.Errorf("cannot open zip file %s: %w", path, err)
|
||||
return
|
||||
}
|
||||
defer zipReader.Close()
|
||||
|
||||
var (
|
||||
rd io.ReadCloser
|
||||
profileFound bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue