gnotes

package module
v0.0.0-...-6958317 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2023 License: BSD-3-Clause-Clear Imports: 26 Imported by: 0

README

GNOTES - Terminal based S3 syncing note app

screenshot

A WIP app. This is my local code and may not work for you. But you may find this useful.

Before using, you need access to a S3 server. Otherwise it will only save notes locally, and may not work correctly.

How it works

GNOTES syncs all notes and attachments to a s3 server. v1 branch will store all notes (not attachments) in one tarball. Every note is contained into that one file. With v2, each note is a seprate file on s3. This greatly improves download and upload speed when saving notes. Also, each note is checked with a sha1sum checksum to avoid downloading the notes if its already cached locally.

In v2, all notes and attachments are compressed, and encrypted before uploading to the s3 server.

Eventually, v3 will be diff based, further improving download and upload speed, and able to keep some revisions.

Installation

$ git clone https://github.com/WestleyR/gnotes
$ cd gnotes/
$ make
$ cp gnotes ~/.local/bin  # or your preferred path

Setting up gnotes for your S3 server

See the config.ini file for an example config.

The user config file for gnotes is located in:

${HOME}/.config/gnotes/config.ini

And as an example, for dreamhost, it should look like this:

[settings]
editor = vim
notes_dir = ${HOME}/.config/gnotes


[s3]
active = true
bucket = gnotes-v2
endpoint = https://objects-us-east-1.dream.io
region = us-east-1
accesskey = ACCESS_KEY
secretkey = SECRET_KEY
user_id = a-one-time-generated-uuid
crypt_key = a-16-bit-token

Inital creation

Right after installing, or if you dont have any gnote data on the s3 server, gnotes will likely print error messages. For safey reasions, if it failed to download data, it will not continue to avoid losing data.

After a fresh install, you first need to run gnotes with these flags:

$ gnotes -s -R

Then create a new note with some content.

The -s tells gnotes to skip the download, and -R for not looking for local cache.

Run gnotes --help for other flags or help.

After the inital creation, do not use those flags. Otherwise you may lose data

Basic usage

To delete a note, just select it with the ui and delete all content with your editor. With vim type :%d as an example. Then save, exit, and it will be deleted. Make sure all lines are removed.

Bugs

This is in develpment, there may be bugs. Please report by opening a github issue.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBookExists = errors.New("book already exists")

Functions

func GetFileFromConfig

func GetFileFromConfig(file string) string

func Sha1

func Sha1(s string) string

func Sha1File

func Sha1File(file string) (string, error)

Types

type Book

type Book struct {
	// Name is the sub-dir name
	Name string `json:"name"`
	// Notes contains all the notes in the sub-dir
	Notes    []*Note `json:"notes"`
	Modified int64   `json:"modified"`
	Selected bool    `json:"selected"`
}

Book contains all the notes for the Name of the sub-categroies.

func (*Book) Changed

func (b *Book) Changed(noteIndex int)

Changed updates the modified timestamp for the book and note.

func (*Book) DeleteNote

func (b *Book) DeleteNote(noteIndex int) error

DeleteNote will delete a specific note. Will delete the note from s3 imetitly, and reupload the index files.

func (*Book) HRModifiedTime

func (b *Book) HRModifiedTime() string

func (*Book) NewAttachment

func (book *Book) NewAttachment(noteDir, path string) error

func (*Book) NewNote

func (book *Book) NewNote(noteDir string, completion func()) error

func (*Book) NewNoteWithContentsOfFile

func (book *Book) NewNoteWithContentsOfFile(noteDir, path string, completion func()) error

func (*Book) SaveNoteIndex

func (b *Book) SaveNoteIndex(noteIndex int) error

SaveNoteIndex does the same thing as Note.Save(), but also updates the modified timestamp for the book.

func (*Book) Sort

func (n *Book) Sort()

type CliOpts

type CliOpts struct {
	SkipDownload bool
	NewNote      bool
}

type Config

type Config struct {
	App appSettings `ini:"settings"`
	S3  S3Config    `ini:"s3"`
}

func LoadConfig

func LoadConfig(configFile string) (*Config, error)

type Note

type Note struct {
	// S3Path is the path to the note on the s3 server. Also used for the local
	// path when caching. eg. "catigory/uuid-1/content"
	S3Path   string `json:"path"`
	Created  int64  `json:"created"`
	Modified int64  `json:"modified"`
	Hash     string `json:"hash"`
	Title    string `json:"title"`

	// For attachments
	IsAttachment    bool   `json:"attachment"`
	AttachmentTitle string `json:"attachment_title"`
	Size            int64  `json:"size"`
}

Note is all the data for a specific note.

func (*Note) Changed

func (n *Note) Changed()

Changed will update the modified date for a note. Depercated: use Book.Changed()

func (*Note) Download

func (n *Note) Download(noteDir string, s3Config S3Config) error

Download will download the note if needed based on hash.

func (*Note) GetTitle

func (n *Note) GetTitle(noteDir string) string

GetTitle returns a title for a note. Requires the local cache path. Should be ~/.cache/gnotes/notes

func (*Note) Info

func (a *Note) Info() string

func (*Note) Save

func (n *Note) Save() error

Save will save a note to the s3 server. Should be called after editing. Will NOT update the note index file. Does not update/upload if the checksum did not change. Depercated: use Book.SaveNoteIndex() instead (MAYBE...)

type NoteBook

type NoteBook struct {
	Books []*Book `json:"folders"`
}

NoteBook is the collection of all sub-categroies.

func (*NoteBook) DeleteBook

func (n *NoteBook) DeleteBook(index int) error

func (*NoteBook) GetSelected

func (b *NoteBook) GetSelected() *Book

func (*NoteBook) NewBook

func (noteBook *NoteBook) NewBook(name string) error

func (*NoteBook) SetSelected

func (b *NoteBook) SetSelected(index int)

func (*NoteBook) Sort

func (n *NoteBook) Sort()

type S3Config

type S3Config struct {
	Active    bool   `ini:"active"`
	Bucket    string `ini:"bucket"`
	Endpoint  string `ini:"endpoint"`
	Region    string `ini:"region"`
	AccessKey string `ini:"accesskey"`
	SecretKey string `ini:"secretkey"`
	UserID    string `ini:"user_id"`
	CryptKey  string `ini:"crypt_key"`
}

func (*S3Config) Decrypt

func (c *S3Config) Decrypt(data []byte) ([]byte, error)

func (S3Config) DecryptAndDeGzip

func (c S3Config) DecryptAndDeGzip(file string) error

func (S3Config) Delete

func (c S3Config) Delete(s3File string) error

func (S3Config) DownloadFileFrom

func (c S3Config) DownloadFileFrom(s3File, endPath string) error

func (*S3Config) Encrypt

func (c *S3Config) Encrypt(data []byte) ([]byte, error)

func (S3Config) GzipAndEncrypt

func (c S3Config) GzipAndEncrypt(file string) (string, error)

func (S3Config) UploadFile

func (c S3Config) UploadFile(local, to string) error

type SelfApp

type SelfApp struct {
	// Notes
	Notes *NoteBook

	// IndexNeedsUpdating indecates if the index file needs to be uploaded
	// like if a new note was created.
	IndexNeedsUpdating bool

	// CLI opts
	CliOpts CliOpts

	Config *Config
}

func InitApp

func InitApp(configPath string) (*SelfApp, error)

func (*SelfApp) DeleteNote

func (self *SelfApp) DeleteNote(bookIndex, noteIndex int) error

DeleteNote will delete a specific note. Will delete the note from s3 imetitly, and reupload the index files. Depercated: use Book.DeleteNote()

func (*SelfApp) LoadNotes

func (self *SelfApp) LoadNotes() error

func (*SelfApp) SaveIndexFile

func (self *SelfApp) SaveIndexFile() error

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL