Add RAW field to customAPIResponseData

pull/892/head
vanderock1 2025-12-03 14:30:18 +07:00 committed by GitHub
parent 36d5ae023f
commit feeb51e53e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 54 additions and 44 deletions

@ -195,6 +195,7 @@ func (req *CustomAPIRequest) initialize() error {
type customAPIResponseData struct { type customAPIResponseData struct {
JSON decoratedGJSONResult JSON decoratedGJSONResult
Response *http.Response Response *http.Response
RAW strings
} }
type customAPITemplateData struct { type customAPITemplateData struct {
@ -233,6 +234,7 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
return &customAPIResponseData{ return &customAPIResponseData{
JSON: decoratedGJSONResult{gjson.Result{}}, JSON: decoratedGJSONResult{gjson.Result{}},
Response: &http.Response{}, Response: &http.Response{},
RAW: nil,
}, nil }, nil
} }
@ -240,7 +242,11 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
req.bodyReader.Seek(0, io.SeekStart) req.bodyReader.Seek(0, io.SeekStart)
} }
client := ternary(req.AllowInsecure, defaultInsecureHTTPClient, defaultHTTPClient) client := defaultHTTPClient
if req.AllowInsecure {
client = defaultInsecureHTTPClient
}
resp, err := client.Do(req.httpRequest.WithContext(ctx)) resp, err := client.Do(req.httpRequest.WithContext(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
@ -261,20 +267,24 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
truncatedBody += "... <truncated>" truncatedBody += "... <truncated>"
} }
slog.Error("Invalid response JSON in custom API widget", "url", req.httpRequest.URL.String(), "body", truncatedBody) slog.Error("Invalid response JSON in custom API widget",
"url", req.httpRequest.URL.String(),
"body", truncatedBody,
)
return nil, errors.New("invalid response JSON") return nil, errors.New("invalid response JSON")
} }
return nil, fmt.Errorf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode)) return nil, fmt.Errorf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode))
} }
return &customAPIResponseData{ return &customAPIResponseData{
JSON: decoratedGJSONResult{gjson.Parse(body)}, JSON: decoratedGJSONResult{gjson.Parse(body)},
Response: resp, Response: resp,
RAW: body,
}, nil }, nil
} }
func fetchAndRenderCustomAPIRequest( func fetchAndRenderCustomAPIRequest(
primaryReq *CustomAPIRequest, primaryReq *CustomAPIRequest,
subReqs map[string]*CustomAPIRequest, subReqs map[string]*CustomAPIRequest,