Commit d4c30fea by Иван Кубота

exclude option

parent e8357cbd
Pipeline #554 canceled with stage
...@@ -59,8 +59,9 @@ app.use(function(req, res, next) { ...@@ -59,8 +59,9 @@ app.use(function(req, res, next) {
app.use(router); app.use(router);
app.use(App.static('public')) app.use(App.static('public'))
app.use(function(req, res, next) { app.use(function(req, res, next) {
req.end('Nope');
}) res.end('Nope');
});
try{ try{
app.listen( APP_PORT ); app.listen( APP_PORT );
}catch(e){ }catch(e){
......
...@@ -55,7 +55,8 @@ module.exports = { ...@@ -55,7 +55,8 @@ module.exports = {
seed: {required: false, description: 'initialize random state. Make response determined', type: String}, seed: {required: false, description: 'initialize random state. Make response determined', type: String},
photo: {required: false, description: 'question with photo', type: Boolean}, photo: {required: false, description: 'question with photo', type: Boolean},
type: {required: false, description: '1 - products, 2 - standards', type: Number}, type: {required: false, description: '1 - products, 2 - standards', type: Number},
nolog: {required: false, description: 'remove human readable log', type: Boolean} nolog: {required: false, description: 'remove human readable log', type: Boolean},
exclude: {required: false, description: 'remove human readable log', type: Array}
}, },
fn: async function(args) { fn: async function(args) {
let seed = args.seed || Math.random().toString(36).substr(2); let seed = args.seed || Math.random().toString(36).substr(2);
...@@ -63,7 +64,7 @@ module.exports = { ...@@ -63,7 +64,7 @@ module.exports = {
let multiple = seeded() > 24 / ( 46 + 24 ), let multiple = seeded() > 24 / ( 46 + 24 ),
photo = seeded() > 0.7, photo = seeded() > 0.7,
result; result, attempts = 0;
while(!result){ while(!result){
if( ( args.type !== void 0 ? args.type === 2 : seeded() > 0.5 ) ){ if( ( args.type !== void 0 ? args.type === 2 : seeded() > 0.5 ) ){
...@@ -71,6 +72,14 @@ module.exports = { ...@@ -71,6 +72,14 @@ module.exports = {
}else{ }else{
result = ctx.quizGenerator( multiple ? 'checkbox' : 'radio', args.photo !== void 0 ? args.photo : photo ); result = ctx.quizGenerator( multiple ? 'checkbox' : 'radio', args.photo !== void 0 ? args.photo : photo );
} }
if(result && args.exclude){
if(args.exclude.filter((a)=>a.categoryId === result.categoryId && a.productId === result.productId).length){
attempts++;
if(attempts < 20){
result = false;
}
}
}
} }
console.log(`cat: ${result.categoryId}, prod: ${result.productId}, seed: ${seed}. ${result.question.substr(0,33)}`); console.log(`cat: ${result.categoryId}, prod: ${result.productId}, seed: ${seed}. ${result.question.substr(0,33)}`);
......
...@@ -25,6 +25,17 @@ const mappers = { ...@@ -25,6 +25,17 @@ const mappers = {
throw new Error( '`' + t + '` is not a number' ) throw new Error( '`' + t + '` is not a number' )
} }
return t; return t;
},
Array: (t)=>{
try{
let res = JSON.parse(t);
if(!Array.isArray(res))
throw new Error('`'+t+'` is not an Array')
return res;
}catch( e ){
throw new Error( '`' + t + '` is not an Array' )
}
} }
}; };
...@@ -138,7 +149,11 @@ ${opt.required?'<span class="api-option-required">Required</span>': '<span class ...@@ -138,7 +149,11 @@ ${opt.required?'<span class="api-option-required">Required</span>': '<span class
let timeout = setTimeout(()=>{ let timeout = setTimeout(()=>{
res.status(408); res.status(408);
res.end('{"error": true, "data": "Timeout"}'); res.end('{"error": true, "data": "Timeout"}');
res.connection.destroy(); try{
res.connection.destroy();
}catch(e){
}
}, 10000); }, 10000);
try{ try{
args = parseArgs( req, res, api.options ); args = parseArgs( req, res, api.options );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment