Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
d4c30fea
Commit
d4c30fea
authored
Feb 17, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exclude option
parent
e8357cbd
Pipeline
#554
canceled with stage
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
4 deletions
+29
-4
api.js
api.js
+3
-2
generateRandom.js
src/api/generateRandom.js
+11
-2
apiMappers.js
src/apiMappers.js
+15
-0
No files found.
api.js
View file @
d4c30fea
...
...
@@ -59,8 +59,9 @@ app.use(function(req, res, next) {
app
.
use
(
router
);
app
.
use
(
App
.
static
(
'public'
))
app
.
use
(
function
(
req
,
res
,
next
)
{
req
.
end
(
'Nope'
);
})
res
.
end
(
'Nope'
);
});
try
{
app
.
listen
(
APP_PORT
);
}
catch
(
e
){
...
...
src/api/generateRandom.js
View file @
d4c30fea
...
...
@@ -55,7 +55,8 @@ module.exports = {
seed
:
{
required
:
false
,
description
:
'initialize random state. Make response determined'
,
type
:
String
},
photo
:
{
required
:
false
,
description
:
'question with photo'
,
type
:
Boolean
},
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
)
{
let
seed
=
args
.
seed
||
Math
.
random
().
toString
(
36
).
substr
(
2
);
...
...
@@ -63,7 +64,7 @@ module.exports = {
let
multiple
=
seeded
()
>
24
/
(
46
+
24
),
photo
=
seeded
()
>
0.7
,
result
;
result
,
attempts
=
0
;
while
(
!
result
){
if
(
(
args
.
type
!==
void
0
?
args
.
type
===
2
:
seeded
()
>
0.5
)
){
...
...
@@ -71,6 +72,14 @@ module.exports = {
}
else
{
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
)}
`
);
...
...
src/apiMappers.js
View file @
d4c30fea
...
...
@@ -25,6 +25,17 @@ const mappers = {
throw
new
Error
(
'`'
+
t
+
'` is not a number'
)
}
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
let timeout = setTimeout(()=>{
res.status(408);
res.end('{"error": true, "data": "Timeout"}');
try{
res.connection.destroy();
}catch(e){
}
}, 10000);
try{
args = parseArgs( req, res, api.options );
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment