mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 02:13:41 +09:00
GO-4969 inmemory exporter: do not allow files
This commit is contained in:
parent
62cd6b7eda
commit
718f8e4ef3
2 changed files with 14 additions and 0 deletions
|
@ -252,6 +252,7 @@ func (e *exportContext) getStateFilters(id string) *state.Filters {
|
|||
func (e *exportContext) exportObject(ctx context.Context, objectId string) (string, error) {
|
||||
e.reqIds = []string{objectId}
|
||||
e.includeArchive = true
|
||||
e.includeFiles = false
|
||||
err := e.docsForExport(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -268,6 +269,16 @@ func (e *exportContext) exportObject(ctx context.Context, objectId string) (stri
|
|||
docNamer = newNamer()
|
||||
}
|
||||
inMemoryWriter := &InMemoryWriter{fn: docNamer}
|
||||
details, err := e.objectStore.SpaceIndex(e.spaceId).GetDetails(objectId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// do not allow file export for in-memory writer
|
||||
switch model.ObjectTypeLayout(details.GetInt64(bundle.RelationKeyLayout)) {
|
||||
case model.ObjectType_file, model.ObjectType_image, model.ObjectType_video, model.ObjectType_audio:
|
||||
return "", fmt.Errorf("file export is not allowed for in-memory writer")
|
||||
}
|
||||
|
||||
err = e.writeDoc(ctx, inMemoryWriter, objectId, e.docs.transformToDetailsMap())
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -173,6 +173,9 @@ func (d *InMemoryWriter) Path() string {
|
|||
func (d *InMemoryWriter) WriteFile(filename string, r io.Reader, lastModifiedDate int64) (err error) {
|
||||
d.m.Lock()
|
||||
defer d.m.Unlock()
|
||||
if filepath.Ext(filename) != ".md" && filepath.Ext(filename) != ".json" && filepath.Ext(filename) != ".pb" {
|
||||
return fmt.Errorf("unsupported file type: %s", filename)
|
||||
}
|
||||
if d.data == nil {
|
||||
d.data = make(map[string][]byte)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue