-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0 results #7
Comments
I have no problems with test code. Can you give information about your OS, location. And when you try directly look at http://www.google.com/search?udm=2&tbm=isch&q=akif9748 , can you reach the site? |
OS: FreeBSD |
This is essentially Google returning a 429 (Too Many Requests) response. Unfortunately, the package doesn't include a method for caching results or bypassing Google's rate limit. However, you can improve the caching system to avoid hitting the rate limit. I was using the lru-cache package to make requests, retrieve music artist icons, and display them in a Next.js app. import { LRUCache } from 'lru-cache'
class Cache<K extends {} = string, V extends {} = string> {
private cache: LRUCache<K, V>
constructor() {
this.cache = new LRUCache({
max: 50,
ttl: 1000 * 60 * 60 * 12,
})
}
get(key: K) {
const value = this.cache.get(key)
return value
}
set(key: K, value: V) {
this.cache.set(key, value)
}
has(key: K) {
return this.cache.has(key)
}
}
export const cache = new Cache() async function getImage(query: string, index = 0) {
const cacheKey = `${query}-${index}`
const cachedResult = cache.get(cacheKey)
if (cachedResult) {
return cachedResult
}
const results = await gis(query, { query: { safe: 'on' } })
console.log(`Found ${results.length} results for ${query}.`)
const result = results[Math.min(index, results.length - 1)]
if (result?.url) {
const cleanUrl = result.url.replace(/&w=\d+&q=\d+/g, '')
cache.set(cacheKey, cleanUrl)
return cleanUrl
}
return undefined
} |
cool |
It returns an empty array
The text was updated successfully, but these errors were encountered: