* /remove_url: use JSON input data format
This commit is contained in:
parent
276d87a218
commit
c93cb43db8
19
control.go
19
control.go
|
@ -676,19 +676,18 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) {
|
func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
parameters, err := parseParametersFromBody(r.Body)
|
|
||||||
|
type request struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
req := request{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "failed to parse parameters from body: %s", err)
|
httpError(w, http.StatusBadRequest, "Failed to parse request body json: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url, ok := parameters["url"]
|
if valid := govalidator.IsRequestURL(req.URL); !valid {
|
||||||
if !ok {
|
|
||||||
http.Error(w, "URL parameter was not specified", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if valid := govalidator.IsRequestURL(url); !valid {
|
|
||||||
http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest)
|
http.Error(w, "URL parameter is not valid request URL", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -697,7 +696,7 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) {
|
||||||
config.Lock()
|
config.Lock()
|
||||||
newFilters := config.Filters[:0]
|
newFilters := config.Filters[:0]
|
||||||
for _, filter := range config.Filters {
|
for _, filter := range config.Filters {
|
||||||
if filter.URL != url {
|
if filter.URL != req.URL {
|
||||||
newFilters = append(newFilters, filter)
|
newFilters = append(newFilters, filter)
|
||||||
} else {
|
} else {
|
||||||
// Remove the filter file
|
// Remove the filter file
|
||||||
|
|
|
@ -484,15 +484,13 @@ paths:
|
||||||
operationId: filteringRemoveURL
|
operationId: filteringRemoveURL
|
||||||
summary: 'Remove filter URL'
|
summary: 'Remove filter URL'
|
||||||
consumes:
|
consumes:
|
||||||
- text/plain
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
- in: body
|
- in: "body"
|
||||||
name: url
|
name: "body"
|
||||||
description: 'Previously added URL containing filtering rules'
|
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
$ref: "#/definitions/RemoveUrlRequest"
|
||||||
example: 'url=https://filters.adtidy.org/windows/filters/15.txt'
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
@ -1298,6 +1296,14 @@ definitions:
|
||||||
description: "URL containing filtering rules"
|
description: "URL containing filtering rules"
|
||||||
type: "string"
|
type: "string"
|
||||||
example: "https://filters.adtidy.org/windows/filters/15.txt"
|
example: "https://filters.adtidy.org/windows/filters/15.txt"
|
||||||
|
RemoveUrlRequest:
|
||||||
|
type: "object"
|
||||||
|
description: "/remove_url request data"
|
||||||
|
properties:
|
||||||
|
url:
|
||||||
|
description: "Previously added URL containing filtering rules"
|
||||||
|
type: "string"
|
||||||
|
example: "https://filters.adtidy.org/windows/filters/15.txt"
|
||||||
QueryLogItem:
|
QueryLogItem:
|
||||||
type: "object"
|
type: "object"
|
||||||
description: "Query log item"
|
description: "Query log item"
|
||||||
|
|
Loading…
Reference in New Issue