From a53dda25bd1f99621c1305a22dce894fa4af721d Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Thu, 28 Mar 2024 10:42:52 +0300 Subject: [PATCH] Add comments --- README.md | 8 ++++---- TODO.md | 5 ++--- config.go | 1 + export.go | 1 + flags.go | 1 + public/date.js | 3 ++- routes.go | 4 ++++ serve.go | 1 + 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7170c8e..f6d35da 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,16 @@ As a result of this, it is also neither secure nor stable. ## Features: * Each day, you get a text file. You have until 23:59 of that very day to finalise it. -* At any moment, you can append a single line to log.txt -* You can save named notes to document milestones, big events, or just a nice game you played this month -* There is also a readme.txt file (just like this one, except you get to write it!) +* You can save named notes to document milestones, big events, or just a nice game you played this month* +* There is also a readme.txt file (just like this one, except you get to write it!)* * You can easily export everything in a zip file for backups * Everything is plain(text) and simple. No databases, encryption, OAuth, or anything fancy. Even the password is plainte- *wait is this a feature?* * Docker support (in fact, that's probably the best way to run this) * Optional Telegram notifications for failed login attempts +*only available through API, subject to change and removal + ## Data format: ``` data @@ -26,7 +27,6 @@ data | +-- note1.txt | +-- note2.txt | ... -+-- log.txt +-- readme.txt config diff --git a/TODO.md b/TODO.md index 4ccd4a5..fa479b2 100644 --- a/TODO.md +++ b/TODO.md @@ -4,9 +4,8 @@ List of things to add to this project * Make scram configurable * Use reflection in config loading * Check export function for improvements -* Improve viewing of days (textarea over raw API requests), add notes to frontend +* Add notes to frontend? * More slog.Debug and a debug flag? * Think about timezones * Consider more secure auth methods -* *Go* dependency-less? <-- this is a terrible idea -* Better visual feedback from JS? \ No newline at end of file +* *Go* dependency-less? <-- this is a terrible idea \ No newline at end of file diff --git a/config.go b/config.go index 4f110d0..3680501 100644 --- a/config.go +++ b/config.go @@ -89,6 +89,7 @@ func (c *Config) Reload() error { return nil } +// ConfigInit loads config on startup func ConfigInit() Config { cfg := Config{Port: 7101, Username: "admin", Password: "admin"} // Default values are declared here, I guess err := cfg.Reload() diff --git a/export.go b/export.go index 3c59659..57989df 100644 --- a/export.go +++ b/export.go @@ -11,6 +11,7 @@ import ( var ExportPath = "data/export.zip" +// Export saves a .zip archive of the data folder to the passed filename func Export(filename string) error { file, err := os.Create(filename) if err != nil { diff --git a/flags.go b/flags.go index 3570cfe..043dbdf 100644 --- a/flags.go +++ b/flags.go @@ -5,6 +5,7 @@ import ( "log" ) +// FlagInit processes app flags func FlagInit() { config := flag.String("config", "", "override config file") username := flag.String("user", "", "override username") diff --git a/public/date.js b/public/date.js index 6f905db..a372f04 100644 --- a/public/date.js +++ b/public/date.js @@ -1,3 +1,4 @@ +// Format time in "Jan 02, 2006" format function formatDate(date) { let dateFormat = new Intl.DateTimeFormat('en', { year: 'numeric', @@ -15,7 +16,7 @@ function updateDate() { } -// Starts interval to update today's date every hour at 00:00 +// Start interval to update today's date every hour at 00:00 function callEveryHour() { setInterval(updateDate, 1000 * 60 * 60); } diff --git a/routes.go b/routes.go index 548afdc..f51e038 100644 --- a/routes.go +++ b/routes.go @@ -37,6 +37,7 @@ func InternalError(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./pages/error/500.html") } +// GetToday renders HTML page for today's view func GetToday(w http.ResponseWriter, r *http.Request) { day, err := ReadToday() if err != nil { @@ -63,6 +64,7 @@ func GetToday(w http.ResponseWriter, r *http.Request) { } } +// PostToday saves today's entry from form and redirects back to GET func PostToday(w http.ResponseWriter, r *http.Request) { err := SaveToday([]byte(r.FormValue("day"))) if err != nil { @@ -71,6 +73,7 @@ func PostToday(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, r.Header.Get("Referer"), 302) } +// GetDays renders HTML page for list of previous days func GetDays(w http.ResponseWriter, r *http.Request) { day, err := ListFiles("day") if err != nil { @@ -104,6 +107,7 @@ func GetDays(w http.ResponseWriter, r *http.Request) { } } +// GetDay renders HTML page for a specific day func GetDay(w http.ResponseWriter, r *http.Request) { dayString := chi.URLParam(r, "day") if dayString == "" { diff --git a/serve.go b/serve.go index de99d36..d98ca3f 100644 --- a/serve.go +++ b/serve.go @@ -9,6 +9,7 @@ import ( "strconv" ) +// Serve starts the app's web server func Serve() { r := chi.NewRouter() r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes)