Sanity check destinations

This commit is contained in:
Justin Hawkins 2022-04-09 23:42:38 +09:30
parent 4f33603a0c
commit f899b9c0c2
2 changed files with 15 additions and 3 deletions

View File

@ -175,6 +175,17 @@ func (c *Config) UpdateFromJSON(j []byte) error {
}
}
// check destinations
for _, dest := range newConfig.Destinations {
s, err := os.Stat(dest.Path)
if err != nil {
return fmt.Errorf("destination '%s' (%s) is bad: %s", dest.Name, dest.Path, err)
}
if !s.IsDir() {
return fmt.Errorf("destination '%s' (%s) is not a directory", dest.Name, dest.Path)
}
}
*c = newConfig
return nil
}

View File

@ -114,8 +114,9 @@
<form class="pure-form gropple-config">
<fieldset>
<legend>Destinations</legend>
<p>You can specify custom destinations here. You can specify that
downloads be moved to one of these directories after complete.</p>
<p>You can specify custom destinations (directories) here. Downloads can be
moved to one of these directories after completion from the index page,
if you do not want them to be left in the download path above.</p>
</p>
<template x-for="(dest, i) in config.destinations">
<div>
@ -137,7 +138,7 @@
</div>
</template>
<button class="pure-button button-add" href="#" @click.prevent="config.destinations.push({name: 'new destination', path: '/'});">add destination</button>
<button class="pure-button button-add" href="#" @click.prevent="config.destinations.push({name: 'new destination', path: '/tmp'});">add destination</button>
</fieldset>
</form>