Add comments

This commit is contained in:
Andrew-71 2024-03-28 10:42:52 +03:00
parent f0198a4a72
commit a53dda25bd
8 changed files with 16 additions and 8 deletions

View file

@ -7,15 +7,16 @@ As a result of this, it is also neither secure nor stable.
## Features: ## Features:
* Each day, you get a text file. You have until 23:59 of that very day to finalise it. * 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*
* 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!)*
* 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 * 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?* * 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) * Docker support (in fact, that's probably the best way to run this)
* Optional Telegram notifications for failed login attempts * Optional Telegram notifications for failed login attempts
*only available through API, subject to change and removal
## Data format: ## Data format:
``` ```
data data
@ -26,7 +27,6 @@ data
| +-- note1.txt | +-- note1.txt
| +-- note2.txt | +-- note2.txt
| ... | ...
+-- log.txt
+-- readme.txt +-- readme.txt
config config

View file

@ -4,9 +4,8 @@ List of things to add to this project
* Make scram configurable * Make scram configurable
* Use reflection in config loading * Use reflection in config loading
* Check export function for improvements * 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? * More slog.Debug and a debug flag?
* Think about timezones * Think about timezones
* Consider more secure auth methods * Consider more secure auth methods
* *Go* dependency-less? <-- this is a terrible idea * *Go* dependency-less? <-- this is a terrible idea
* Better visual feedback from JS?

View file

@ -89,6 +89,7 @@ func (c *Config) Reload() error {
return nil return nil
} }
// ConfigInit loads config on startup
func ConfigInit() Config { func ConfigInit() Config {
cfg := Config{Port: 7101, Username: "admin", Password: "admin"} // Default values are declared here, I guess cfg := Config{Port: 7101, Username: "admin", Password: "admin"} // Default values are declared here, I guess
err := cfg.Reload() err := cfg.Reload()

View file

@ -11,6 +11,7 @@ import (
var ExportPath = "data/export.zip" var ExportPath = "data/export.zip"
// Export saves a .zip archive of the data folder to the passed filename
func Export(filename string) error { func Export(filename string) error {
file, err := os.Create(filename) file, err := os.Create(filename)
if err != nil { if err != nil {

View file

@ -5,6 +5,7 @@ import (
"log" "log"
) )
// FlagInit processes app flags
func FlagInit() { func FlagInit() {
config := flag.String("config", "", "override config file") config := flag.String("config", "", "override config file")
username := flag.String("user", "", "override username") username := flag.String("user", "", "override username")

View file

@ -1,3 +1,4 @@
// Format time in "Jan 02, 2006" format
function formatDate(date) { function formatDate(date) {
let dateFormat = new Intl.DateTimeFormat('en', { let dateFormat = new Intl.DateTimeFormat('en', {
year: 'numeric', 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() { function callEveryHour() {
setInterval(updateDate, 1000 * 60 * 60); setInterval(updateDate, 1000 * 60 * 60);
} }

View file

@ -37,6 +37,7 @@ func InternalError(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./pages/error/500.html") http.ServeFile(w, r, "./pages/error/500.html")
} }
// GetToday renders HTML page for today's view
func GetToday(w http.ResponseWriter, r *http.Request) { func GetToday(w http.ResponseWriter, r *http.Request) {
day, err := ReadToday() day, err := ReadToday()
if err != nil { 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) { func PostToday(w http.ResponseWriter, r *http.Request) {
err := SaveToday([]byte(r.FormValue("day"))) err := SaveToday([]byte(r.FormValue("day")))
if err != nil { if err != nil {
@ -71,6 +73,7 @@ func PostToday(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, r.Header.Get("Referer"), 302) 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) { func GetDays(w http.ResponseWriter, r *http.Request) {
day, err := ListFiles("day") day, err := ListFiles("day")
if err != nil { 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) { func GetDay(w http.ResponseWriter, r *http.Request) {
dayString := chi.URLParam(r, "day") dayString := chi.URLParam(r, "day")
if dayString == "" { if dayString == "" {

View file

@ -9,6 +9,7 @@ import (
"strconv" "strconv"
) )
// Serve starts the app's web server
func Serve() { func Serve() {
r := chi.NewRouter() r := chi.NewRouter()
r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes) r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes)