Add half arsed user separation

This commit is contained in:
Maximilian Friedersdorff 2025-07-30 13:41:03 +01:00
parent 3c792decd6
commit 25bcf4d706
6 changed files with 125 additions and 41 deletions

View file

@ -29,6 +29,7 @@ type Note struct {
Title string
BodyRendered template.HTML
Body []byte
Owner string
}
func fmtPath(path string) string {
@ -37,7 +38,7 @@ func fmtPath(path string) string {
// Save a note to a path derived from the title
func (n *Note) Save() error {
filename := filepath.Join(conf.Conf.NotesDir, fmtPath(n.EncodedTitle()))
filename := filepath.Join(conf.Conf.NotesDir, n.Owner, fmtPath(n.EncodedTitle()))
return os.WriteFile(filename, n.Body, 0600)
}
@ -58,18 +59,18 @@ func (n *Note) Render() {
}
// LoadNote from the disk. The path is derived from the title
func LoadNote(encodedTitle string) (*Note, error) {
filename := filepath.Join(conf.Conf.NotesDir, fmtPath(encodedTitle))
func LoadNote(owner string, encodedTitle string) (*Note, error) {
filename := filepath.Join(conf.Conf.NotesDir, owner, fmtPath(encodedTitle))
body, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
title := DecodeTitle(encodedTitle)
return &Note{Title: title, Body: body}, nil
return &Note{Title: title, Body: body, Owner: owner}, nil
}
func DeleteNote(title string) error {
filename := filepath.Join(conf.Conf.NotesDir, fmtPath(title))
func DeleteNote(owner string, title string) error {
filename := filepath.Join(conf.Conf.NotesDir, owner, fmtPath(title))
return os.Remove(filename)
}