Add UI to export the list of bookmarks

This commit is contained in:
2022-05-25 17:18:32 +09:30
parent 78488d2f41
commit be10f5238e
4 changed files with 26 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package db
import (
"fmt"
"io"
"log"
"sync"
"time"
@@ -48,6 +49,19 @@ func (m *BookmarkManager) ListBookmarks() ([]entity.Bookmark, error) {
return bookmarks, nil
}
// ExportBookmarks exports all bookmarks to an io.Writer
func (m *BookmarkManager) ExportBookmarks(w io.Writer) error {
bms := []entity.Bookmark{}
err := m.db.store.Find(&bms, &badgerhold.Query{})
if err != nil {
return fmt.Errorf("could not export bookmarks: %w", err)
}
for _, bm := range bms {
w.Write([]byte(bm.URL + "\n"))
}
return nil
}
func (m *BookmarkManager) SaveBookmark(bm *entity.Bookmark) error {
err := m.db.store.Update(bm.ID, &bm)
if err != nil {