mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-09 21:49:48 -05:00
[json] Add endpoint to delete a setting (reset to defaults)
This commit is contained in:
@@ -998,6 +998,43 @@ jsonapi_reply_settings_option_put(struct httpd_request *hreq)
|
||||
return HTTP_NOCONTENT;
|
||||
}
|
||||
|
||||
static int
|
||||
jsonapi_reply_settings_option_delete(struct httpd_request *hreq)
|
||||
{
|
||||
const char *categoryname;
|
||||
const char *optionname;
|
||||
struct settings_category *category;
|
||||
struct settings_option *option;
|
||||
int ret;
|
||||
|
||||
|
||||
categoryname = hreq->uri_parsed->path_parts[2];
|
||||
optionname = hreq->uri_parsed->path_parts[3];
|
||||
|
||||
category = settings_category_get(categoryname);
|
||||
if (!category)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "Invalid category name '%s' given\n", categoryname);
|
||||
return HTTP_NOTFOUND;
|
||||
}
|
||||
|
||||
option = settings_option_get(category, optionname);
|
||||
if (!option)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "Invalid option name '%s' given\n", optionname);
|
||||
return HTTP_NOTFOUND;
|
||||
}
|
||||
|
||||
ret = settings_option_delete(option);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "Error deleting option '%s'\n", optionname);
|
||||
return HTTP_INTERNAL;
|
||||
}
|
||||
|
||||
return HTTP_NOCONTENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Endpoint to retrieve informations about the library
|
||||
*
|
||||
@@ -4167,6 +4204,7 @@ static struct httpd_uri_map adm_handlers[] =
|
||||
{ EVHTTP_REQ_GET, "^/api/settings/[A-Za-z0-9_]+$", jsonapi_reply_settings_category_get },
|
||||
{ EVHTTP_REQ_GET, "^/api/settings/[A-Za-z0-9_]+/[A-Za-z0-9_]+$", jsonapi_reply_settings_option_get },
|
||||
{ EVHTTP_REQ_PUT, "^/api/settings/[A-Za-z0-9_]+/[A-Za-z0-9_]+$", jsonapi_reply_settings_option_put },
|
||||
{ EVHTTP_REQ_DELETE, "^/api/settings/[A-Za-z0-9_]+/[A-Za-z0-9_]+$", jsonapi_reply_settings_option_delete },
|
||||
{ EVHTTP_REQ_GET, "^/api/library$", jsonapi_reply_library },
|
||||
{ EVHTTP_REQ_GET |
|
||||
EVHTTP_REQ_PUT, "^/api/update$", jsonapi_reply_update },
|
||||
|
||||
@@ -241,3 +241,12 @@ settings_option_setstr(struct settings_option *option, const char *value)
|
||||
|
||||
return db_admin_set(option->name, value);
|
||||
}
|
||||
|
||||
int
|
||||
settings_option_delete(struct settings_option *option)
|
||||
{
|
||||
if (!option)
|
||||
return -1;
|
||||
|
||||
return db_admin_delete(option->name);
|
||||
}
|
||||
|
||||
@@ -64,4 +64,7 @@ settings_option_setbool(struct settings_option *option, bool value);
|
||||
int
|
||||
settings_option_setstr(struct settings_option *option, const char *value);
|
||||
|
||||
int
|
||||
settings_option_delete(struct settings_option *option);
|
||||
|
||||
#endif /* __SETTINGS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user