mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-16 20:24:15 +03:00
Merge: * minor API changes
Close #785 * commit '7f5ac19b592c2a63e52a5e5319e9e8eb687c7410': * client: use JSON for filtering/remove_url * /remove_url: use JSON input data format - openapi: correct format - openapi: fix /add_url
This commit is contained in:
commit
450e2ac549
@ -301,6 +301,7 @@
|
|||||||
"table_statistics": "Requests count (last 24 hours)",
|
"table_statistics": "Requests count (last 24 hours)",
|
||||||
"clients_not_found": "No clients found",
|
"clients_not_found": "No clients found",
|
||||||
"client_confirm_delete": "Are you sure you want to delete client \"{{key}}\"?",
|
"client_confirm_delete": "Are you sure you want to delete client \"{{key}}\"?",
|
||||||
|
"filter_confirm_delete": "Are you sure you want to delete filter?",
|
||||||
"auto_clients_title": "Clients (runtime)",
|
"auto_clients_title": "Clients (runtime)",
|
||||||
"auto_clients_desc": "Data on the clients that use AdGuard Home, but not stored in the configuration",
|
"auto_clients_desc": "Data on the clients that use AdGuard Home, but not stored in the configuration",
|
||||||
"access_title": "Access settings",
|
"access_title": "Access settings",
|
||||||
|
@ -188,15 +188,14 @@ export default class Api {
|
|||||||
return this.makeRequest(path, method, config);
|
return this.makeRequest(path, method, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFilter(url) {
|
removeFilter(config) {
|
||||||
const { path, method } = this.FILTERING_REMOVE_FILTER;
|
const { path, method } = this.FILTERING_REMOVE_FILTER;
|
||||||
const parameter = 'url';
|
const parameters = {
|
||||||
const requestBody = `${parameter}=${url}`;
|
data: config,
|
||||||
const config = {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
data: requestBody,
|
|
||||||
header: { 'Content-Type': 'text/plain' },
|
|
||||||
};
|
};
|
||||||
return this.makeRequest(path, method, config);
|
|
||||||
|
return this.makeRequest(path, method, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
setRules(rules) {
|
setRules(rules) {
|
||||||
@ -424,10 +423,10 @@ export default class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Per-client settings
|
// Per-client settings
|
||||||
GET_CLIENTS = { path: 'clients', method: 'GET' }
|
GET_CLIENTS = { path: 'clients', method: 'GET' };
|
||||||
ADD_CLIENT = { path: 'clients/add', method: 'POST' }
|
ADD_CLIENT = { path: 'clients/add', method: 'POST' };
|
||||||
DELETE_CLIENT = { path: 'clients/delete', method: 'POST' }
|
DELETE_CLIENT = { path: 'clients/delete', method: 'POST' };
|
||||||
UPDATE_CLIENT = { path: 'clients/update', method: 'POST' }
|
UPDATE_CLIENT = { path: 'clients/update', method: 'POST' };
|
||||||
|
|
||||||
getClients() {
|
getClients() {
|
||||||
const { path, method } = this.GET_CLIENTS;
|
const { path, method } = this.GET_CLIENTS;
|
||||||
|
@ -32,6 +32,13 @@ class Filters extends Component {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleDelete = (url) => {
|
||||||
|
// eslint-disable-next-line no-alert
|
||||||
|
if (window.confirm(this.props.t('filter_confirm_delete'))) {
|
||||||
|
this.props.removeFilter({ url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
columns = [{
|
columns = [{
|
||||||
Header: <Trans>enabled_table_header</Trans>,
|
Header: <Trans>enabled_table_header</Trans>,
|
||||||
accessor: 'enabled',
|
accessor: 'enabled',
|
||||||
@ -62,7 +69,7 @@ class Filters extends Component {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-icon btn-outline-secondary btn-sm"
|
className="btn btn-icon btn-outline-secondary btn-sm"
|
||||||
onClick={() => this.props.removeFilter(value)}
|
onClick={() => this.handleDelete(value)}
|
||||||
title={this.props.t('delete_table_action')}
|
title={this.props.t('delete_table_action')}
|
||||||
>
|
>
|
||||||
<svg className="icons">
|
<svg className="icons">
|
||||||
|
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
|
||||||
|
@ -466,15 +466,13 @@ paths:
|
|||||||
operationId: filteringAddURL
|
operationId: filteringAddURL
|
||||||
summary: 'Add filter URL'
|
summary: 'Add filter URL'
|
||||||
consumes:
|
consumes:
|
||||||
- text/plain
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
- in: body
|
- in: "body"
|
||||||
name: url
|
name: "body"
|
||||||
description: 'URL containing filtering rules'
|
required: true
|
||||||
required: true
|
schema:
|
||||||
schema:
|
$ref: "#/definitions/AddUrlRequest"
|
||||||
type: string
|
|
||||||
example: 'url=https://filters.adtidy.org/windows/filters/15.txt'
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
@ -486,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:
|
$ref: "#/definitions/RemoveUrlRequest"
|
||||||
type: string
|
|
||||||
example: 'url=https://filters.adtidy.org/windows/filters/15.txt'
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
@ -1290,6 +1286,24 @@ definitions:
|
|||||||
type:
|
type:
|
||||||
type: "string"
|
type: "string"
|
||||||
example: "A"
|
example: "A"
|
||||||
|
AddUrlRequest:
|
||||||
|
type: "object"
|
||||||
|
description: "/add_url request data"
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: "string"
|
||||||
|
url:
|
||||||
|
description: "URL containing filtering rules"
|
||||||
|
type: "string"
|
||||||
|
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
Block a user