mirror of
https://github.com/pi-hole/FTL.git
synced 2025-12-24 19:35:29 +00:00
Merge pull request #2718 from pi-hole/gravity-colour-tweak
Make colour output optional in streaming gravity API call
This commit is contained in:
@@ -121,7 +121,15 @@ static int run_and_stream_command(struct ftl_conn *api, const char *path, const
|
|||||||
|
|
||||||
int api_action_gravity(struct ftl_conn *api)
|
int api_action_gravity(struct ftl_conn *api)
|
||||||
{
|
{
|
||||||
return run_and_stream_command(api, "/usr/local/bin/pihole", (const char *const []){ "pihole", "-g", NULL }, "FORCE_COLOR");
|
// Only set FORCE_COLOR if the client explicitly requests it via "color=true" query parameter
|
||||||
|
// This prevents ANSI escape codes from being included in the output for API consumers that don't need them
|
||||||
|
bool color = false;
|
||||||
|
const char *query = api->request != NULL ? api->request->query_string : "";
|
||||||
|
if(query != NULL)
|
||||||
|
get_bool_var(query, "color", &color);
|
||||||
|
|
||||||
|
const char *extra_env = color ? "FORCE_COLOR" : NULL;
|
||||||
|
return run_and_stream_command(api, "/usr/local/bin/pihole", (const char *const []){ "pihole", "-g", NULL }, extra_env);
|
||||||
}
|
}
|
||||||
|
|
||||||
int api_action_restartDNS(struct ftl_conn *api)
|
int api_action_restartDNS(struct ftl_conn *api)
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ components:
|
|||||||
gravity:
|
gravity:
|
||||||
post:
|
post:
|
||||||
summary: Run gravity
|
summary: Run gravity
|
||||||
|
parameters:
|
||||||
|
- $ref: 'action.yaml#/components/parameters/color'
|
||||||
tags:
|
tags:
|
||||||
- Actions
|
- Actions
|
||||||
operationId: "action_gravity"
|
operationId: "action_gravity"
|
||||||
description: |
|
description: |
|
||||||
Update Pi-hole's adlists by running `pihole -g`. The output of the process is streamed with chunked encoding.
|
Update Pi-hole's adlists by running `pihole -g`. The output of the process is streamed with chunked encoding. Use the optional `color` query parameter to include ANSI color escape codes in the output.
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: OK
|
description: OK
|
||||||
@@ -183,6 +185,17 @@ components:
|
|||||||
- $ref: 'action.yaml#/components/errors/forbidden'
|
- $ref: 'action.yaml#/components/errors/forbidden'
|
||||||
- $ref: 'common.yaml#/components/schemas/took'
|
- $ref: 'common.yaml#/components/schemas/took'
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
color:
|
||||||
|
name: color
|
||||||
|
in: query
|
||||||
|
description: Include ANSI color escape codes in the streamed output. Defaults to false to prevent colored output for API consumers that don't need formatting.
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
example: true
|
||||||
|
required: false
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
forbidden:
|
forbidden:
|
||||||
description: |
|
description: |
|
||||||
|
|||||||
Reference in New Issue
Block a user