Load LastModified time on note
This commit is contained in:
parent
33cc62b3fc
commit
3de1b8b714
1 changed files with 10 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
||||
markdown "github.com/teekennedy/goldmark-markdown"
|
||||
|
|
@ -36,6 +37,7 @@ type Note struct {
|
|||
Owner string
|
||||
Viewers map[string]struct{}
|
||||
Uid string
|
||||
LastModified time.Time
|
||||
}
|
||||
|
||||
type NoteStore struct {
|
||||
|
|
@ -63,7 +65,7 @@ func Init() error {
|
|||
files, err := os.ReadDir(notesDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
os.MkdirAll(notesDir, os.FileMode(0750))
|
||||
os.MkdirAll(notesDir, os.FileMode(0o750))
|
||||
} else {
|
||||
log.Print(err.Error())
|
||||
return err
|
||||
|
|
@ -165,7 +167,7 @@ func (n *Note) Save() error {
|
|||
return os.WriteFile(
|
||||
filename,
|
||||
[]byte(fmt.Sprintf("---\n%s---\n%s", frontmatter, n.Body)),
|
||||
0600,
|
||||
0o600,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -190,6 +192,11 @@ func loadNote(uid string) (*Note, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
stat, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bodyScanner := bufio.NewScanner(f)
|
||||
body := make([]byte, 0, 10)
|
||||
fullBody := make([]byte, 0, 10)
|
||||
|
|
@ -236,6 +243,7 @@ func loadNote(uid string) (*Note, error) {
|
|||
note := NewNoteNoSave(title, owner)
|
||||
note.Uid = uid
|
||||
note.Body = body
|
||||
note.LastModified = stat.ModTime()
|
||||
|
||||
viewers := metaData["viewers"].([]interface{})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue