mirror of
https://github.com/direct-img/direct-img.link.git
synced 2026-03-17 03:01:01 +00:00
Refactor: Extract Brave image search logic
This commit is contained in:
8
functions/_utils/brave.js
Normal file
8
functions/_utils/brave.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export async function braveImageSearch(query, apiKey) {
|
||||
const res = await fetch(`https://api.search.brave.com/res/v1/images/search?q=${encodeURIComponent(query)}&count=50&safesearch=off`, {
|
||||
headers: { "Accept": "application/json", "X-Subscription-Token": apiKey },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
return data.results?.map(r => r.properties?.url || r.thumbnail?.src).filter(url => !!url) || null;
|
||||
}
|
||||
Reference in New Issue
Block a user