Skip to content

Commit ef477ff

Browse files
Merge pull request #1 from transloadit/master
Merge
2 parents 63b5769 + 1e07cf1 commit ef477ff

File tree

10 files changed

+184
-57
lines changed

10 files changed

+184
-57
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Ideas that will be planned and find their way into a release at one point
4747
- [ ] possibility to edit/delete more than one file at once #118, #97
4848
- [ ] optimize problematic filenames #72
4949
- [ ] an uploader plugin to receive files in a callback instead of uploading them
50+
- [ ] core: calling `upload` immediately after `addFile` does not upload all files (#249 @goto-bus-stop)
5051

5152
## 1.0 Goals
5253

@@ -55,7 +56,7 @@ What we need to do to release Uppy 1.0
5556
- [x] feature: restrictions: by size, number of files, file type
5657
- [x] feature: beta file recovering after closed tab / browser crash
5758
- [ ] feature: improved UI for Provider, Google Drive and Instagram, grid/list views
58-
- [ ] feature: finish the direct-to-s3 upload plugin and test it with the flow to then upload to :transloadit: afterwards. This is because this might influence the inner flow of the plugin architecture quite a bit
59+
- [x] feature: finish the direct-to-s3 upload plugin and test it with the flow to then upload to :transloadit: afterwards. This is because this might influence the inner flow of the plugin architecture quite a bit
5960
- [ ] feature: Uppy should work well with React/Redux and React Native
6061
- [ ] feature: preset for Transloadit that mimics jQuery SDK
6162
- [ ] QA: test how everything works together: user experience from `npm install` to production build with Webpack, using in React/Redux environment (npm pack)
@@ -95,9 +96,8 @@ Theme: React and Retry
9596

9697
- [ ] core: add error in file progress state? error UI, question mark button, `core:error` (@arturi)
9798
- [ ] core: retry or show error when upload can’t start / fails (offline, wrong endpoint) — now it just sits there (@arturi @goto-bus-stop)
98-
- [ ] core: calling `upload` immediately after `addFile` does not upload all files (#249 @goto-bus-stop)
9999
- [ ] core: React / Redux PRs (@arturi @goto-bus-stop)
100-
- [ ] transloadit: upload to S3, then import into :tl: assembly using `/add_file?s3url=${url}` (@goto-bus-stop)
100+
- [x] transloadit: upload to S3, then import into :tl: assembly using `/add_file?s3url=${url}` (@goto-bus-stop)
101101
- [ ] goldenretriver: add “ghost” files (@arturi @goto-bus-stop)
102102
- [ ] dashboard: cancel button for any kind of uploads? currently resume/pause only for tus, and cancel for XHR (@arturi @goto-bus-stop)
103103
- [x] informer: support “explanations”, a (?) button that shows more info on hover / click

src/core/Core.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Uppy {
7272
this.initSocket = this.initSocket.bind(this)
7373
this.log = this.log.bind(this)
7474
this.addFile = this.addFile.bind(this)
75+
this.removeFile = this.removeFile.bind(this)
7576
this.calculateProgress = this.calculateProgress.bind(this)
7677
this.resetProgress = this.resetProgress.bind(this)
7778

@@ -115,10 +116,8 @@ class Uppy {
115116
*
116117
*/
117118
updateAll (state) {
118-
Object.keys(this.plugins).forEach((pluginType) => {
119-
this.plugins[pluginType].forEach((plugin) => {
120-
plugin.update(state)
121-
})
119+
this.iteratePlugins(plugin => {
120+
plugin.update(state)
122121
})
123122
}
124123

@@ -444,7 +443,11 @@ class Uppy {
444443

445444
this.on('core:upload-error', (fileID, error) => {
446445
const fileName = this.state.files[fileID].name
447-
this.info(`Failed to upload: ${fileName}`, 'error', 5000)
446+
let message = `Failed to upload ${fileName}`
447+
if (typeof error === 'object' && error.message) {
448+
message = `${message}: ${error.message}`
449+
}
450+
this.info(message, 'error', 5000)
448451
})
449452

450453
this.on('core:upload', () => {
@@ -609,21 +612,21 @@ class Uppy {
609612

610613
// Instantiate
611614
const plugin = new Plugin(this, opts)
612-
const pluginName = plugin.id
615+
const pluginId = plugin.id
613616
this.plugins[plugin.type] = this.plugins[plugin.type] || []
614617

615-
if (!pluginName) {
616-
throw new Error('Your plugin must have a name')
618+
if (!pluginId) {
619+
throw new Error('Your plugin must have an id')
617620
}
618621

619622
if (!plugin.type) {
620623
throw new Error('Your plugin must have a type')
621624
}
622625

623-
let existsPluginAlready = this.getPlugin(pluginName)
626+
let existsPluginAlready = this.getPlugin(pluginId)
624627
if (existsPluginAlready) {
625-
let msg = `Already found a plugin named '${existsPluginAlready.name}'.
626-
Tried to use: '${pluginName}'.
628+
let msg = `Already found a plugin named '${existsPluginAlready.id}'.
629+
Tried to use: '${pluginId}'.
627630
Uppy is currently limited to running one of every plugin.
628631
Share your use case with us over at
629632
https://github.com/transloadit/uppy/issues/

src/plugins/AwsS3/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ module.exports = class AwsS3 extends Plugin {
6666
key: getValue('Key'),
6767
etag: getValue('ETag')
6868
}
69+
},
70+
getResponseError (xhr) {
71+
// If no response, we don't have a specific error message, use the default.
72+
if (!xhr.responseXML) {
73+
return
74+
}
75+
const error = xhr.responseXML.querySelector('Error > Message')
76+
return new Error(error.textContent)
6977
}
7078
})
7179
})

src/plugins/Dashboard/FileCard.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ module.exports = function fileCard (props) {
66
const file = props.fileCardFor ? props.files[props.fileCardFor] : false
77
const meta = {}
88

9-
function tempStoreMeta (ev) {
9+
const tempStoreMetaOrSubmit = (ev) => {
10+
if (ev.keyCode === 13) {
11+
props.done(meta, file.id)
12+
}
13+
1014
const value = ev.target.value
11-
const name = ev.target.attributes.name.value
15+
const name = ev.target.dataset.name
1216
meta[name] = value
1317
}
1418

@@ -18,11 +22,11 @@ module.exports = function fileCard (props) {
1822
return html`<fieldset class="UppyDashboardFileCard-fieldset">
1923
<label class="UppyDashboardFileCard-label">${field.name}</label>
2024
<input class="UppyDashboardFileCard-input"
21-
name="${field.id}"
2225
type="text"
26+
data-name="${field.id}"
2327
value="${file.meta[field.id]}"
2428
placeholder="${field.placeholder || ''}"
25-
onkeyup=${tempStoreMeta} /></fieldset>`
29+
onkeyup=${tempStoreMetaOrSubmit} /></fieldset>`
2630
})
2731
}
2832

@@ -46,8 +50,8 @@ module.exports = function fileCard (props) {
4650
<div class="UppyDashboardFileCard-info">
4751
<fieldset class="UppyDashboardFileCard-fieldset">
4852
<label class="UppyDashboardFileCard-label">Name</label>
49-
<input class="UppyDashboardFileCard-input" name="name" type="text" value="${file.meta.name}"
50-
onkeyup=${tempStoreMeta} />
53+
<input class="UppyDashboardFileCard-input" data-name="name" type="text" value="${file.meta.name}"
54+
onkeyup=${tempStoreMetaOrSubmit} />
5155
</fieldset>
5256
${renderMetaFields(file)}
5357
</div>
@@ -60,5 +64,5 @@ module.exports = function fileCard (props) {
6064
title="Finish editing file"
6165
onclick=${() => props.done(meta, file.id)}>${checkIcon()}</button>
6266
</div>
63-
</div>`
67+
</div>`
6468
}

src/plugins/Dashboard/index.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ module.exports = class DashboardUI extends Plugin {
249249
}
250250

251251
handleFileCard (fileId) {
252-
const modal = this.core.getState().modal
252+
const modal = this.core.state.modal
253253

254254
this.core.setState({
255255
modal: Object.assign({}, modal, {
@@ -318,44 +318,36 @@ module.exports = class DashboardUI extends Plugin {
318318
return target.type === 'progressindicator'
319319
})
320320

321-
// const addFile = (file) => {
322-
// this.core.emitter.emit('core:file-add', file)
323-
// }
324-
325-
const removeFile = (fileID) => {
326-
this.core.emitter.emit('core:file-remove', fileID)
327-
}
328-
329321
const startUpload = (ev) => {
330322
this.core.upload().catch((err) => {
331323
// Log error.
332-
console.error(err.stack || err.message || err)
324+
this.core.log(err.stack || err.message || err)
333325
})
334326
}
335327

336328
const pauseUpload = (fileID) => {
337-
this.core.emitter.emit('core:upload-pause', fileID)
329+
this.core.emit.emit('core:upload-pause', fileID)
338330
}
339331

340332
const cancelUpload = (fileID) => {
341-
this.core.emitter.emit('core:upload-cancel', fileID)
342-
this.core.emitter.emit('core:file-remove', fileID)
333+
this.core.emit('core:upload-cancel', fileID)
334+
this.core.emit('core:file-remove', fileID)
343335
}
344336

345337
const showFileCard = (fileID) => {
346-
this.core.emitter.emit('dashboard:file-card', fileID)
338+
this.core.emit('dashboard:file-card', fileID)
347339
}
348340

349341
const fileCardDone = (meta, fileID) => {
350-
this.core.emitter.emit('core:update-meta', meta, fileID)
351-
this.core.emitter.emit('dashboard:file-card')
342+
this.core.emit('core:update-meta', meta, fileID)
343+
this.core.emit('dashboard:file-card')
352344
}
353345

354346
const info = (text, type, duration) => {
355347
this.core.info(text, type, duration)
356348
}
357349

358-
const resumableUploads = this.core.getState().capabilities.resumableUploads || false
350+
const resumableUploads = this.core.state.capabilities.resumableUploads || false
359351

360352
return Dashboard({
361353
state: state,
@@ -382,7 +374,7 @@ module.exports = class DashboardUI extends Plugin {
382374
pauseAll: this.pauseAll,
383375
resumeAll: this.resumeAll,
384376
addFile: this.core.addFile,
385-
removeFile: removeFile,
377+
removeFile: this.core.removeFile,
386378
info: info,
387379
note: this.opts.note,
388380
metaFields: state.metaFields,

src/plugins/Plugin.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = class Plugin {
1717
constructor (core, opts) {
1818
this.core = core
1919
this.opts = opts || {}
20-
this.type = 'none'
2120

2221
// clear everything inside the target selector
2322
this.opts.replaceTargetContent === this.opts.replaceTargetContent || true

src/plugins/Transloadit/Client.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = class Client {
3030
Object.keys(fields).forEach((key) => {
3131
data.append(key, fields[key])
3232
})
33-
data.append('tus_num_expected_upload_files', expectedFiles)
33+
data.append('num_expected_upload_files', expectedFiles)
3434

3535
return fetch(`${this.apiUrl}/assemblies`, {
3636
method: 'post',
@@ -47,6 +47,26 @@ module.exports = class Client {
4747
})
4848
}
4949

50+
reserveFile (assembly, file) {
51+
const size = encodeURIComponent(file.size)
52+
return fetch(`${assembly.assembly_ssl_url}/reserve_file?size=${size}`, { method: 'post' })
53+
.then((response) => response.json())
54+
}
55+
56+
addFile (assembly, file) {
57+
if (!file.uploadURL) {
58+
return Promise.reject(new Error('File does not have an `uploadURL`.'))
59+
}
60+
const size = encodeURIComponent(file.size)
61+
const url = encodeURIComponent(file.uploadURL)
62+
const filename = encodeURIComponent(file.name)
63+
const fieldname = 'file'
64+
65+
const qs = `size=${size}&filename=${filename}&fieldname=${fieldname}&s3Url=${url}`
66+
return fetch(`${assembly.assembly_ssl_url}/add_file?${qs}`, { method: 'post' })
67+
.then((response) => response.json())
68+
}
69+
5070
/**
5171
* Get the current status for an assembly.
5272
*

0 commit comments

Comments
 (0)