1
- /* eslint-disable no-use-before-define,no-param-reassign,no-console */
2
- const debug = require ( 'debug' ) ( 'attachment' ) ;
1
+ /* eslint-disable no-param-reassign */
3
2
const request = require ( 'request' ) ;
4
3
const { Readable } = require ( 'stream' ) ;
5
4
const { BasicAuthRestClient } = require ( '../StatelessBasicAuthRestClient' ) ;
6
5
7
- exports . addAttachment = addAttachment ;
8
-
9
6
function addAttachment ( msg , name , body , contentType ) {
10
- return getUrlsManualy ( ) . then ( ( result ) => {
11
- debug ( 'createSignedUrl result: %j' , result ) ;
12
- debug ( 'Uploading to url: %s' , result . put_url ) ;
13
- debug ( 'Content-Type: %s' , contentType ) ;
14
- console . log ( 'uploadFile is about to execute' ) ;
15
- return uploadFile ( result , contentType ) ;
16
- } ) ;
17
-
7
+ const self = this ;
18
8
async function getUrlsManualy ( ) {
19
- const attachmentClient = new BasicAuthRestClient ( this , {
9
+ const attachmentClient = new BasicAuthRestClient ( self , {
20
10
resourceServerUrl : 'http://api-service.platform.svc.cluster.local.:9000' ,
21
11
} , process . env . ELASTICIO_API_USERNAME , process . env . ELASTICIO_API_KEY ) ;
22
12
@@ -27,7 +17,7 @@ function addAttachment(msg, name, body, contentType) {
27
17
}
28
18
29
19
async function uploadFile ( urls ) {
30
- debug ( 'Trying to upload file: %j' , body ) ;
20
+ self . logger . debug ( 'Trying to upload file: %j' , body ) ;
31
21
32
22
const stream = new Readable ( ) ;
33
23
stream . push ( body . toString ( ) ) ;
@@ -44,4 +34,14 @@ function addAttachment(msg, name, body, contentType) {
44
34
} ;
45
35
return msg ;
46
36
}
37
+
38
+ return getUrlsManualy ( ) . then ( ( result ) => {
39
+ self . logger . debug ( 'createSignedUrl result: %j' , result ) ;
40
+ self . logger . debug ( 'Uploading to url: %s' , result . put_url ) ;
41
+ self . logger . debug ( 'Content-Type: %s' , contentType ) ;
42
+ self . logger . info ( 'uploadFile is about to execute' ) ;
43
+ return uploadFile ( result , contentType ) ;
44
+ } ) ;
47
45
}
46
+
47
+ exports . addAttachment = addAttachment ;
0 commit comments