diff --git a/README.md b/README.md index c392f5a..8007def 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,48 @@ saved in a file called '.dau.json' in your home directory. The first time you run it, you will need to configure at least the discord web hook and the watch path for `dau` to be useful. -While running, `dau` will continually scan a directory for new images, and each time it finds one it will -upload it to discord, via the discord web hook. +While running, `dau` will continually scan a directory for new images, and each time it finds one it will upload it to discord, via the discord web hook. `dau` will only upload "new" screenshots, where "new" means a file that appears in a directory that it is watching, if it appears *after* it has started executing. Thus, you do not have to worry about pointing `dau` at a directory full of images, it will only upload new ones. +## Configuration options + +See the web interface at http://localhost:9090 to configure `dau`. + +### 'Discord WebHook URL' + +The webhook URL from Discord. See https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks +for more information on setting one up. + +### 'Bot Username' + +This is completely optional and can be any arbitrary string. It makes the upload +appear to come from a different user (though this is visual only, and does not +actually hide the bot identity in any way). You might like to set it to your own +discord name. + +### 'Directory to watch' + +This is the path that `dau` will periodically inspect, looking for new images. +Note that subdirectories are also scanned. You need to enter the full filesystem +path here. + +### 'Period between filesystem checks' + +This is the number of seconds between which `dau` will look for new images. + +### 'Do not watermark images' + +This will disable the watermarking of images. I like it when you don't set this :-) + +### 'Files to exclude' + +This is a string to match against the filename to check for exclusions. The common +use case is to use 'thumbnail' or similar if your image directory contains additional +thumbnail files. + ## Limitations/bugs * Only files ending jpg, gif or png are uploaded. diff --git a/config/config.go b/config/config.go index 300e371..8505380 100644 --- a/config/config.go +++ b/config/config.go @@ -34,7 +34,7 @@ func LoadOrInit() { Config.Watch = 10 SaveConfig() } else { - LoadConfig() + LoadConfig() } } diff --git a/data/config.html b/data/config.html index 0377f50..a10c6b8 100644 --- a/data/config.html +++ b/data/config.html @@ -81,6 +81,21 @@ +
+ diff --git a/dau.go b/dau.go index b70135c..f92dbc4 100644 --- a/dau.go +++ b/dau.go @@ -114,7 +114,6 @@ func checkUpdates() { func parseOptions() { // Declare the flags to be used - excludeFlag := getopt.StringLong("exclude", 'x', "", "exclude files containing this string") helpFlag := getopt.BoolLong("help", 'h', "help") versionFlag := getopt.BoolLong("version", 'v', "show version") getopt.SetParameters("") @@ -132,15 +131,8 @@ func parseOptions() { os.Exit(0) } - // if !getopt.IsSet("webhook") { - // log.Fatal("ERROR: You must specify a --webhook URL") - // } - // grab the config config.LoadOrInit() - - // overrides from command line - config.Config.Exclude = *excludeFlag } func checkFile(path string, f os.FileInfo, err error) error { diff --git a/web/server.go b/web/server.go index 9af4f98..b1e28a7 100644 --- a/web/server.go +++ b/web/server.go @@ -247,6 +247,30 @@ func getSetDirectory(w http.ResponseWriter, r *http.Request) { } } +func getSetExclude(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + if r.Method == "GET" { + getResponse := valueStringResponse{Success: true, Value: config.Config.Exclude} + // I can't see any way this will fail + js, _ := json.Marshal(getResponse) + w.Write(js) + } else if r.Method == "POST" { + err := r.ParseForm() + if err != nil { + log.Fatal(err) + } + config.Config.Exclude = r.PostForm.Get("value") + config.SaveConfig() + + postResponse := valueStringResponse{Success: true, Value: config.Config.Exclude} + + js, _ := json.Marshal(postResponse) + w.Write(js) + } +} + + func StartWebServer() { http.HandleFunc("/", getStatic) http.HandleFunc("/rest/config/webhook", getSetWebhook) @@ -254,6 +278,8 @@ func StartWebServer() { http.HandleFunc("/rest/config/watch", getSetWatch) http.HandleFunc("/rest/config/nowatermark", getSetNoWatermark) http.HandleFunc("/rest/config/directory", getSetDirectory) + http.HandleFunc("/rest/config/exclude", getSetExclude) + log.Print("Starting web server on http://localhost:9090") err := http.ListenAndServe(":9090", nil) // set listen port