feat: add Brave Search as web search engine provider (#1481)
* feat: add Brave Search as web search engine provider * docs: update README
This commit is contained in:
@@ -378,6 +378,23 @@ function M.web_search(opts, on_log)
|
||||
if resp.status ~= 200 then return nil, "Error: " .. resp.body end
|
||||
local jsn = vim.json.decode(resp.body)
|
||||
return search_engine.format_response_body(jsn)
|
||||
elseif provider_type == "brave" then
|
||||
local query_params = vim.tbl_deep_extend("force", {
|
||||
q = opts.query,
|
||||
}, search_engine.extra_request_body)
|
||||
local query_string = ""
|
||||
for key, value in pairs(query_params) do
|
||||
query_string = query_string .. key .. "=" .. vim.uri_encode(value) .. "&"
|
||||
end
|
||||
local resp = curl.get("https://api.search.brave.com/res/v1/web/search?" .. query_string, {
|
||||
headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
["X-Subscription-Token"] = api_key,
|
||||
},
|
||||
})
|
||||
if resp.status ~= 200 then return nil, "Error: " .. resp.body end
|
||||
local jsn = vim.json.decode(resp.body)
|
||||
return search_engine.format_response_body(jsn)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user