Skip to content

Commit

Permalink
Write notesnook data to file when debugging (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnetop authored Nov 16, 2023
1 parent d62b77b commit 1607e7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/notesnook/model.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package notesnook

type ExportData struct {
Version float64 `json:"version"`
Type string `json:"type"`
Date int64 `json:"date"`
Data string `json:"data"`
Hash string `json:"hash"`
HashType string `json:"hash_type"`
Compressed bool `json:"compressed"`
Encrypted bool `json:"encrypted"`
FileName string
Version float64 `json:"version"`
Type string `json:"type"`
Date int64 `json:"date"`
Data string `json:"data"`
Hash string `json:"hash"`
HashType string `json:"hash_type"`
Compressed bool `json:"compressed"`
Encrypted bool `json:"encrypted"`
FileName string
DebugFileName string
}

type Topic struct {
Expand Down
16 changes: 16 additions & 0 deletions internal/notesnook/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"strings"

fileUtil "github.com/danielnetop/notesnook-to-standardnotes/internal/file"
)
Expand All @@ -30,6 +32,7 @@ func ValidateBackupFiles(zf *zip.ReadCloser) ([]ExportData, error) {
}

content.FileName = fmt.Sprintf("%s_converted.txt", file.Name)
content.DebugFileName = fmt.Sprintf("%s_notesnook_debug.json", file.Name)

files = append(files, content)
}
Expand Down Expand Up @@ -81,5 +84,18 @@ func ProcessNotesnookExportData(file ExportData) ([]Nook, error) {
return []Nook{}, err
}

debugNotesnook := os.Getenv("DEBUG_NOTESNOOK_DATA")
if strings.ToLower(debugNotesnook) == "true" {
debugData, err := json.MarshalIndent(nooks, "", " ")
if err != nil {
fmt.Println("Unable to write to debug file")
}

err = fileUtil.CreateFileFromContent(debugData, file.DebugFileName)
if err != nil {
fmt.Println("Unable to write to debug file")
}
}

return nooks, nil
}

0 comments on commit 1607e7d

Please sign in to comment.