Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Pope
ftl
Commits
175269f3
Commit
175269f3
authored
5 years ago
by
Sami Spets
Browse files
Options
Downloads
Patches
Plain Diff
Added logic to the config search
parent
d7932fbd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web-service/server/src/index.js
+37
-38
37 additions, 38 deletions
web-service/server/src/index.js
with
37 additions
and
38 deletions
web-service/server/src/index.js
+
37
−
38
View file @
175269f3
...
@@ -227,10 +227,11 @@ app.post('/stream/config', async (req, res) => {
...
@@ -227,10 +227,11 @@ app.post('/stream/config', async (req, res) => {
})
})
app
.
get
(
'
/stream/config
'
,
async
(
req
,
res
)
=>
{
app
.
get
(
'
/stream/config
'
,
async
(
req
,
res
)
=>
{
//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations
/
//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations
//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations/board_size/value=1
//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations/board_size/value=1
const
wholeURI
=
encodeURIComponent
(
req
.
query
.
uri
)
const
wholeURI
=
encodeURIComponent
(
req
.
query
.
uri
)
console
.
log
(
wholeURI
)
// await new Configs({
// await new Configs({
// URI: wholeURI,
// URI: wholeURI,
...
@@ -246,52 +247,50 @@ app.get('/stream/config', async(req, res) => {
...
@@ -246,52 +247,50 @@ app.get('/stream/config', async(req, res) => {
// }
// }
// }).save()
// }).save()
cons
t
response
=
await
Configs
.
find
({
URI
:
wholeURI
});
le
t
response
=
await
Configs
.
find
({
URI
:
wholeURI
});
if
(
response
.
length
){
if
(
response
.
length
){
console
.
log
(
response
[
0
])
return
res
.
status
(
200
).
json
(
response
[
0
].
data
);
return
res
.
status
(
200
).
json
(
response
[
0
].
data
);
}
}
const
uri
=
wholeURI
.
substring
(
47
)
const
uri
=
wholeURI
.
substring
(
35
)
let
depth
=
uri
.
split
(
"
%2F
"
);
const
depth
=
uri
.
split
(
"
/
"
);
console
.
log
(
depth
[
1
])
console
.
log
(
depth
)
if
(
depth
.
length
==
2
){
if
(
depth
[
depth
.
length
-
1
].
length
==
0
){
const
splitted
=
wholeURI
.
split
(
depth
[
1
])
depth
.
pop
;
const
uri
=
splitted
[
0
].
substring
(
0
,
splitted
[
0
].
length
-
3
)
console
.
log
(
'
VAL
'
,
uri
)
const
responseData
=
await
Configs
.
find
({
URI
:
uri
})
const
realData
=
responseData
[
0
].
data
const
obj
=
Object
.
entries
(
realData
);
const
helpObj
=
{}
for
(
const
[
key
,
data
]
of
obj
){
console
.
log
(
'
PIIPPIIP
'
,
depth
[
1
]
in
data
)
if
(
depth
[
1
]
in
data
)
{
helpObj
[
`
${
key
}
`
]
=
data
}
}
console
.
log
(
"
HELPOBJECT
"
,
helpObj
)
const
actualData
=
Object
.
entries
(
helpObj
)
for
(
const
[
key
,
data
]
of
actualData
){
console
.
log
(
"
KEY2
"
,
key
)
console
.
log
(
"
DATA2
"
,
data
)
}
return
res
.
status
(
200
).
json
(
realData
)
}
}
if
(
depth
.
length
===
1
){
// if(depth.length ==3){
let
data
=
await
Configs
.
find
({
URI
:
wholeURI
});
// get the value
return
res
.
status
(
200
).
json
(
data
);
// save the get the first depth
}
else
if
(
depth
.
length
===
2
){
// save the value with default values into the first depth
const
data
=
await
Configs
.
find
({
URI
:
wholeURI
})
// }
return
res
.
status
(
200
).
json
(
data
)
}
else
if
(
depth
.
length
===
3
){
console
.
log
(
depth
)
return
res
.
status
(
200
).
json
(
'
DEPTH 3
'
)
}
else
{
return
res
.
status
(
500
).
json
(
'
ERROR
'
);
}
console
.
log
(
wholeURI
)
console
.
log
(
wholeURI
)
console
.
log
(
uri
)
console
.
log
(
uri
)
console
.
log
(
depth
)
console
.
log
(
depth
)
switch
(
depth
.
length
){
case
1
:
return
res
.
send
(
200
)
console
.
log
(
'
DEPTH 1
'
)
return
res
.
status
(
200
).
json
(
'
DEPTH IS 1, RETURNING EVERYTHING
'
);
case
2
:
console
.
log
(
'
DEPTH 2
'
)
return
res
.
status
(
200
).
json
(
'
DEPTH IS 2, RETURNING ALMOST EVERYTHING
'
);
case
3
:
console
.
log
(
'
DEPTH 3
'
)
return
res
.
status
(
200
).
json
(
'
DEPTH IS 3, RETURNING BIT LESS
'
);
case
4
:
console
.
log
(
'
DEPTH 4
'
)
return
res
.
status
(
200
).
json
(
'
DEPTH IS 4, RETURNING SINGLE VALUE
'
);
default
:
console
.
log
(
'
DEPTH ERROR
'
)
return
res
.
status
(
200
).
json
(
'
Error
'
);
}
})
})
app
.
get
(
'
/stream
'
,
(
req
,
res
)
=>
{
app
.
get
(
'
/stream
'
,
(
req
,
res
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment