mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-26 11:44:53 +00:00
Merge pull request #432 from richardwillars/thumbnailGeneration
Adds ability to disable thumbnail generation
This commit is contained in:
commit
ee5abb6946
4 changed files with 54 additions and 4 deletions
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
() => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue