diff --git a/package.json b/package.json index 39ddb13..300c95b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,10 @@ { "name": "mksec", +<<<<<<< HEAD "version": "2.2.2", +======= + "version": "2.3.0", +>>>>>>> b8883c375128178a5e1a45fe63ca4a45624b9ad5 "main": "src/index.js", "repository": "git@github.com:IoTcat/sentence-generator.git", "author": "iotcat ", diff --git a/src/fy.js b/src/fy.js new file mode 100644 index 0000000..589402d --- /dev/null +++ b/src/fy.js @@ -0,0 +1,32 @@ +module.exports = async (params) => { + + var o_params = { + word: 'home', + url: 'https://fy.iciba.com/ajax.php?a=fy&f=en&t=zh&w=' + } + + Object.assign(o_params, params); + + var o = []; + + const request = require('request'); + + + return new Promise((resolve, reject) => { + request(o_params.url+o_params.word, (err, res, body) => { + if(err){ + reject(err); + }else{ + try{ + + let data = JSON.parse(res.body); + resolve(data.content.out); + }catch(e){ + reject(e); + } + reject('other error..'); + } + }); + }); +} + diff --git a/src/modules/push.js b/src/modules/push.js index 503e16f..0268023 100644 --- a/src/modules/push.js +++ b/src/modules/push.js @@ -6,7 +6,7 @@ module.exports = (yargs) => { ban.fail('Empty Email!! Please use mksec config -e [email] first!!'); return; } - request.post(data.config.remote(), { + request.post(data.config.remote()+'/publish/', { form:{ action: 'push', email: data.config.email(), @@ -55,6 +55,27 @@ module.exports = (yargs) => { o.push(oArr); }) + .command('pull', "mksec pull".green + " Pull all words from remote in csv..", yargs => yargs, async argv => { + ban = new ora(`Downloading...`).start(); + + request(data.config.remote()+'/getData/?email='+data.config.email(), (err, res, body) => { + if(err){ + ban.fail('Download failed!'); + return; + } + let s = JSON.parse(res.body); + if(s.code == '200'){ + if(!argv._[1]) argv._[1] = 'download.csv' + fs.writeFileSync(argv._[1], s.data.join('\n')); + ban.succeed('Downloaded '+s.data.length+' words in file '+argv._[1]+'!!'); + }else{ + ban.fail(s.message); + } + + }) + + }) + return yargs; } diff --git a/src/public/index.html b/src/public/index.html index 3a6223f..02d60c3 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -156,8 +156,12 @@ data = []; iter = 0; +sentence = ''; var next = function(){ $.get('./mksec/?word='+data[(iter++)%data.length], function(res){ + sentence = res; + let pos = res.indexOf(data[(iter-1)%data.length]); + res = res.substring(0, pos) + '' + String(data[(iter-1)%data.length]) + '' + res.substring(pos + String(data[(iter-1)%data.length]).length); $('#sentence').html(res); getInfo(); }) @@ -184,7 +188,18 @@ var getInfo = function(){ $('#no').click(function(){ - next(); + + $.get('./fy/?word='+sentence, function(res){ + tips.show({ + title: '', + message: res, + timeout: res.length * 1000, + onClosing: function () { + next(); + } + }); + }) + }); diff --git a/src/server.js b/src/server.js index 05e078b..3e2a96d 100644 --- a/src/server.js +++ b/src/server.js @@ -1,10 +1,10 @@ const mksec = require(__dirname+'/index.js'); +const fy = require(__dirname+'/fy.js'); const app = require('express')(); const md5 = require('md5'); const bodyParser = require('body-parser'); const fs = require('fs'); - port = 3000; data_folder = __dirname+'/data/' @@ -24,6 +24,16 @@ app.get('/mksec/', async (req, res) => { }); +app.get('/fy/', async (req, res) => { + + let arr = await fy({ + word: req.query.word + }); + res.send(arr); + +}); + + app.post('/publish/', async (req, res) => { if(req.body.hasOwnProperty('email') && req.body.hasOwnProperty('data')){ diff --git a/src/utilities/data.js b/src/utilities/data.js index 862ca63..3816e6a 100644 --- a/src/utilities/data.js +++ b/src/utilities/data.js @@ -22,14 +22,14 @@ module.exports = () => { type: "object", default: { email: '', - remote: "https://mksec.yimian.xyz/publish/" + remote: "https://mksec.yimian.xyz" } } }); if(conf.get('config') == undefined) conf.set('config', { email: '', - remote: "https://mksec.yimian.xyz/publish/" + remote: "https://mksec.yimian.xyz" }); return o;