Skip to content

Commit 32fdab7

Browse files
committed
update teplates for new search behaviour and add needsRestart flag
1 parent 867fd25 commit 32fdab7

12 files changed

Lines changed: 169 additions & 134 deletions

File tree

src/generators/autocomplete.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import { scaffoldDir, authorJsonTpl, readmeTpl } from "../utils/files.ts"
22
import type { GeneratorCtx } from "../types/index.ts"
33

4-
const indexTpl = (name: string) => `export const name = "${name}"
5-
6-
// settingsSchema example:
7-
// export const settingsSchema = [
8-
// { key: "endpoint", label: "Endpoint URL", type: "url", required: true },
9-
// ]
10-
//
11-
// export const configure = (settings) => {}
12-
13-
type RichSuggestion = {
4+
const indexTpl = (name: string) => `type RichSuggestion = {
145
description?: string
156
thumbnail?: string
167
type?: string
178
}
189
1910
type Suggestion = string | { text: string; rich?: RichSuggestion }
2011
21-
export const getSuggestions = async (
22-
query: string,
23-
context: {
24-
fetch: typeof fetch
25-
lang: string
26-
}
27-
): Promise<Suggestion[]> => {
28-
// TODO: implement autocomplete logic
29-
// use context.fetch instead of global fetch
30-
return []
12+
export const provider = {
13+
name: "${name}",
14+
15+
// settingsSchema: [
16+
// { key: "endpoint", label: "Endpoint URL", type: "url", required: true },
17+
// ],
18+
//
19+
// configure(settings) {},
20+
//
21+
// needsAppRestart: true, // set true if this autocomplete provider needs a server restart to work (e.g. registers a WebSocket route)
22+
23+
async getSuggestions(
24+
query: string,
25+
context: {
26+
fetch: typeof fetch
27+
lang: string
28+
}
29+
): Promise<Suggestion[]> {
30+
// TODO: implement autocomplete logic
31+
// use context.fetch instead of global fetch
32+
return []
33+
},
3134
}
3235
`
3336

src/generators/engine.ts

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,82 @@
11
import { scaffoldDir, authorJsonTpl, readmeTpl } from "../utils/files.ts";
22
import type { GeneratorCtx } from "../types/index.ts";
33

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"]
75
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.
1212
//
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"],
1519
// }
20+
//
21+
// The selected values arrive on context.imageFilter, e.g.
22+
// context.imageFilter = { color: "red", nsfw: "moderate" }
1623
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+
}> = []
4668
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+
}
5780
}
5881
}
5982
`;

src/generators/plugin-bang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default {
4545
// ],
4646
//
4747
// configure(settings) {},
48+
// needsAppRestart: true, // set true if this command needs a server restart to work (e.g. registers a WebSocket route)
4849
//
4950
// async init(ctx) {
5051
// ctx.template // template.html contents

src/generators/plugin-intercept.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const interceptor = {
2222
// ],
2323
//
2424
// configure(settings) {},
25+
// needsAppRestart: true, // set true if this interceptor needs a server restart to work (e.g. registers a WebSocket route)
26+
//
2527
// async init(ctx) {
2628
// ctx.pluginId // installed plugin folder ID assigned by degoog (alias: ctx.id)
2729
// ctx.apiBase // /api/plugin/<ctx.pluginId> - base for your own routes

src/generators/plugin-mid.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const middleware = {
1717
id: "${name}",
1818
name: "${name}",
1919
20+
// needsAppRestart: true, // set true if this middleware needs a server restart to work (e.g. registers a WebSocket route)
21+
2022
async handle(req: Request, context: {
2123
fetch: typeof fetch
2224
}): Promise<Response | { redirect: string } | null> {

src/generators/plugin-slot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const slot = {
3434
// ],
3535
//
3636
// configure(settings) {},
37+
// needsAppRestart: true, // set true if this slot needs a server restart to work (e.g. registers a WebSocket route)
38+
//
3739
// async init(ctx) {
3840
// ctx.template // template.html contents
3941
// ctx.pluginId // installed plugin folder ID assigned by degoog (alias: ctx.id)

src/generators/plugin-tab.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const tab = {
3333
// ],
3434
//
3535
// configure(settings) {},
36+
// needsAppRestart: true, // set true if this tab needs a server restart to work (e.g. registers a WebSocket route)
37+
//
3638
// async init(ctx) {
3739
// ctx.template // template.html contents
3840
// ctx.pluginId // installed plugin folder ID assigned by degoog (alias: ctx.id)

src/generators/transport.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
import { scaffoldDir, authorJsonTpl, readmeTpl } from "../utils/files.ts"
22
import type { GeneratorCtx } from "../types/index.ts"
33

4-
const indexTpl = (name: string) => `export const name = "${name}"
5-
export const displayName = "${name}"
6-
export const description = "Custom transport for degoog"
4+
const indexTpl = (name: string) => `export const transport = {
5+
name: "${name}",
6+
displayName: "${name}",
7+
description: "Custom transport for degoog",
78
8-
// settingsSchema example:
9-
// export const settingsSchema = [
10-
// { key: "proxyUrl", label: "Proxy URL", type: "url", required: true },
11-
// ]
12-
//
13-
// export const configure = (settings) => {
14-
// // called after settings save and on server restart
15-
// }
9+
// settingsSchema: [
10+
// { key: "proxyUrl", label: "Proxy URL", type: "url", required: true },
11+
// ],
12+
//
13+
// configure(settings) {
14+
// // called after settings save and on server restart
15+
// },
16+
//
17+
// needsAppRestart: true, // set true if this transport needs a server restart to work (e.g. registers a WebSocket route)
1618
17-
export const available = async (): Promise<boolean> => {
18-
// return true if this transport is ready to use
19-
return true
20-
}
19+
async available(): Promise<boolean> {
20+
// return true if this transport is ready to use
21+
return true
22+
},
2123
22-
export const fetch = async (
23-
url: string,
24-
options: {
25-
method?: string
26-
headers?: Record<string, string>
27-
body?: string
28-
redirect?: RequestRedirect
29-
signal?: AbortSignal
24+
async fetch(
25+
url: string,
26+
options: {
27+
method?: string
28+
headers?: Record<string, string>
29+
body?: string
30+
redirect?: RequestRedirect
31+
signal?: AbortSignal
32+
},
33+
context: {
34+
proxyUrl?: string
35+
fetch: typeof globalThis.fetch
36+
}
37+
): Promise<Response> {
38+
// TODO: implement transport logic
39+
return context.fetch(url, options)
3040
},
31-
context: {
32-
proxyUrl?: string
33-
fetch: typeof globalThis.fetch
34-
}
35-
): Promise<Response> => {
36-
// TODO: implement transport logic
37-
return context.fetch(url, options)
3841
}
3942
`
4043

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const main = async () => {
4747
}
4848

4949
if (action === "update" && newVersion) {
50-
p.outro(`run: ${t.brand(updateCmd(newVersion))}`)
50+
p.outro(`run: ${t.brand(updateCmd())}`)
5151
process.exit(0)
5252
}
5353
if (action === "login") await loginCmd()

src/templates/theme/search-templates/image-card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
data-fallback="{{ fallback_url }}"
66
alt="{{ title }}"
77
loading="lazy"
8-
onerror="this.src!==this.dataset.fallback?(this.src=this.dataset.fallback):this.closest('.image-card').style.display='none'"
8+
onerror="this.dataset.triedFallback||this.dataset.fallback===''?this.closest('.image-card').style.display='none':(this.dataset.triedFallback='1',this.src=this.dataset.fallback)"
99
/>
1010
</div>
1111
<div class="image-info">

0 commit comments

Comments
 (0)