Clean up logging and improve web interface

This commit is contained in:
Justin Hawkins 2021-02-07 22:06:19 +10:30
parent 942f81a378
commit 2d1ac3c803
5 changed files with 10 additions and 12 deletions

View File

@ -26,7 +26,9 @@ func LoadOrInit() {
log.Printf("Trying to load from %s\n", configPath) log.Printf("Trying to load from %s\n", configPath)
_, err := os.Stat(configPath) _, err := os.Stat(configPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Printf("Initialising empty config") log.Printf("NOTE: No config file, writing out sample configuration")
log.Printf("You need to set the configuration via the web interface")
Config.WebHookURL = "" Config.WebHookURL = ""
Config.Path = homeDir() + string(os.PathSeparator) + "screenshots" Config.Path = homeDir() + string(os.PathSeparator) + "screenshots"
Config.Watch = 10 Config.Watch = 10

View File

@ -51,7 +51,7 @@
<form class=""> <form class="">
<div class="form-row align-items-center config-item" data-key="watch"> <div class="form-row align-items-center config-item" data-key="watch">
<div class="col-sm-5 my-1"> <div class="col-sm-5 my-1">
<span>Period between filesystem checks</span> <span>Period between filesystem checks (seconds)</span>
</div> </div>
<div class="col-sm-4 my-1"> <div class="col-sm-4 my-1">
<label class="sr-only" for="inlineFormInputName">Seconds</label> <label class="sr-only" for="inlineFormInputName">Seconds</label>
@ -81,9 +81,6 @@
</div> </div>
</form> </form>
<p class="lead">
<a href="#" class="btn btn-lg btn-secondary">Learn more</a>
</p>
</main> </main>

View File

@ -1,8 +1,8 @@
<main role="main" class="inner DAU"> <main role="main" class="inner DAU">
<h1 class="DAU-heading">Discord Auto Upload</h1> <h1 class="DAU-heading">Discord Auto Upload</h1>
<p class="lead">Hey look it's DAU.</p> <p class="lead">Hey look, it's DAU :-)</p>
<p class="lead"> <p class="lead">
<a href="#" class="btn btn-lg btn-secondary">Learn more</a> <a href="https://github.com/tardisx/discord-auto-upload" class="btn btn-lg btn-secondary">Learn more</a>
</p> </p>
</main> </main>

8
dau.go
View File

@ -55,7 +55,7 @@ func main() {
} }
lastCheck = newLastCheck lastCheck = newLastCheck
} }
log.Print("sleeping before next check") log.Printf("sleeping for %ds before next check of %s", config.Config.Watch, config.Config.Path)
time.Sleep(time.Duration(config.Config.Watch) * time.Second) time.Sleep(time.Duration(config.Config.Watch) * time.Second)
} }
} }
@ -63,11 +63,11 @@ func main() {
func checkPath(path string) bool { func checkPath(path string) bool {
src, err := os.Stat(path) src, err := os.Stat(path)
if err != nil { if err != nil {
log.Println("path problem: ", err) log.Printf("Problem with path '%s': %s", path, err)
return false return false
} }
if !src.IsDir() { if !src.IsDir() {
log.Println(path, " is not a directory") log.Printf("Problem with path '%s': is not a directory", path)
return false return false
} }
return true return true
@ -287,7 +287,7 @@ func sleepForRetries(retry int) {
} }
retryTime := (6-retry)*(6-retry) + 6 retryTime := (6-retry)*(6-retry) + 6
log.Printf("Will retry in %d seconds (%d remaining attempts)", retryTime, retry) log.Printf("Will retry in %d seconds (%d remaining attempts)", retryTime, retry)
// time.Sleep(time.Duration(retryTime) * time.Second) time.Sleep(time.Duration(retryTime) * time.Second)
} }
func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) { func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {

View File

@ -206,7 +206,6 @@ func getSetNoWatermark(w http.ResponseWriter, r *http.Request) {
} }
func getSetDirectory(w http.ResponseWriter, r *http.Request) { func getSetDirectory(w http.ResponseWriter, r *http.Request) {
log.Print("ok")
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if r.Method == "GET" { if r.Method == "GET" {