Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
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
bs
node-bigstream
Commits
8753b1bb
Commit
8753b1bb
authored
Nov 15, 2019
by
Kamron Aroonrua
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do http plugin
parent
3a93de96
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
168 additions
and
0 deletions
+168
-0
index.js
plugins/do/do-ext-storage/index.js
+12
-0
perform.js
plugins/do/do-ext-storage/perform.js
+72
-0
index.js
plugins/do/do-http/index.js
+12
-0
perform.js
plugins/do/do-http/perform.js
+72
-0
No files found.
plugins/do/do-ext-storage/index.js
0 → 100644
View file @
8753b1bb
var
util
=
require
(
'util'
);
var
DOPlugin
=
require
(
'../do-plugin'
);
function
DOTask
(
context
,
request
){
DOPlugin
.
call
(
this
,
context
,
request
);
this
.
name
=
"ext-storage"
;
}
util
.
inherits
(
DOTask
,
DOPlugin
);
DOTask
.
prototype
.
perform
=
require
(
'./perform'
);
module
.
exports
=
DOTask
;
plugins/do/do-ext-storage/perform.js
0 → 100644
View file @
8753b1bb
var
ctx
=
require
(
'../../../context'
);
var
Utils
=
ctx
.
getLib
(
'lib/util/plugin-utils'
);
var
bsdata
=
ctx
.
getLib
(
'lib/model/bsdata'
);
var
request
=
require
(
"request"
);
function
perform_function
(
context
,
request
,
response
){
var
job_id
=
context
.
jobconfig
.
job_id
;
var
transaction_id
=
context
.
transaction
.
id
;
var
param
=
context
.
jobconfig
.
data_out
.
param
;
var
memstore
=
context
.
task
.
memstore
var
output_type
=
request
.
input_type
;
var
data
=
request
.
data
;
var
meta
=
request
.
meta
;
var
token
=
param
.
token
;
var
api_url
=
param
.
api
;
var
storage_name
=
param
.
storage_name
;
var
env
=
{
'type'
:
output_type
,
'data'
:
data
,
'meta'
:
meta
}
var
sname
=
Utils
.
vm_execute_text
(
env
,
storage_name
);
var
en_data
=
bsdata
.
create
(
data
).
serialize
(
'object-encoded'
);
var
storage_url
=
api_url
+
'/storage/'
+
sname
var
msgbody
=
{
'meta'
:
meta
,
'data'
:
en_data
}
send_to_storage
({
'api'
:
storage_url
,
'token'
:
token
,
'body'
:
msgbody
},
function
(
err
){
if
(
!
err
){
response
.
success
();
}
else
{
response
.
error
(
err
);
}
})
//response.success();
//response.reject();
//response.error("error message")
}
function
send_to_storage
(
prm
,
cb
)
{
var
options
=
{
method
:
'PUT'
,
url
:
prm
.
api
,
headers
:
{
'cache-control'
:
'no-cache'
,
'content-type'
:
'application/json'
},
json
:
prm
.
body
};
if
(
prm
.
token
){
options
.
headers
.
authorization
=
'Bearer '
+
prm
.
token
;}
request
(
options
,
function
(
err
,
resp
,
body
)
{
if
(
!
err
&&
resp
.
statusCode
==
200
)
{
cb
();
}
else
{
cb
(
new
Error
(
"api error"
));
}
});
}
module
.
exports
=
perform_function
;
plugins/do/do-http/index.js
0 → 100644
View file @
8753b1bb
var
util
=
require
(
'util'
);
var
DOPlugin
=
require
(
'../do-plugin'
);
function
DOTask
(
context
,
request
){
DOPlugin
.
call
(
this
,
context
,
request
);
this
.
name
=
"http"
;
}
util
.
inherits
(
DOTask
,
DOPlugin
);
DOTask
.
prototype
.
perform
=
require
(
'./perform'
);
module
.
exports
=
DOTask
;
plugins/do/do-http/perform.js
0 → 100644
View file @
8753b1bb
var
ctx
=
require
(
'../../../context'
);
var
Utils
=
ctx
.
getLib
(
'lib/util/plugin-utils'
);
var
bsdata
=
ctx
.
getLib
(
'lib/model/bsdata'
);
var
request
=
require
(
"request"
);
function
perform_function
(
context
,
request
,
response
){
var
job_id
=
context
.
jobconfig
.
job_id
;
var
transaction_id
=
context
.
transaction
.
id
;
var
param
=
context
.
jobconfig
.
data_out
.
param
;
var
memstore
=
context
.
task
.
memstore
var
output_type
=
request
.
input_type
;
var
data
=
request
.
data
;
var
meta
=
request
.
meta
;
var
req_url
=
param
.
url
||
""
;
var
req_method
=
param
.
method
||
"GET"
;
var
env
=
{
'type'
:
output_type
,
'data'
:
data
,
'meta'
:
meta
}
var
req_url
=
Utils
.
vm_execute_text
(
env
,
req_url
);
send_request
({
'url'
:
req_url
,
'method'
:
req_method
,
'headers'
:
param
.
headers
,
'body'
:
data
},
function
(
err
){
if
(
!
err
){
response
.
success
();
}
else
{
response
.
error
(
err
);
}
})
//response.success();
//response.reject();
//response.error("error message")
}
function
send_request
(
prm
,
cb
)
{
var
options
=
{
method
:
'GET'
,
url
:
prm
.
url
,
headers
:
{
'cache-control'
:
'no-cache'
}
};
if
(
prm
.
method
.
toLowerCase
()
==
'post'
||
prm
.
method
.
toLowerCase
()
==
'put'
)
{
options
.
method
=
prm
.
method
.
toUpperCase
();
options
.
headers
[
'content-type'
]
=
'application/json'
;
options
.
json
=
prm
.
body
;
}
if
(
typeof
prm
.
headers
==
'object'
)
{
options
.
headers
=
Object
.
assign
(
options
.
headers
,
prm
.
headers
)
}
request
(
options
,
function
(
err
,
resp
,
body
)
{
if
(
!
err
)
{
cb
();
}
else
{
cb
(
new
Error
(
"request error"
));
}
});
}
module
.
exports
=
perform_function
;
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