Initial commit

This commit is contained in:
ItzCrazyKns 2024-04-09 16:21:05 +05:30
commit d1c74c861e
No known key found for this signature in database
GPG key ID: 8162927C7CCE3065
57 changed files with 4568 additions and 0 deletions

42
src/core/searxng.ts Normal file
View file

@ -0,0 +1,42 @@
import axios from 'axios';
interface SearxngSearchOptions {
categories?: string[];
engines?: string[];
language?: string;
pageno?: number;
}
interface SearxngSearchResult {
title: string;
url: string;
img_src?: string;
thumbnail_src?: string;
content?: string;
author?: string;
}
export const searchSearxng = async (
query: string,
opts?: SearxngSearchOptions,
) => {
const url = new URL(`${process.env.SEARXNG_API_URL}/search?format=json`);
url.searchParams.append('q', query);
if (opts) {
Object.keys(opts).forEach((key) => {
if (Array.isArray(opts[key])) {
url.searchParams.append(key, opts[key].join(','));
return;
}
url.searchParams.append(key, opts[key]);
});
}
const res = await axios.get(url.toString());
const results: SearxngSearchResult[] = res.data.results;
const suggestions: string[] = res.data.suggestions;
return { results, suggestions };
};