You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
module.exports = async (params) => { |
|
|
|
var o_params = { |
|
word: 'home', |
|
url: 'https://corpus.vocabulary.com/api/1.0/examples.json?query=' |
|
} |
|
|
|
Object.assign(o_params, params); |
|
|
|
var o = []; |
|
|
|
const request = require('request'); |
|
|
|
return new Promise((resolve, reject) => { |
|
request('https://proxy.yimian.xyz/get/?url='+ Buffer.from(o_params.url+o_params.word, 'utf-8').toString('base64'), (err, res, body) => { |
|
if(err){ |
|
reject(err); |
|
}else{ |
|
try{ |
|
|
|
let data = JSON.parse(res.body); |
|
let o = []; |
|
if(!data.result.totalHits){ |
|
reject(); |
|
} |
|
data.result.sentences.forEach((item, index) => { |
|
o.push(item.sentence+' --'+item.volume.corpus.name); |
|
if(index == data.result.sentences.length - 1){ |
|
resolve(o); |
|
} |
|
}); |
|
}catch(e){ |
|
reject(e); |
|
} |
|
reject('other error..'); |
|
} |
|
}); |
|
}); |
|
} |
|
|
|
|