forked from theabbie/suggest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import axios from 'axios'; | ||
import { Engine, Result } from '../' | ||
|
||
export interface Icon { | ||
Height: string; | ||
URL: string; | ||
Width: string; | ||
} | ||
|
||
export interface Topic { | ||
FirstURL: string; | ||
Icon: Icon; | ||
Result: string; | ||
Text: string; | ||
} | ||
|
||
export interface RelatedTopic { | ||
FirstURL: string; | ||
Icon: Icon; | ||
Result: string; | ||
Text: string; | ||
Name: string; | ||
Topics: Topic[]; | ||
} | ||
|
||
export interface Developer { | ||
name: string; | ||
type: string; | ||
url: string; | ||
} | ||
|
||
export interface Maintainer { | ||
github: string; | ||
} | ||
|
||
export interface SrcOptions { | ||
directory: string; | ||
is_fanon: number; | ||
is_mediawiki: number; | ||
is_wikipedia: number; | ||
language: string; | ||
min_abstract_length: string; | ||
skip_abstract: number; | ||
skip_abstract_paren: number; | ||
skip_end: string; | ||
skip_icon: number; | ||
skip_image_name: number; | ||
skip_qr: string; | ||
source_skip: string; | ||
src_info: string; | ||
} | ||
|
||
export interface Meta { | ||
attribution?: any; | ||
blockgroup?: any; | ||
created_date?: any; | ||
description: string; | ||
designer?: any; | ||
dev_date?: any; | ||
dev_milestone: string; | ||
developer: Developer[]; | ||
example_query: string; | ||
id: string; | ||
is_stackexchange?: any; | ||
js_callback_name: string; | ||
live_date?: any; | ||
maintainer: Maintainer; | ||
name: string; | ||
perl_module: string; | ||
producer?: any; | ||
production_state: string; | ||
repo: string; | ||
signal_from: string; | ||
src_domain: string; | ||
src_id: number; | ||
src_name: string; | ||
src_options: SrcOptions; | ||
src_url?: any; | ||
status: string; | ||
tab: string; | ||
topic: string[]; | ||
unsafe: number; | ||
} | ||
|
||
export interface Answer { | ||
from: string | ||
id: string | ||
name: string | ||
result: string | ||
signal: string | ||
templates: { | ||
group: string, | ||
options: { | ||
content: string | ||
} | ||
} | ||
} | ||
|
||
export interface RootObject { | ||
Abstract: string; | ||
AbstractSource: string; | ||
AbstractText: string; | ||
AbstractURL: string; | ||
Answer: string | Answer; | ||
AnswerType: string | "calc"; | ||
Definition: string; | ||
DefinitionSource: string; | ||
DefinitionURL: string; | ||
Entity: string; | ||
Heading: string; | ||
Image: string; | ||
ImageHeight: number; | ||
ImageIsLogo: number; | ||
ImageWidth: number; | ||
Infobox: string; | ||
Redirect: string; | ||
RelatedTopics: RelatedTopic[]; | ||
Results: any[]; | ||
Type: string; | ||
meta: Meta; | ||
} | ||
|
||
export interface DuckDuckGo { | ||
instantAnswer: RootObject | ||
suggestions: Result | ||
} | ||
|
||
export default async (query: string): Promise<DuckDuckGo> => { | ||
const [{ data: suggestions }, { data: instantAnswer }] = await Promise.all([ | ||
axios.get<{ phrase: string }[]>(Engine.DDG + query), | ||
axios.get<RootObject>('https://api.duckduckgo.com?q=' + query + "&format=json") | ||
]) | ||
return { | ||
instantAnswer, | ||
suggestions: suggestions.map(x => x.phrase), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters