This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
engine.ts
66 lines (57 loc) · 1.44 KB
/
engine.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Book, Word } from './data';
import axios, { AxiosInstance } from 'axios';
import { getLogger, Logger } from 'log4js';
abstract class Engine {
name: string;
isLogin: boolean = false;
req: AxiosInstance = null;
logger: Logger;
// @ts-ignore
static get UA_BROWSER() {
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36';
}
constructor(name, cookie?) {
this.name = name;
this.isLogin = false;
this.req = axios.create({
headers: { cookie, 'User-Agent': Engine.UA_BROWSER },
});
this.logger = getLogger(name);
// this.reqConfig = {
// jar: true,
// // proxy: 'http://localhost:8888',
// headers: {
// 'User-Agent': Engine.UA_BROWSER,
// },
// }
// this.debug = false
}
login() {
this.isLogin = true;
}
work() {}
/**
* 获取单词本
*/
abstract fetchBookNames(): Promise<Array<Book>>;
/**
* 获取单词本的词汇
*/
abstract fetchBookWords(book: Book): Promise<boolean>;
/**
* 查询单词
* @param word {string}
* @returns {Promise<any>}
*/
abstract async lookup(word: string): Promise<Word>;
/**
* 添加单词,根据需求对单词进行细化
* @param book
* @param word
*/
async addWordToBook(book: Book, word: Word): Promise<boolean> {
return false;
}
async start() {}
}
export default Engine;