Support noWatermark config
This commit is contained in:
parent
6e493522c8
commit
6b1867f35f
@ -63,6 +63,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form class="">
|
||||||
|
<div class="form-row align-items-center config-item" data-key="nowatermark">
|
||||||
|
<div class="col-sm-5 my-1">
|
||||||
|
<span>Do not watermark images</span>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4 my-1">
|
||||||
|
<div class="custom-control custom-switch">
|
||||||
|
<input type="checkbox" class="custom-control-input rest-field rest-field-boolean" id="customSwitch1">
|
||||||
|
<label class="custom-control-label" for="customSwitch1"><span style="display: none;">😭</span></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto my-1">
|
||||||
|
<button type="submit" class="btn btn-primary">update</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<p class="lead">
|
<p class="lead">
|
||||||
<a href="#" class="btn btn-lg btn-secondary">Learn more</a>
|
<a href="#" class="btn btn-lg btn-secondary">Learn more</a>
|
||||||
</p>
|
</p>
|
||||||
@ -78,7 +95,13 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
$.ajax({ method: 'get', url: '/rest/config/'+key})
|
$.ajax({ method: 'get', url: '/rest/config/'+key})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
$(".config-item[data-key='"+key+"']").find('.rest-field').val(data.Value);
|
var this_el = $(".config-item[data-key='"+key+"']").find('.rest-field');
|
||||||
|
if (this_el.hasClass('rest-field-boolean')) {
|
||||||
|
this_el.prop('checked', data.Value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this_el.val(data.Value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,6 +109,9 @@ $(document).ready(function() {
|
|||||||
$('.config-item button').on('click', function(e,f) {
|
$('.config-item button').on('click', function(e,f) {
|
||||||
key = $(this).parents('.config-item').data('key');
|
key = $(this).parents('.config-item').data('key');
|
||||||
val = $(this).parents('.config-item').find('.rest-field').val();
|
val = $(this).parents('.config-item').find('.rest-field').val();
|
||||||
|
if ($(this).parents('.config-item').find('.rest-field-boolean')) {
|
||||||
|
val = $(this).parents('.config-item').find('.rest-field').prop('checked') ? 1 : 0;
|
||||||
|
}
|
||||||
$.post('/rest/config/'+key, { value: val })
|
$.post('/rest/config/'+key, { value: val })
|
||||||
.done(function(d) {
|
.done(function(d) {
|
||||||
if (d.Success) {
|
if (d.Success) {
|
||||||
|
@ -25,6 +25,11 @@ type valueStringResponse struct {
|
|||||||
Value string `json: 'value'`
|
Value string `json: 'value'`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type valueBooleanResponse struct {
|
||||||
|
Success bool `json: 'success'`
|
||||||
|
Value bool `json: 'value'`
|
||||||
|
}
|
||||||
|
|
||||||
type errorResponse struct {
|
type errorResponse struct {
|
||||||
Success bool `json: 'success'`
|
Success bool `json: 'success'`
|
||||||
Error string `json: 'error'`
|
Error string `json: 'error'`
|
||||||
@ -159,6 +164,43 @@ func getSetWatch(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSetNoWatermark(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if r.Method == "GET" {
|
||||||
|
getResponse := valueBooleanResponse{Success: true, Value: config.Config.NoWatermark}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := r.PostForm.Get("value")
|
||||||
|
|
||||||
|
if v != "0" && v != "1" {
|
||||||
|
response := errorResponse{Success: false, Error: fmt.Sprintf("Bad value for nowatermark: %v", err)}
|
||||||
|
js, _ := json.Marshal(response)
|
||||||
|
w.Write(js)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if v == "0" {
|
||||||
|
config.Config.NoWatermark = false
|
||||||
|
} else {
|
||||||
|
config.Config.NoWatermark = true
|
||||||
|
}
|
||||||
|
postResponse := valueBooleanResponse{Success: true, Value: config.Config.NoWatermark}
|
||||||
|
|
||||||
|
js, _ := json.Marshal(postResponse)
|
||||||
|
w.Write(js)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func getSetDirectory(w http.ResponseWriter, r *http.Request) {
|
func getSetDirectory(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Print("ok")
|
log.Print("ok")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@ -205,6 +247,7 @@ func StartWebServer() {
|
|||||||
http.HandleFunc("/rest/config/webhook", getSetWebhook)
|
http.HandleFunc("/rest/config/webhook", getSetWebhook)
|
||||||
http.HandleFunc("/rest/config/username", getSetUsername)
|
http.HandleFunc("/rest/config/username", getSetUsername)
|
||||||
http.HandleFunc("/rest/config/watch", getSetWatch)
|
http.HandleFunc("/rest/config/watch", getSetWatch)
|
||||||
|
http.HandleFunc("/rest/config/nowatermark", getSetNoWatermark)
|
||||||
http.HandleFunc("/rest/config/directory", getSetDirectory)
|
http.HandleFunc("/rest/config/directory", getSetDirectory)
|
||||||
|
|
||||||
log.Print("Starting web server on http://localhost:9090")
|
log.Print("Starting web server on http://localhost:9090")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user