Merge pull request #432 from richardwillars/thumbnailGeneration

Adds ability to disable thumbnail generation
This commit is contained in:
Artur Paikin 2017-11-29 17:54:32 -05:00 committed by GitHub
commit ee5abb6946
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 4 deletions

View file

@ -45,7 +45,8 @@ class Uppy {
meta: {},
onBeforeFileAdded: (currentFile, files) => Promise.resolve(),
onBeforeUpload: (files, done) => Promise.resolve(),
locale: defaultLocale
locale: defaultLocale,
thumbnailGeneration: true
}
// Merge default options with the ones set by user
@ -394,8 +395,14 @@ class Uppy {
*/
generatePreview (file) {
if (Utils.isPreviewSupported(file.type) && !file.isRemote) {
Utils.createThumbnail(file, 200).then((thumbnail) => {
this.setPreviewURL(file.id, thumbnail)
let previewPromise
if (this.opts.thumbnailGeneration === true) {
previewPromise = Utils.createThumbnail(file, 200)
} else {
previewPromise = Promise.resolve(URL.createObjectURL(file.data))
}
previewPromise.then((preview) => {
this.setPreviewURL(file.id, preview)
}).catch((err) => {
console.warn(err.stack || err.message)
})

File diff suppressed because one or more lines are too long

View file

@ -217,7 +217,6 @@ function getProportionalHeight (img, width) {
*/
function createThumbnail (file, targetWidth) {
const originalUrl = URL.createObjectURL(file.data)
const onload = new Promise((resolve, reject) => {
const image = new Image()
image.src = originalUrl

View file

@ -261,6 +261,16 @@ describe('core/utils', () => {
})
describe('createThumbnail', () => {
const RealCreateObjectUrl = global.URL.createObjectURL
beforeEach(() => {
global.URL.createObjectURL = jest.fn().mockReturnValue('newUrl')
})
afterEach(() => {
global.URL.createObjectURL = RealCreateObjectUrl
})
xit(
'should create a thumbnail of the specified image at the specified width',
() => {}