Merge branch 'master' of github.com:IoTcat/sentence-generator

Conflicts:
	package.json
dependabot/npm_and_yarn/y18n-4.0.1
cn.yimian.xyz 4 years ago
commit 0ff21ae11f
  1. 4
      package.json
  2. 32
      src/fy.js
  3. 23
      src/modules/push.js
  4. 17
      src/public/index.html
  5. 12
      src/server.js
  6. 4
      src/utilities/data.js

@ -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 <i@iotcat.me>",

@ -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..');
}
});
});
}

@ -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;
}

@ -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) + '<strong>' + String(data[(iter-1)%data.length]) + '</strong>' + 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();
}
});
})
});

@ -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')){

@ -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;

Loading…
Cancel
Save