u
This commit is contained in:
@@ -966,6 +966,40 @@ export const serper = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/serper/image
|
||||
* Crawl image from URL, crop white/transparency margins, resize to max 1000px, return AVIF Blob.
|
||||
*
|
||||
* @param {string} url - External image URL to crawl and process
|
||||
* @param {object} [options]
|
||||
* @param {AbortSignal} [options.signal] - Abort controller signal
|
||||
* @returns {Promise<Blob>} AVIF image blob
|
||||
*/
|
||||
async fetchImage(url, { signal } = {}) {
|
||||
const res = await fetch('/api/serper/image', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ url }),
|
||||
signal,
|
||||
});
|
||||
if (!res.ok) {
|
||||
let message = res.statusText;
|
||||
try {
|
||||
const data = await res.json();
|
||||
message = data.error || data.message || message;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
const err = new Error(message || `Request failed (${res.status})`);
|
||||
err.status = res.status;
|
||||
throw err;
|
||||
}
|
||||
return await res.blob();
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user