Add Exclude to the config as well.

This commit is contained in:
Justin Hawkins 2021-02-09 22:07:40 +10:30
parent 2d1ac3c803
commit 23c0aa2a34
5 changed files with 79 additions and 11 deletions

View File

@ -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 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. `dau` to be useful.
While running, `dau` will continually scan a directory for new images, and each time it finds one it will 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.
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. `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. 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 ## Limitations/bugs
* Only files ending jpg, gif or png are uploaded. * Only files ending jpg, gif or png are uploaded.

View File

@ -34,7 +34,7 @@ func LoadOrInit() {
Config.Watch = 10 Config.Watch = 10
SaveConfig() SaveConfig()
} else { } else {
LoadConfig() LoadConfig()
} }
} }

View File

@ -81,6 +81,21 @@
</div> </div>
</form> </form>
<form class="">
<div class="form-row align-items-center config-item" data-key="exclude">
<div class="col-sm-5 my-1">
<span>Files to exclude</span>
</div>
<div class="col-sm-4 my-1">
<label class="sr-only" for="input-exclude">Name</label>
<input type="text" id="input-exclude" class="form-control rest-field" placeholder="">
</div>
<div class="col-auto my-1">
<button type="submit" class="btn btn-primary">update</button>
</div>
</div>
</form>
</main> </main>

8
dau.go
View File

@ -114,7 +114,6 @@ func checkUpdates() {
func parseOptions() { func parseOptions() {
// Declare the flags to be used // Declare the flags to be used
excludeFlag := getopt.StringLong("exclude", 'x', "", "exclude files containing this string")
helpFlag := getopt.BoolLong("help", 'h', "help") helpFlag := getopt.BoolLong("help", 'h', "help")
versionFlag := getopt.BoolLong("version", 'v', "show version") versionFlag := getopt.BoolLong("version", 'v', "show version")
getopt.SetParameters("") getopt.SetParameters("")
@ -132,15 +131,8 @@ func parseOptions() {
os.Exit(0) os.Exit(0)
} }
// if !getopt.IsSet("webhook") {
// log.Fatal("ERROR: You must specify a --webhook URL")
// }
// grab the config // grab the config
config.LoadOrInit() config.LoadOrInit()
// overrides from command line
config.Config.Exclude = *excludeFlag
} }
func checkFile(path string, f os.FileInfo, err error) error { func checkFile(path string, f os.FileInfo, err error) error {

View File

@ -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() { func StartWebServer() {
http.HandleFunc("/", getStatic) http.HandleFunc("/", getStatic)
http.HandleFunc("/rest/config/webhook", getSetWebhook) http.HandleFunc("/rest/config/webhook", getSetWebhook)
@ -254,6 +278,8 @@ func StartWebServer() {
http.HandleFunc("/rest/config/watch", getSetWatch) http.HandleFunc("/rest/config/watch", getSetWatch)
http.HandleFunc("/rest/config/nowatermark", getSetNoWatermark) http.HandleFunc("/rest/config/nowatermark", getSetNoWatermark)
http.HandleFunc("/rest/config/directory", getSetDirectory) http.HandleFunc("/rest/config/directory", getSetDirectory)
http.HandleFunc("/rest/config/exclude", getSetExclude)
log.Print("Starting web server on http://localhost:9090") log.Print("Starting web server on http://localhost:9090")
err := http.ListenAndServe(":9090", nil) // set listen port err := http.ListenAndServe(":9090", nil) // set listen port