Skip to content

Commit 1e906d9

Browse files
committed
2.2.0
1 parent c25c344 commit 1e906d9

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 2.2.0
3+
- Implemented automatic string cleaning to prevent file save errors.
4+
25
## 2.1.3
36
- Implemented Prettier.
47
- Formated files with Prettier.

lib/cleanString.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// returns a string that has been striped of all characters that would
2+
// cause errors in dropbox
3+
4+
const cleanString = str =>
5+
str
6+
.replace(/\*/g, "")
7+
.replace(/\|/g, "")
8+
.replace(/&/g, "")
9+
.replace(/!/g, "")
10+
.replace(/@/g, "")
11+
.replace(/#/g, "")
12+
.replace(/\$/g, "")
13+
.replace(/%/g, "")
14+
.replace(/\^/g, "")
15+
.replace(/\(/g, "")
16+
.replace(/\)/g, "")
17+
.replace(/-/g, "")
18+
.replace(/_/g, "")
19+
.replace(/\+/g, "")
20+
.replace(/=/g, "")
21+
.replace(/~/g, "")
22+
.replace(/`/g, "")
23+
.replace(/"/g, "")
24+
.replace(/'/g, "")
25+
.replace(/;/g, "")
26+
.replace(/:/g, "")
27+
.replace(/>/g, "")
28+
.replace(/</g, "")
29+
.replace(/\{/g, "")
30+
.replace(/\}/g, "")
31+
.replace(/\[/g, "")
32+
.replace(/\]/g, "")
33+
.replace(/\?/g, "")
34+
35+
module.exports = cleanString

lib/dropbox.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const { Transform } = require("stream")
33
const Dropbox = require("dropbox")
44
const streamLength = require("stream-length")
5+
const cleanString = require("./cleanString")
56

67
// Dropbox Upload Stream
78
class DropboxUploadStream extends Transform {
@@ -89,7 +90,7 @@ class DropboxUploadStream extends Transform {
8990
offset: this.offset, // offset, current location of chunk
9091
},
9192
commit: {
92-
path: this.options.saveLocation, // path to save thew new file
93+
path: cleanString(this.options.saveLocation), // path to save thew new file
9394
mode: "add", // add mode, this will NOT overwrite an existing file
9495
autorename: true, // if there is duplicates rename ex. file(2).txt
9596
mute: false, // show notifications to db users that files were changed
@@ -99,7 +100,9 @@ class DropboxUploadStream extends Transform {
99100
// we are finished uploading the file
100101
if (this.options.debugMode) {
101102
console.log(
102-
`Filed Uploaded for save location ${this.options.saveLocation}`
103+
`Filed Uploaded for save location ${cleanString(
104+
this.options.saveLocation
105+
)}`
103106
)
104107
}
105108

lib/transform.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import modules
22
const { Transform } = require("stream")
3+
const cleanString = require("./cleanString")
34

45
class TransformStream extends Transform {
56
constructor(options) {
@@ -37,7 +38,7 @@ class TransformStream extends Transform {
3738
console.log(
3839
`Passing buffer (size: ${Math.round(
3940
this.buffer.byteLength / 1024
40-
)} KB) for save location ${this.options.saveLocation}`
41+
)} KB) for save location ${cleanString(this.options.saveLocation)}`
4142
)
4243
}
4344

@@ -58,7 +59,7 @@ class TransformStream extends Transform {
5859
console.log(
5960
`Passing buffer (size: ${Math.round(
6061
this.buffer.byteLength / 1024
61-
)} KB) for save location ${this.options.saveLocation}`
62+
)} KB) for save location ${cleanString(this.options.saveLocation)}`
6263
)
6364
}
6465

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dropbox_session_upload",
3-
"version": "2.1.3",
3+
"version": "2.2.0",
44
"description": "Node wrapper around the dropbox upload session API to help concurrently upload files over 150mb to dropbox.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)