|
@@ -1,4 +1,5 @@
|
|
const Plugin = require('./Plugin')
|
|
const Plugin = require('./Plugin')
|
|
|
|
+const Translator = require('../core/Translator')
|
|
const UppySocket = require('../core/UppySocket')
|
|
const UppySocket = require('../core/UppySocket')
|
|
const {
|
|
const {
|
|
emitSocketProgress,
|
|
emitSocketProgress,
|
|
@@ -13,6 +14,12 @@ module.exports = class XHRUpload extends Plugin {
|
|
this.id = 'XHRUpload'
|
|
this.id = 'XHRUpload'
|
|
this.title = 'XHRUpload'
|
|
this.title = 'XHRUpload'
|
|
|
|
|
|
|
|
+ const defaultLocale = {
|
|
|
|
+ strings: {
|
|
|
|
+ timedOut: 'Upload stalled for %{seconds} seconds, aborting.'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Default options
|
|
// Default options
|
|
const defaultOptions = {
|
|
const defaultOptions = {
|
|
formData: true,
|
|
formData: true,
|
|
@@ -22,6 +29,7 @@ module.exports = class XHRUpload extends Plugin {
|
|
responseUrlFieldName: 'url',
|
|
responseUrlFieldName: 'url',
|
|
bundle: true,
|
|
bundle: true,
|
|
headers: {},
|
|
headers: {},
|
|
|
|
+ locale: defaultLocale,
|
|
timeout: 30 * 1000,
|
|
timeout: 30 * 1000,
|
|
getResponseData (xhr) {
|
|
getResponseData (xhr) {
|
|
return JSON.parse(xhr.response)
|
|
return JSON.parse(xhr.response)
|
|
@@ -33,6 +41,12 @@ module.exports = class XHRUpload extends Plugin {
|
|
|
|
|
|
// Merge default options with the ones set by user
|
|
// Merge default options with the ones set by user
|
|
this.opts = Object.assign({}, defaultOptions, opts)
|
|
this.opts = Object.assign({}, defaultOptions, opts)
|
|
|
|
+ this.locale = Object.assign({}, defaultLocale, this.opts.locale)
|
|
|
|
+ this.locale.strings = Object.assign({}, defaultLocale.strings, this.opts.locale.strings)
|
|
|
|
+
|
|
|
|
+ // i18n
|
|
|
|
+ this.translator = new Translator({ locale: this.locale })
|
|
|
|
+ this.i18n = this.translator.translate.bind(this.translator)
|
|
|
|
|
|
this.handleUpload = this.handleUpload.bind(this)
|
|
this.handleUpload = this.handleUpload.bind(this)
|
|
}
|
|
}
|
|
@@ -86,7 +100,7 @@ module.exports = class XHRUpload extends Plugin {
|
|
|
|
|
|
const onTimedOut = () => {
|
|
const onTimedOut = () => {
|
|
xhr.abort()
|
|
xhr.abort()
|
|
- const error = new Error(`No progress for ${Math.ceil(opts.timeout / 1000)} seconds, aborting`)
|
|
|
|
|
|
+ const error = new Error(this.i18n('timedOut', { seconds: Math.ceil(opts.timeout / 1000) }))
|
|
this.core.emit('core:upload-error', file.id, error)
|
|
this.core.emit('core:upload-error', file.id, error)
|
|
reject(error)
|
|
reject(error)
|
|
}
|
|
}
|