|
1 | 1 | import { scaffoldDir, authorJsonTpl, readmeTpl } from "../utils/files.ts"; |
2 | 2 | import type { GeneratorCtx } from "../types/index.ts"; |
3 | 3 |
|
4 | | -const indexTpl = (name: string) => `export const name = "${name}" |
5 | | -export const type = "web" // string or array - e.g. "web", "books", ["web", "any-type"] |
6 | | -export const bangShortcut = "${name}" |
| 4 | +const indexTpl = (name: string) => `export const type = "web" // string or array - e.g. "web", "books", ["web", "any-type"] |
7 | 5 |
|
8 | | -// settingsSchema example: |
9 | | -// export const settingsSchema = [ |
10 | | -// { key: "apiKey", label: "API Key", type: "password", required: true }, |
11 | | -// ] |
| 6 | +// filters example (image engines only): |
| 7 | +// Declare which image filter groups/values this engine actually supports. |
| 8 | +// degoog builds the image filter bar from the union of every enabled image |
| 9 | +// engine's filters, so only declare values you really translate below. |
| 10 | +// "transparent" can live under "color" OR "type" depending on the engine - |
| 11 | +// put it wherever your engine implements it and degoog shows it there. |
12 | 12 | // |
13 | | -// export const configure = (settings) => { |
14 | | -// // called after settings save and on server restart |
| 13 | +// export const filters = { |
| 14 | +// size: ["small", "medium", "large", "wallpaper"], |
| 15 | +// color: ["red", "blue", "green", "transparent"], |
| 16 | +// type: ["photo", "clipart", "lineart", "animated"], |
| 17 | +// layout: ["square", "wide", "tall"], |
| 18 | +// nsfw: ["on", "moderate", "off"], |
15 | 19 | // } |
| 20 | +// |
| 21 | +// The selected values arrive on context.imageFilter, e.g. |
| 22 | +// context.imageFilter = { color: "red", nsfw: "moderate" } |
16 | 23 |
|
17 | | -export const executeSearch = async ( |
18 | | - query: string, |
19 | | - page = 1, |
20 | | - timeFilter: string, |
21 | | - context: { |
22 | | - lang: string |
23 | | - fetch: typeof fetch |
24 | | - signProxyUrl: (url: string) => string |
25 | | - buildAcceptLanguage: () => string |
26 | | - dateFrom?: string |
27 | | - dateTo?: string |
28 | | - sentinel?: ( |
29 | | - response: { ok: boolean; status: number }, |
30 | | - engineName?: string |
31 | | - ) => void |
32 | | - engineError?: ( |
33 | | - status: string, |
34 | | - message: string, |
35 | | - opts?: { httpStatus?: number; engine?: string } |
36 | | - ) => Error |
37 | | - } |
38 | | -) => { |
39 | | - const results: Array<{ |
40 | | - title: string |
41 | | - url: string |
42 | | - snippet: string |
43 | | - source: string |
44 | | - thumbnail?: string |
45 | | - }> = [] |
| 24 | +export const engine = { |
| 25 | + name: "${name}", |
| 26 | + bangShortcut: "${name}", |
| 27 | +
|
| 28 | + // settingsSchema: [ |
| 29 | + // { key: "apiKey", label: "API Key", type: "password", required: true }, |
| 30 | + // ], |
| 31 | + // |
| 32 | + // configure(settings) { |
| 33 | + // // called after settings save and on server restart |
| 34 | + // }, |
| 35 | + // |
| 36 | + // needsAppRestart: true, // set true if this engine needs a server restart to work (e.g. registers a WebSocket route) |
| 37 | +
|
| 38 | + async executeSearch( |
| 39 | + query: string, |
| 40 | + page = 1, |
| 41 | + timeFilter: string, |
| 42 | + context: { |
| 43 | + lang: string |
| 44 | + fetch: typeof fetch |
| 45 | + signProxyUrl: (url: string) => string |
| 46 | + buildAcceptLanguage: () => string |
| 47 | + dateFrom?: string |
| 48 | + dateTo?: string |
| 49 | + imageFilter?: Record<string, string> |
| 50 | + sentinel?: ( |
| 51 | + response: { ok: boolean; status: number }, |
| 52 | + engineName?: string |
| 53 | + ) => void |
| 54 | + engineError?: ( |
| 55 | + status: string, |
| 56 | + message: string, |
| 57 | + opts?: { httpStatus?: number; engine?: string } |
| 58 | + ) => Error |
| 59 | + } |
| 60 | + ) { |
| 61 | + const results: Array<{ |
| 62 | + title: string |
| 63 | + url: string |
| 64 | + snippet: string |
| 65 | + source: string |
| 66 | + thumbnail?: string |
| 67 | + }> = [] |
46 | 68 |
|
47 | | - try { |
48 | | - const doFetch = context?.fetch ?? fetch |
49 | | - const response = await doFetch(\`https://api.example.com/search?q=\${encodeURIComponent(query)}\`) |
50 | | - context?.sentinel?.(response, name) |
51 | | - const data = await response.json() |
52 | | - // TODO: map data into results |
53 | | - return results |
54 | | - } catch (e: any) { |
55 | | - if (e?.name === "SentinelBreach") throw e |
56 | | - return [] |
| 69 | + try { |
| 70 | + const doFetch = context?.fetch ?? fetch |
| 71 | + const response = await doFetch(\`https://api.example.com/search?q=\${encodeURIComponent(query)}\`) |
| 72 | + context?.sentinel?.(response, "${name}") |
| 73 | + const data = await response.json() |
| 74 | + // TODO: map data into results |
| 75 | + return results |
| 76 | + } catch (e: any) { |
| 77 | + if (e?.name === "SentinelBreach") throw e |
| 78 | + return [] |
| 79 | + } |
57 | 80 | } |
58 | 81 | } |
59 | 82 | `; |
|
0 commit comments