1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-02-16 19:47:23 +02:00

Filter out orphaned blocks on export

This commit is contained in:
Chen-I Lim 2020-12-10 12:39:09 -08:00
parent 7570182fa4
commit 6f40b80d6e

View File

@ -196,7 +196,9 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("EXPORT Blocks, %d result(s)", len(blocks))
log.Printf("%d raw block(s)", len(blocks))
blocks = filterOrphanBlocks(blocks)
log.Printf("EXPORT Blocks, %d filtered block(s)", len(blocks))
json, err := json.Marshal(blocks)
if err != nil {
@ -209,6 +211,24 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
jsonBytesResponse(w, http.StatusOK, json)
}
func filterOrphanBlocks(blocks []model.Block) (ret []model.Block) {
for _, block := range blocks {
if len(block.ParentID) == 0 || arrayContainsBlockWithID(blocks, block.ParentID) {
ret = append(ret, block)
}
}
return
}
func arrayContainsBlockWithID(array []model.Block, blockID string) bool {
for _, item := range array {
if item.ID == blockID {
return true
}
}
return false
}
func (a *API) handleImport(w http.ResponseWriter, r *http.Request) {
requestBody, err := ioutil.ReadAll(r.Body)
if err != nil {