Implement gitea search engine
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
export const name = "gitea-searchengine"
|
||||
export const type = "web" // web | images | videos | news | custom
|
||||
export const bangShortcut = "gitea-searchengine"
|
||||
export const bangShortcut = "gitea"
|
||||
|
||||
// settingsSchema example:
|
||||
// export const settingsSchema = [
|
||||
// { key: "apiKey", label: "API Key", type: "password", required: true },
|
||||
// ]
|
||||
//
|
||||
// export const configure = (settings) => {
|
||||
// // called after settings save and on server restart
|
||||
// }
|
||||
const hostedGiteaUrl = "https://gitea.com"
|
||||
const apiPath = "/api/v1/repos/search"
|
||||
|
||||
var giteaSearchUrl : string = ""
|
||||
var giteaBase : string = ""
|
||||
var giteaToken : string = ""
|
||||
|
||||
export const settingsSchema = [
|
||||
{ key: "giteaUrl", label: "Gitea Instance URL", description: "The base URL of your custom gitea instance, if empty uses the public hosted version.", type: "url", required: false },
|
||||
{ key: "accessToken", label: "Access Token", description: "Access Token to the gitea instance, allows searching for private repositories. Requires repository read permission.", type: "password", required: false },
|
||||
]
|
||||
|
||||
export const configure = (settings:any) => {
|
||||
// called after settings save and on server restart
|
||||
giteaBase = (settings.giteaUrl || hostedGiteaUrl )
|
||||
giteaSearchUrl = giteaBase + apiPath
|
||||
giteaToken = settings.accessToken || ""
|
||||
}
|
||||
|
||||
export const executeSearch = async (
|
||||
query: string,
|
||||
@@ -43,11 +53,24 @@ export const executeSearch = async (
|
||||
|
||||
try {
|
||||
const doFetch = context?.fetch ?? fetch
|
||||
const response = await doFetch(`https://api.example.com/search?q=${encodeURIComponent(query)}`)
|
||||
|
||||
var headers = {}
|
||||
|
||||
if(giteaToken.length > 0){
|
||||
headers = { "Authorization": `token ${giteaToken}` }
|
||||
}
|
||||
|
||||
const response = await doFetch(`${giteaSearchUrl}?q=${encodeURIComponent(query)}&page=${encodeURIComponent(page)}`, {headers: headers})
|
||||
context?.sentinel?.(response, name)
|
||||
const data = await response.json()
|
||||
// TODO: map data into results
|
||||
return results
|
||||
return data.map((r:any) => ({
|
||||
title: r.full_name,
|
||||
url: r.html_url,
|
||||
snippet: r.description ?? "",
|
||||
source: "Gitea",
|
||||
...(r.avatar_url ? { thumbnail: r.avatar_url } : {}),
|
||||
...(r.duration ? { duration: r.duration } : {}),
|
||||
}));
|
||||
} catch (e: any) {
|
||||
if (e?.name === "SentinelBreach") throw e
|
||||
return []
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"path": "engines/gitea-searchengine",
|
||||
"name": "gitea-searchengine",
|
||||
"description": "",
|
||||
"description": "Search your private gitea instance",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user