1- import { env } from './env.ts'
21import * as cache from './cache.ts'
3-
4- export type SearchRequestInfo = {
5- title : string
6- totalResults : string
7- searchTerms : string
8- count : number
9- startIndex : number
10- inputEncoding : string
11- outputEncoding : string
12- safe : string
13- cx : string
14- }
2+ import { env } from './env.ts'
153
164export type SearchItem = {
175 kind : string
@@ -25,19 +13,12 @@ export type SearchItem = {
2513 htmlFormattedUrl : string
2614}
2715
28- export type SearchQueries = {
29- request : Array < SearchRequestInfo >
30- }
31-
32- export type SearchUrl = {
33- type : string
34- template : string
35- }
36-
3716export type SearchResult = {
3817 kind : string
39- url : SearchUrl
40- queries : SearchQueries
18+ // deno-lint-ignore no-explicit-any
19+ url : any
20+ // deno-lint-ignore no-explicit-any
21+ queries : any
4122 items : Array < SearchItem >
4223}
4324
@@ -51,7 +32,7 @@ export const googleSearch = async (query: string): Promise<SearchResult> => {
5132 const cacheKey = 'search:' + query
5233
5334 const cached = await cache . get ( cacheKey )
54- if ( cached && cached . items ? .length > 0 ) {
35+ if ( cached && cached . items && cached . items . length > 0 ) {
5536 return cached
5637 }
5738
@@ -73,7 +54,9 @@ export const googleSearch = async (query: string): Promise<SearchResult> => {
7354 if ( ! res . ok ) {
7455 const errorMessage = json . error ?. message || 'Unknown error'
7556 const errorCode = json . error ?. code || res . status
76- throw new Error ( 'Google Search API error (' + errorCode + '): ' + errorMessage )
57+ throw new Error (
58+ [ 'Google Search API error (' , errorCode , '): ' , errorMessage ] . join ( '' ) ,
59+ )
7760 }
7861
7962 if ( ! json . items || json . items . length === 0 ) {
@@ -86,7 +69,9 @@ export const googleSearch = async (query: string): Promise<SearchResult> => {
8669 } )
8770
8871 if ( filtered . length === 0 ) {
89- throw new Error ( 'Google Search returned results but all were from blocked domains for: ' + query )
72+ throw new Error (
73+ 'Google Search returned results but all were from blocked domains for: ' + query ,
74+ )
9075 }
9176
9277 const result : SearchResult = { ...json , items : filtered }
0 commit comments