-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GO-2746: add export structure #1451
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cf7e4e
GO-2746: add export structure
AnastasiaShemyakinskaya 669c280
GO-2746: fix comments
AnastasiaShemyakinskaya 5e1e9c5
GO-2746 Merge branch 'main' of github.com:anyproto/anytype-heart into…
AnastasiaShemyakinskaya 533f2ec
GO-2746: refactoring
AnastasiaShemyakinskaya 4501c58
GO-2746 Merge branch 'main' of github.com:anyproto/anytype-heart into…
AnastasiaShemyakinskaya b4f8757
GO-2746: add comments
AnastasiaShemyakinskaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,8 +55,14 @@ import ( | |
const CName = "export" | ||
|
||
const ( | ||
tempFileName = "temp_anytype_backup" | ||
spaceDirectory = "spaces" | ||
tempFileName = "temp_anytype_backup" | ||
spaceDirectory = "spaces" | ||
typesDirectory = "types" | ||
objectsDirectory = "objects" | ||
relationsDirectory = "relations" | ||
relationsOptionsDirectory = "relationsOptions" | ||
templatesDirectory = "templates" | ||
filesObjects = "filesObjects" | ||
) | ||
|
||
var log = logging.Logger("anytype-mw-export") | ||
|
@@ -461,8 +467,8 @@ func (e *export) writeMultiDoc(ctx context.Context, | |
return | ||
} | ||
|
||
func (e *export) writeDoc(ctx context.Context, req *pb.RpcObjectListExportRequest, wr writer, docInfo map[string]*types.Struct, queue process.Queue, docID string) (err error) { | ||
return cache.Do(e.picker, docID, func(b sb.SmartBlock) error { | ||
func (e *export) writeDoc(ctx context.Context, req *pb.RpcObjectListExportRequest, wr writer, docInfo map[string]*types.Struct, queue process.Queue, docId string) (err error) { | ||
return cache.Do(e.picker, docId, func(b sb.SmartBlock) error { | ||
st := b.NewState() | ||
if pbtypes.GetBool(st.CombinedDetails(), bundle.RelationKeyIsDeleted.String()) { | ||
return nil | ||
|
@@ -491,11 +497,11 @@ func (e *export) writeDoc(ctx context.Context, req *pb.RpcObjectListExportReques | |
} | ||
conv.SetKnownDocs(docInfo) | ||
result := conv.Convert(b.Type().ToProto()) | ||
filename := e.provideFileName(docID, req.SpaceId, conv, st) | ||
filename := e.provideFileName(docId, req.SpaceId, conv, st, b.Type()) | ||
if req.Format == model.Export_Markdown { | ||
filename = e.provideMarkdownName(st, wr, docID, conv, req.SpaceId) | ||
filename = e.provideMarkdownName(st, wr, docId, conv, req.SpaceId) | ||
} | ||
if docID == b.Space().DerivedIDs().Home { | ||
if docId == b.Space().DerivedIDs().Home { | ||
filename = "index" + conv.Ext() | ||
} | ||
lastModifiedDate := pbtypes.GetInt64(st.LocalDetails(), bundle.RelationKeyLastModifiedDate.String()) | ||
|
@@ -519,15 +525,33 @@ func (e *export) provideMarkdownName(s *state.State, wr writer, docID string, co | |
return wr.Namer().Get(path, docID, name, conv.Ext()) | ||
} | ||
|
||
func (e *export) provideFileName(docID, spaceId string, conv converter.Converter, st *state.State) string { | ||
filename := docID + conv.Ext() | ||
func (e *export) provideFileName(docId, spaceId string, conv converter.Converter, st *state.State, blockType smartblock.SmartBlockType) string { | ||
dir := e.provideFileDirectory(blockType) | ||
filename := filepath.Join(dir, docId+conv.Ext()) | ||
if spaceId == "" { | ||
spaceId := pbtypes.GetString(st.LocalDetails(), bundle.RelationKeySpaceId.String()) | ||
filename = filepath.Join(spaceDirectory, spaceId, filename) | ||
} | ||
return filename | ||
} | ||
|
||
func (e *export) provideFileDirectory(blockType smartblock.SmartBlockType) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call it just |
||
switch blockType { | ||
case smartblock.SmartBlockTypeRelation: | ||
return relationsDirectory | ||
case smartblock.SmartBlockTypeRelationOption: | ||
return relationsOptionsDirectory | ||
case smartblock.SmartBlockTypeObjectType: | ||
return typesDirectory | ||
case smartblock.SmartBlockTypeTemplate: | ||
return templatesDirectory | ||
case smartblock.SmartBlockTypeFile, smartblock.SmartBlockTypeFileObject: | ||
return filesObjects | ||
default: | ||
return objectsDirectory | ||
} | ||
} | ||
|
||
func (e *export) saveFile(ctx context.Context, wr writer, fileObject sb.SmartBlock, exportAllSpaces bool) (fileName string, err error) { | ||
fullId := domain.FullFileId{ | ||
SpaceId: fileObject.Space().Id(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be the case that spaceId is nil? What happens here, why if spaceId == "" we do something completely different? Maybe It shouldn't be inside this function? Can you explain please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be empty, if user want to export all spaces. We build file directory based on this value, so I guess it makes sense to check it here 🧐