Skip to content

Commit

Permalink
Merge branch 'master' into feature/group-from
Browse files Browse the repository at this point in the history
# Conflicts:
#	.size-snapshot.json
#	CHANGELOG.md
#	package-lock.json
  • Loading branch information
bautrukevich committed Jul 15, 2019
2 parents 3894f05 + e41c52f commit e954c4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The first public alpha release.
* Low-level request wrappers for `/base/` and `/info/` paths of Upload API.
* `UploadClient` class with settings and `fileFrom` method that supports
only direct uploads now.
* Support of following Uploadcare Settings: `publicKey`, `baseUrl`,
* Support of following Uploadcare Settings: `publicKey`, `baseUrl`,
`doNotStore`, `integration`, `secureExpire`, `secureSignature`.
* Test environment for both Node.js and browsers

Expand Down
30 changes: 30 additions & 0 deletions src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {FileData, Settings} from '../types'
import {BaseProgress} from './base'
import {Thenable} from '../tools/Thenable'
import {CancelableInterface} from './types'
import {isNode} from '../tools/isNode'

export type Query = {
[key: string]: string | string[] | boolean | number | void,
Expand Down Expand Up @@ -52,6 +53,35 @@ const MAX_CONTENT_LENGTH = 50 * 1000 * 1000
const DEFAULT_FILE_NAME = 'original'
const DEFAULT_RETRY_AFTER_TIMEOUT = 15000

if (isNode()) {
axios.interceptors.request.use(
config => {
const {data, onUploadProgress} = config
if (!onUploadProgress) {
return config
}

const total = data.getLengthSync()

let loaded = 0

data.on('data', chunk => {
loaded += chunk.length

onUploadProgress({
total,
loaded,
} as ProgressEvent)
})

return config
},
error => {
return Promise.reject(error)
}
)
}

/**
* Updates options with Uploadcare Settings
*
Expand Down
8 changes: 8 additions & 0 deletions src/tools/isNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const isNode = (): boolean => {
try {
return Object.prototype.toString.call(global.process) === '[object process]'
}
catch (e) {
return false
}
}
2 changes: 1 addition & 1 deletion test/api/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('API - base', () => {
})
})

xit('should be able to handle progress', (done) => {
it('should be able to handle progress', (done) => {
let progressValue = 0
const settings = getSettingsForTesting({
publicKey: factory.publicKey('demo')
Expand Down

0 comments on commit e954c4c

Please sign in to comment.