@@ -42,31 +42,34 @@ class DropboxUploadStream extends Transform {
42
42
43
43
sessionStart ( chunk , next ) {
44
44
// start the session on dropbox, sending the first chunk
45
- this . dropbox . filesUploadSessionStart ( {
46
- close : false ,
47
- contents : chunk
48
- } ) . then ( response => {
49
- // set the session id
50
- this . sessionId = response . session_id
51
-
52
- // update the offset
53
- this . offset += chunk . byteLength
54
-
55
- // return next
56
- return next ( )
57
- } , next /* call next if there is an error*/ )
45
+ this . dropbox
46
+ . filesUploadSessionStart ( {
47
+ close : false ,
48
+ contents : chunk ,
49
+ } )
50
+ . then ( response => {
51
+ // set the session id
52
+ this . sessionId = response . session_id
53
+
54
+ // update the offset
55
+ this . offset += chunk . byteLength
56
+
57
+ // return next
58
+ return next ( )
59
+ } , next /* call next if there is an error*/ )
58
60
}
59
61
60
62
sessionAppend ( chunk , next ) {
61
63
// append chunk to a session that has already been started
62
- this . dropbox . filesUploadSessionAppendV2 ( {
63
- cursor : {
64
- session_id : this . sessionId , // id for this upload session
65
- offset : this . offset // offset, current location of chunk
66
- } ,
67
- close : false ,
68
- contents : chunk // current chunk being uploaded
69
- } )
64
+ this . dropbox
65
+ . filesUploadSessionAppendV2 ( {
66
+ cursor : {
67
+ session_id : this . sessionId , // id for this upload session
68
+ offset : this . offset , // offset, current location of chunk
69
+ } ,
70
+ close : false ,
71
+ contents : chunk , // current chunk being uploaded
72
+ } )
70
73
. then ( ( ) => {
71
74
// set the new offset
72
75
this . offset += chunk . byteLength
@@ -79,31 +82,35 @@ class DropboxUploadStream extends Transform {
79
82
80
83
sessionFinish ( next ) {
81
84
// let dropbox know we are finished uploading
82
- this . dropbox . filesUploadSessionFinish ( {
83
- "cursor" : {
84
- "session_id" : this . sessionId , // id for this upload session
85
- "offset" : this . offset // offset, current location of chunk
86
- } ,
87
- "commit" : {
88
- "path" : this . options . saveLocation , // path to save thew new file
89
- "mode" : "add" , // add mode, this will NOT overwrite an existing file
90
- "autorename" : true , // if there is duplicates rename ex. file(2).txt
91
- "mute" : false // show notifications to db users that files were changed
92
- }
93
- } ) . then ( ( ) => {
94
- // we are finished uploading the file
95
- if ( this . options . debugMode ) {
96
- console . log ( `Filed Uploaded for save location ${ this . options . saveLocation } ` )
97
- }
98
-
99
- // reset variables
100
- this . sessionId = null
101
- this . offset = 0
102
- this . totalSize = null
103
-
104
- // trigger next because we are done
105
- next ( )
106
- } , next /* call next if there is an error*/ )
85
+ this . dropbox
86
+ . filesUploadSessionFinish ( {
87
+ cursor : {
88
+ session_id : this . sessionId , // id for this upload session
89
+ offset : this . offset , // offset, current location of chunk
90
+ } ,
91
+ commit : {
92
+ path : this . options . saveLocation , // path to save thew new file
93
+ mode : "add" , // add mode, this will NOT overwrite an existing file
94
+ autorename : true , // if there is duplicates rename ex. file(2).txt
95
+ mute : false , // show notifications to db users that files were changed
96
+ } ,
97
+ } )
98
+ . then ( ( ) => {
99
+ // we are finished uploading the file
100
+ if ( this . options . debugMode ) {
101
+ console . log (
102
+ `Filed Uploaded for save location ${ this . options . saveLocation } `
103
+ )
104
+ }
105
+
106
+ // reset variables
107
+ this . sessionId = null
108
+ this . offset = 0
109
+ this . totalSize = null
110
+
111
+ // trigger next because we are done
112
+ next ( )
113
+ } , next /* call next if there is an error*/ )
107
114
}
108
115
109
116
caluclateProgress ( ) {
@@ -112,20 +119,19 @@ class DropboxUploadStream extends Transform {
112
119
// size is set, calculate percentage and emit and event
113
120
this . options . progressEvent . emit ( "change" , {
114
121
id : this . options . id ,
115
- percentage : Math . floor ( ( this . offset / this . totalSize ) * 100 )
122
+ percentage : Math . floor ( this . offset / this . totalSize * 100 ) ,
116
123
} )
117
124
}
118
125
}
119
126
120
127
createTotalSize ( ) {
121
- streamLength ( this . options . file )
122
- . then ( size => {
123
- // set the total size
124
- this . totalSize = size
128
+ streamLength ( this . options . file ) . then ( size => {
129
+ // set the total size
130
+ this . totalSize = size
125
131
126
- // execute calculate size for initial calculation
127
- this . caluclateProgress ( )
128
- } )
132
+ // execute calculate size for initial calculation
133
+ this . caluclateProgress ( )
134
+ } )
129
135
}
130
136
}
131
137
0 commit comments