New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@uppy/core

Package Overview
Dependencies
Maintainers
5
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/core - npm Package Compare versions

Comparing version 1.19.1 to 1.19.2

212

lib/index.js

@@ -50,5 +50,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var Plugin = require('./Plugin'); // Exported from here.
var Plugin = require('./Plugin');
var _require2 = require('../package.json'),
version = _require2.version; // Exported from here.
var RestrictionError = /*#__PURE__*/function (_Error) {

@@ -107,3 +110,3 @@ _inheritsLoose(RestrictionError, _Error);

exceedsSize2: '%{backwardsCompat} %{size}',
exceedsSize: 'This file exceeds maximum allowed size of',
exceedsSize: '%{file} exceeds maximum allowed size of',
inferiorSize: 'This file is smaller than the allowed size of %{size}',

@@ -160,3 +163,3 @@ youCanOnlyUploadFileTypes: 'You can only upload: %{types}',

meta: {},
onBeforeFileAdded: function onBeforeFileAdded(currentFile, files) {
onBeforeFileAdded: function onBeforeFileAdded(currentFile) {
return currentFile;

@@ -204,8 +207,10 @@ },

this.validateRestrictions = this.validateRestrictions.bind(this); // ___Why throttle at 500ms?
// - We must throttle at >250ms for superfocus in Dashboard to work well (because animation takes 0.25s, and we want to wait for all animations to be over before refocusing).
// [Practical Check]: if thottle is at 100ms, then if you are uploading a file, and click 'ADD MORE FILES', - focus won't activate in Firefox.
// - We must throttle at >250ms for superfocus in Dashboard to work well
// (because animation takes 0.25s, and we want to wait for all animations to be over before refocusing).
// [Practical Check]: if thottle is at 100ms, then if you are uploading a file,
// and click 'ADD MORE FILES', - focus won't activate in Firefox.
// - We must throttle at around >500ms to avoid performance lags.
// [Practical Check] Firefox, try to upload a big file for a prolonged period of time. Laptop will start to heat up.
this._calculateProgress = throttle(this._calculateProgress.bind(this), 500, {
this.calculateProgress = throttle(this.calculateProgress.bind(this), 500, {
leading: true,

@@ -250,3 +255,3 @@ trailing: true

});
this._storeUnsubscribe = this.store.subscribe(function (prevState, nextState, patch) {
this.storeUnsubscribe = this.store.subscribe(function (prevState, nextState, patch) {
_this2.emit('state-update', prevState, nextState, patch);

@@ -261,5 +266,4 @@

this._addListeners(); // Re-enable if we’ll need some capabilities on boot, like isMobileDevice
this.addListeners(); // Re-enable if we’ll need some capabilities on boot, like isMobileDevice
// this._setCapabilities()
} // _setCapabilities = () => {

@@ -361,4 +365,5 @@ // const capabilities = {

});
}
} // Note: this is not the preact `setState`, it's an internal function that has the same name.
this.setState(); // so that UI re-renders with new options

@@ -497,4 +502,3 @@ };

try {
this._checkRestrictions(file, files);
this.checkRestrictions(file, files);
return {

@@ -520,3 +524,3 @@ result: true

_proto._checkRestrictions = function _checkRestrictions(file, files) {
_proto.checkRestrictions = function checkRestrictions(file, files) {
if (files === void 0) {

@@ -569,4 +573,4 @@ files = this.getFiles();

totalFilesSize += file.size;
files.forEach(function (file) {
totalFilesSize += file.size;
files.forEach(function (f) {
totalFilesSize += f.size;
});

@@ -577,3 +581,4 @@

backwardsCompat: this.i18n('exceedsSize'),
size: prettierBytes(maxTotalFileSize)
size: prettierBytes(maxTotalFileSize),
file: file.name
}));

@@ -588,3 +593,4 @@ }

backwardsCompat: this.i18n('exceedsSize'),
size: prettierBytes(maxFileSize)
size: prettierBytes(maxFileSize),
file: file.name
}));

@@ -610,3 +616,3 @@ }

_proto._checkMinNumberOfFiles = function _checkMinNumberOfFiles(files) {
_proto.checkMinNumberOfFiles = function checkMinNumberOfFiles(files) {
var minNumberOfFiles = this.opts.restrictions.minNumberOfFiles;

@@ -633,3 +639,3 @@

_proto._showOrLogErrorAndThrow = function _showOrLogErrorAndThrow(err, _temp) {
_proto.showOrLogErrorAndThrow = function showOrLogErrorAndThrow(err, _temp) {
var _ref = _temp === void 0 ? {} : _temp,

@@ -674,3 +680,3 @@ _ref$showInformer = _ref.showInformer,

_proto._assertNewUploadAllowed = function _assertNewUploadAllowed(file) {
_proto.assertNewUploadAllowed = function assertNewUploadAllowed(file) {
var _this$getState2 = this.getState(),

@@ -680,3 +686,3 @@ allowNewUpload = _this$getState2.allowNewUpload;

if (allowNewUpload === false) {
this._showOrLogErrorAndThrow(new RestrictionError(this.i18n('noNewAlreadyUploading')), {
this.showOrLogErrorAndThrow(new RestrictionError(this.i18n('noNewAlreadyUploading')), {
file: file

@@ -695,4 +701,5 @@ });

_proto._checkAndCreateFileStateObject = function _checkAndCreateFileStateObject(files, file) {
var fileType = getFileType(file);
_proto.checkAndCreateFileStateObject = function checkAndCreateFileStateObject(files, f) {
var fileType = getFileType(f);
var file = f;
file.type = fileType;

@@ -703,3 +710,3 @@ var onBeforeFileAddedResult = this.opts.onBeforeFileAdded(file, files);

// Don’t show UI info for this error, as it should be done by the developer
this._showOrLogErrorAndThrow(new RestrictionError('Cannot add the file because onBeforeFileAdded returned false.'), {
this.showOrLogErrorAndThrow(new RestrictionError('Cannot add the file because onBeforeFileAdded returned false.'), {
showInformer: false,

@@ -729,3 +736,3 @@ file: file

if (files[fileID] && !files[fileID].isGhost) {
this._showOrLogErrorAndThrow(new RestrictionError(this.i18n('noDuplicates', {
this.showOrLogErrorAndThrow(new RestrictionError(this.i18n('noDuplicates', {
fileName: fileName

@@ -741,3 +748,3 @@ })), {

var size = isFinite(file.data.size) ? file.data.size : null;
var size = Number.isFinite(file.data.size) ? file.data.size : null;
var newFile = {

@@ -768,6 +775,5 @@ source: file.source || '',

});
this._checkRestrictions(newFile, filesArray);
this.checkRestrictions(newFile, filesArray);
} catch (err) {
this._showOrLogErrorAndThrow(err, {
this.showOrLogErrorAndThrow(err, {
file: newFile

@@ -781,3 +787,3 @@ });

_proto._startIfAutoProceed = function _startIfAutoProceed() {
_proto.startIfAutoProceed = function startIfAutoProceed() {
var _this3 = this;

@@ -810,3 +816,3 @@

this._assertNewUploadAllowed(file);
this.assertNewUploadAllowed(file);

@@ -816,6 +822,5 @@ var _this$getState3 = this.getState(),

var newFile = this._checkAndCreateFileStateObject(files, file); // Users are asked to re-select recovered files without data,
var newFile = this.checkAndCreateFileStateObject(files, file); // Users are asked to re-select recovered files without data,
// and to keep the progress, meta and everthing else, we only replace said data
if (files[newFile.id] && files[newFile.id].isGhost) {

@@ -835,5 +840,3 @@ newFile = _extends({}, files[newFile.id], {

this.log("Added file: " + newFile.name + ", " + newFile.id + ", mime type: " + newFile.type);
this._startIfAutoProceed();
this.startIfAutoProceed();
return newFile.id;

@@ -853,5 +856,4 @@ }

this._assertNewUploadAllowed(); // create a copy of the files object only once
this.assertNewUploadAllowed(); // create a copy of the files object only once
var files = _extends({}, this.getState().files);

@@ -864,6 +866,5 @@

try {
var newFile = this._checkAndCreateFileStateObject(files, fileDescriptors[i]); // Users are asked to re-select recovered files without data,
var newFile = this.checkAndCreateFileStateObject(files, fileDescriptors[i]); // Users are asked to re-select recovered files without data,
// and to keep the progress, meta and everthing else, we only replace said data
if (files[newFile.id] && files[newFile.id].isGhost) {

@@ -903,3 +904,3 @@ newFile = _extends({}, files[newFile.id], {

if (newFiles.length > 0) {
this._startIfAutoProceed();
this.startIfAutoProceed();
}

@@ -977,5 +978,3 @@

this.setState(stateUpdate);
this._calculateTotalProgress();
this.calculateTotalProgress();
var removedFileIDs = Object.keys(removedFiles);

@@ -1003,3 +1002,3 @@ removedFileIDs.forEach(function (fileID) {

if (!this.getState().capabilities.resumableUploads || this.getFile(fileID).uploadComplete) {
return;
return undefined;
}

@@ -1082,8 +1081,7 @@

var uploadID = this._createUpload(filesToRetry, {
var uploadID = this.createUpload(filesToRetry, {
forceAllowNewUpload: true // create new upload even if allowNewUpload: false
});
return this._runUpload(uploadID);
return this.runUpload(uploadID);
};

@@ -1116,9 +1114,7 @@

this.emit('upload-retry', fileID);
var uploadID = this._createUpload([fileID], {
var uploadID = this.createUpload([fileID], {
forceAllowNewUpload: true // create new upload even if allowNewUpload: false
});
return this._runUpload(uploadID);
return this.runUpload(uploadID);
};

@@ -1138,3 +1134,3 @@

_proto._calculateProgress = function _calculateProgress(file, data) {
_proto.calculateProgress = function calculateProgress(file, data) {
if (!this.getFile(file.id)) {

@@ -1146,3 +1142,3 @@ this.log("Not setting progress for a file that has been removed: " + file.id);

var canHavePercentage = isFinite(data.bytesTotal) && data.bytesTotal > 0;
var canHavePercentage = Number.isFinite(data.bytesTotal) && data.bytesTotal > 0;
this.setFileState(file.id, {

@@ -1157,7 +1153,6 @@ progress: _extends({}, this.getFile(file.id).progress, {

});
this._calculateTotalProgress();
this.calculateTotalProgress();
};
_proto._calculateTotalProgress = function _calculateTotalProgress() {
_proto.calculateTotalProgress = function calculateTotalProgress() {
// calculate total progress, using the number of files currently uploading,

@@ -1229,12 +1224,13 @@ // multiplied by 100 and the summ of individual progress of each file

_proto._addListeners = function _addListeners() {
_proto.addListeners = function addListeners() {
var _this6 = this;
this.on('error', function (error) {
var errorMsg = 'Unknown error';
/**
* @param {Error} error
* @param {object} [file]
* @param {object} [response]
*/
var errorHandler = function errorHandler(error, file, response) {
var errorMsg = error.message || 'Unknown error';
if (error.message) {
errorMsg = error.message;
}
if (error.details) {

@@ -1247,23 +1243,15 @@ errorMsg += " " + error.details;

});
});
this.on('upload-error', function (file, error, response) {
var errorMsg = 'Unknown error';
if (error.message) {
errorMsg = error.message;
if (file != null) {
_this6.setFileState(file.id, {
error: errorMsg,
response: response
});
}
};
if (error.details) {
errorMsg += " " + error.details;
}
this.on('error', errorHandler);
this.on('upload-error', function (file, error, response) {
errorHandler(error, file, response);
_this6.setFileState(file.id, {
error: errorMsg,
response: response
});
_this6.setState({
error: error.message
});
if (typeof error === 'object' && error.message) {

@@ -1281,7 +1269,7 @@ var newError = new Error(error.message);

_this6._showOrLogErrorAndThrow(newError, {
_this6.showOrLogErrorAndThrow(newError, {
throwErr: false
});
} else {
_this6._showOrLogErrorAndThrow(error, {
_this6.showOrLogErrorAndThrow(error, {
throwErr: false

@@ -1296,3 +1284,3 @@ });

});
this.on('upload-started', function (file, upload) {
this.on('upload-started', function (file) {
if (!_this6.getFile(file.id)) {

@@ -1314,3 +1302,3 @@ _this6.log("Not setting progress for a file that has been removed: " + file.id);

});
this.on('upload-progress', this._calculateProgress);
this.on('upload-progress', this.calculateProgress);
this.on('upload-success', function (file, uploadResp) {

@@ -1339,3 +1327,3 @@ if (!_this6.getFile(file.id)) {

_this6._calculateTotalProgress();
_this6.calculateTotalProgress();
});

@@ -1408,3 +1396,3 @@ this.on('preprocess-progress', function (file, progress) {

// Files may have changed--ensure progress is still accurate.
_this6._calculateTotalProgress();
_this6.calculateTotalProgress();
}); // show informer if offline

@@ -1453,2 +1441,3 @@

*/
// eslint-disable-next-line no-shadow
;

@@ -1569,5 +1558,3 @@

this.reset();
this._storeUnsubscribe();
this.storeUnsubscribe();
this.iteratePlugins(function (plugin) {

@@ -1671,8 +1658,7 @@ _this8.removePlugin(plugin);

if (!this.getState().currentUploads[uploadID]) {
this._removeUpload(uploadID);
this.removeUpload(uploadID);
return Promise.reject(new Error('Nonexistent upload'));
}
return this._runUpload(uploadID);
return this.runUpload(uploadID);
}

@@ -1687,3 +1673,3 @@ /**

_proto._createUpload = function _createUpload(fileIDs, opts) {
_proto.createUpload = function createUpload(fileIDs, opts) {
var _extends5;

@@ -1695,2 +1681,3 @@

// uppy.retryAll sets this to true — when retrying we want to ignore `allowNewUpload: false`
var _opts = opts,

@@ -1724,3 +1711,3 @@ _opts$forceAllowNewUp = _opts.forceAllowNewUpload,

_proto._getUpload = function _getUpload(uploadID) {
_proto.getUpload = function getUpload(uploadID) {
var _this$getState7 = this.getState(),

@@ -1742,3 +1729,3 @@ currentUploads = _this$getState7.currentUploads;

if (!this._getUpload(uploadID)) {
if (!this.getUpload(uploadID)) {
this.log("Not setting result for an upload that has been removed: " + uploadID);

@@ -1748,3 +1735,4 @@ return;

var currentUploads = this.getState().currentUploads;
var _this$getState8 = this.getState(),
currentUploads = _this$getState8.currentUploads;

@@ -1766,3 +1754,3 @@ var currentUpload = _extends({}, currentUploads[uploadID], {

_proto._removeUpload = function _removeUpload(uploadID) {
_proto.removeUpload = function removeUpload(uploadID) {
var currentUploads = _extends({}, this.getState().currentUploads);

@@ -1782,3 +1770,3 @@

_proto._runUpload = function _runUpload(uploadID) {
_proto.runUpload = function runUpload(uploadID) {
var _this9 = this;

@@ -1816,6 +1804,7 @@

// Otherwise when more metadata may be added to the upload this would keep getting more parameters
// eslint-disable-next-line consistent-return
return fn(updatedUpload.fileIDs, uploadID);
}).then(function (result) {
}).then(function () {
return null;

@@ -1829,3 +1818,3 @@ });

_this9._removeUpload(uploadID);
_this9.removeUpload(uploadID);
});

@@ -1892,4 +1881,5 @@ return lastStep.then(function () {

_this9._removeUpload(uploadID);
_this9.removeUpload(uploadID); // eslint-disable-next-line consistent-return
return result;

@@ -1918,3 +1908,5 @@ }).then(function (result) {

var files = this.getState().files;
var _this$getState9 = this.getState(),
files = _this$getState9.files;
var onBeforeUploadResult = this.opts.onBeforeUpload(files);

@@ -1936,5 +1928,5 @@

return Promise.resolve().then(function () {
return _this10._checkMinNumberOfFiles(files);
return _this10.checkMinNumberOfFiles(files);
}).catch(function (err) {
_this10._showOrLogErrorAndThrow(err);
_this10.showOrLogErrorAndThrow(err);
}).then(function () {

@@ -1958,7 +1950,7 @@ var _this10$getState = _this10.getState(),

var uploadID = _this10._createUpload(waitingFileIDs);
var uploadID = _this10.createUpload(waitingFileIDs);
return _this10._runUpload(uploadID);
return _this10.runUpload(uploadID);
}).catch(function (err) {
_this10._showOrLogErrorAndThrow(err, {
_this10.showOrLogErrorAndThrow(err, {
showInformer: false

@@ -1979,5 +1971,5 @@ });

Uppy.VERSION = "1.19.1";
Uppy.VERSION = version;
module.exports = function (opts) {
module.exports = function core(opts) {
return new Uppy(opts);

@@ -1984,0 +1976,0 @@ }; // Expose class constructor.

{
"name": "@uppy/core",
"description": "Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:",
"version": "1.19.1",
"version": "1.19.2",
"license": "MIT",

@@ -25,3 +25,3 @@ "main": "lib/index.js",

"@uppy/store-default": "^1.2.7",
"@uppy/utils": "^3.6.1",
"@uppy/utils": "^3.6.2",
"cuid": "^2.1.1",

@@ -33,3 +33,3 @@ "lodash.throttle": "^4.1.1",

},
"gitHead": "23e4a537a6ab8e5062529de36ad3a91c8257de19"
"gitHead": "4b782ffbbb443672843d7b4096956bed3b11d612"
}

@@ -16,2 +16,4 @@ /* global AggregateError */

const Plugin = require('./Plugin')
const { version } = require('../package.json')
// Exported from here.

@@ -31,3 +33,3 @@ class RestrictionError extends Error {

class Uppy {
static VERSION = require('../package.json').version
static VERSION = version

@@ -60,3 +62,3 @@ /**

exceedsSize2: '%{backwardsCompat} %{size}',
exceedsSize: 'This file exceeds maximum allowed size of',
exceedsSize: '%{file} exceeds maximum allowed size of',
inferiorSize: 'This file is smaller than the allowed size of %{size}',

@@ -114,3 +116,3 @@ youCanOnlyUploadFileTypes: 'You can only upload: %{types}',

meta: {},
onBeforeFileAdded: (currentFile, files) => currentFile,
onBeforeFileAdded: (currentFile) => currentFile,
onBeforeUpload: (files) => files,

@@ -167,7 +169,9 @@ store: DefaultStore(),

// ___Why throttle at 500ms?
// - We must throttle at >250ms for superfocus in Dashboard to work well (because animation takes 0.25s, and we want to wait for all animations to be over before refocusing).
// [Practical Check]: if thottle is at 100ms, then if you are uploading a file, and click 'ADD MORE FILES', - focus won't activate in Firefox.
// - We must throttle at >250ms for superfocus in Dashboard to work well
// (because animation takes 0.25s, and we want to wait for all animations to be over before refocusing).
// [Practical Check]: if thottle is at 100ms, then if you are uploading a file,
// and click 'ADD MORE FILES', - focus won't activate in Firefox.
// - We must throttle at around >500ms to avoid performance lags.
// [Practical Check] Firefox, try to upload a big file for a prolonged period of time. Laptop will start to heat up.
this._calculateProgress = throttle(this._calculateProgress.bind(this), 500, { leading: true, trailing: true })
this.calculateProgress = throttle(this.calculateProgress.bind(this), 500, { leading: true, trailing: true })

@@ -215,3 +219,3 @@ this.updateOnlineStatus = this.updateOnlineStatus.bind(this)

this._storeUnsubscribe = this.store.subscribe((prevState, nextState, patch) => {
this.storeUnsubscribe = this.store.subscribe((prevState, nextState, patch) => {
this.emit('state-update', prevState, nextState, patch)

@@ -226,3 +230,3 @@ this.updateAll(nextState)

this._addListeners()
this.addListeners()

@@ -332,2 +336,3 @@ // Re-enable if we’ll need some capabilities on boot, like isMobileDevice

// Note: this is not the preact `setState`, it's an internal function that has the same name.
this.setState() // so that UI re-renders with new options

@@ -447,3 +452,3 @@ }

try {
this._checkRestrictions(file, files)
this.checkRestrictions(file, files)
return {

@@ -468,3 +473,3 @@ result: true,

*/
_checkRestrictions (file, files = this.getFiles()) {
checkRestrictions (file, files = this.getFiles()) {
const { maxFileSize, minFileSize, maxTotalFileSize, maxNumberOfFiles, allowedFileTypes } = this.opts.restrictions

@@ -503,4 +508,4 @@

totalFilesSize += file.size
files.forEach((file) => {
totalFilesSize += file.size
files.forEach((f) => {
totalFilesSize += f.size
})

@@ -511,2 +516,3 @@ if (totalFilesSize > maxTotalFileSize) {

size: prettierBytes(maxTotalFileSize),
file: file.name,
}))

@@ -522,2 +528,3 @@ }

size: prettierBytes(maxFileSize),
file: file.name,
}))

@@ -542,3 +549,3 @@ }

*/
_checkMinNumberOfFiles (files) {
checkMinNumberOfFiles (files) {
const { minNumberOfFiles } = this.opts.restrictions

@@ -561,3 +568,3 @@ if (Object.keys(files).length < minNumberOfFiles) {

*/
_showOrLogErrorAndThrow (err, { showInformer = true, file = null, throwErr = true } = {}) {
showOrLogErrorAndThrow (err, { showInformer = true, file = null, throwErr = true } = {}) {
const message = typeof err === 'object' ? err.message : err

@@ -590,7 +597,7 @@ const details = (typeof err === 'object' && err.details) ? err.details : ''

_assertNewUploadAllowed (file) {
assertNewUploadAllowed (file) {
const { allowNewUpload } = this.getState()
if (allowNewUpload === false) {
this._showOrLogErrorAndThrow(new RestrictionError(this.i18n('noNewAlreadyUploading')), { file })
this.showOrLogErrorAndThrow(new RestrictionError(this.i18n('noNewAlreadyUploading')), { file })
}

@@ -606,4 +613,5 @@ }

*/
_checkAndCreateFileStateObject (files, file) {
const fileType = getFileType(file)
checkAndCreateFileStateObject (files, f) {
const fileType = getFileType(f)
let file = f
file.type = fileType

@@ -615,3 +623,3 @@

// Don’t show UI info for this error, as it should be done by the developer
this._showOrLogErrorAndThrow(new RestrictionError('Cannot add the file because onBeforeFileAdded returned false.'), { showInformer: false, file })
this.showOrLogErrorAndThrow(new RestrictionError('Cannot add the file because onBeforeFileAdded returned false.'), { showInformer: false, file })
}

@@ -637,3 +645,3 @@

if (files[fileID] && !files[fileID].isGhost) {
this._showOrLogErrorAndThrow(new RestrictionError(this.i18n('noDuplicates', { fileName })), { file })
this.showOrLogErrorAndThrow(new RestrictionError(this.i18n('noDuplicates', { fileName })), { file })
}

@@ -646,3 +654,3 @@

// `null` means the size is unknown.
const size = isFinite(file.data.size) ? file.data.size : null
const size = Number.isFinite(file.data.size) ? file.data.size : null
const newFile = {

@@ -674,5 +682,5 @@ source: file.source || '',

const filesArray = Object.keys(files).map(i => files[i])
this._checkRestrictions(newFile, filesArray)
this.checkRestrictions(newFile, filesArray)
} catch (err) {
this._showOrLogErrorAndThrow(err, { file: newFile })
this.showOrLogErrorAndThrow(err, { file: newFile })
}

@@ -684,3 +692,3 @@

// Schedule an upload if `autoProceed` is enabled.
_startIfAutoProceed () {
startIfAutoProceed () {
if (this.opts.autoProceed && !this.scheduledAutoProceed) {

@@ -707,6 +715,6 @@ this.scheduledAutoProceed = setTimeout(() => {

addFile (file) {
this._assertNewUploadAllowed(file)
this.assertNewUploadAllowed(file)
const { files } = this.getState()
let newFile = this._checkAndCreateFileStateObject(files, file)
let newFile = this.checkAndCreateFileStateObject(files, file)

@@ -735,3 +743,3 @@ // Users are asked to re-select recovered files without data,

this._startIfAutoProceed()
this.startIfAutoProceed()

@@ -749,3 +757,3 @@ return newFile.id

addFiles (fileDescriptors) {
this._assertNewUploadAllowed()
this.assertNewUploadAllowed()

@@ -758,3 +766,3 @@ // create a copy of the files object only once

try {
let newFile = this._checkAndCreateFileStateObject(files, fileDescriptors[i])
let newFile = this.checkAndCreateFileStateObject(files, fileDescriptors[i])
// Users are asked to re-select recovered files without data,

@@ -796,3 +804,3 @@ // and to keep the progress, meta and everthing else, we only replace said data

if (newFiles.length > 0) {
this._startIfAutoProceed()
this.startIfAutoProceed()
}

@@ -868,3 +876,3 @@

this.setState(stateUpdate)
this._calculateTotalProgress()
this.calculateTotalProgress()

@@ -890,3 +898,3 @@ const removedFileIDs = Object.keys(removedFiles)

|| this.getFile(fileID).uploadComplete) {
return
return undefined
}

@@ -970,6 +978,6 @@

const uploadID = this._createUpload(filesToRetry, {
const uploadID = this.createUpload(filesToRetry, {
forceAllowNewUpload: true, // create new upload even if allowNewUpload: false
})
return this._runUpload(uploadID)
return this.runUpload(uploadID)
}

@@ -1002,6 +1010,6 @@

const uploadID = this._createUpload([fileID], {
const uploadID = this.createUpload([fileID], {
forceAllowNewUpload: true, // create new upload even if allowNewUpload: false
})
return this._runUpload(uploadID)
return this.runUpload(uploadID)
}

@@ -1021,3 +1029,3 @@

_calculateProgress (file, data) {
calculateProgress (file, data) {
if (!this.getFile(file.id)) {

@@ -1029,3 +1037,3 @@ this.log(`Not setting progress for a file that has been removed: ${file.id}`)

// bytesTotal may be null or zero; in that case we can't divide by it
const canHavePercentage = isFinite(data.bytesTotal) && data.bytesTotal > 0
const canHavePercentage = Number.isFinite(data.bytesTotal) && data.bytesTotal > 0
this.setFileState(file.id, {

@@ -1039,3 +1047,3 @@ progress: {

// we get more accurate calculations if we don't round this at all.
? Math.round(data.bytesUploaded / data.bytesTotal * 100)
? Math.round((data.bytesUploaded / data.bytesTotal) * 100)
: 0,

@@ -1045,6 +1053,6 @@ },

this._calculateTotalProgress()
this.calculateTotalProgress()
}
_calculateTotalProgress () {
calculateTotalProgress () {
// calculate total progress, using the number of files currently uploading,

@@ -1074,3 +1082,3 @@ // multiplied by 100 and the summ of individual progress of each file

}, 0)
const totalProgress = Math.round(currentProgress / progressMax * 100)
const totalProgress = Math.round((currentProgress / progressMax) * 100)
this.setState({ totalProgress })

@@ -1091,3 +1099,3 @@ return

unsizedFiles.forEach((file) => {
uploadedSize += averageSize * (file.progress.percentage || 0) / 100
uploadedSize += (averageSize * (file.progress.percentage || 0)) / 100
})

@@ -1097,3 +1105,3 @@

? 0
: Math.round(uploadedSize / totalSize * 100)
: Math.round((uploadedSize / totalSize) * 100)

@@ -1114,9 +1122,10 @@ // hot fix, because:

*/
_addListeners () {
this.on('error', (error) => {
let errorMsg = 'Unknown error'
if (error.message) {
errorMsg = error.message
}
addListeners () {
/**
* @param {Error} error
* @param {object} [file]
* @param {object} [response]
*/
const errorHandler = (error, file, response) => {
let errorMsg = error.message || 'Unknown error'
if (error.details) {

@@ -1127,21 +1136,16 @@ errorMsg += ` ${error.details}`

this.setState({ error: errorMsg })
})
this.on('upload-error', (file, error, response) => {
let errorMsg = 'Unknown error'
if (error.message) {
errorMsg = error.message
if (file != null) {
this.setFileState(file.id, {
error: errorMsg,
response,
})
}
}
if (error.details) {
errorMsg += ` ${error.details}`
}
this.on('error', errorHandler)
this.setFileState(file.id, {
error: errorMsg,
response,
})
this.on('upload-error', (file, error, response) => {
errorHandler(error, file, response)
this.setState({ error: error.message })
if (typeof error === 'object' && error.message) {

@@ -1154,7 +1158,7 @@ const newError = new Error(error.message)

newError.message = this.i18n('failedToUpload', { file: file.name })
this._showOrLogErrorAndThrow(newError, {
this.showOrLogErrorAndThrow(newError, {
throwErr: false,
})
} else {
this._showOrLogErrorAndThrow(error, {
this.showOrLogErrorAndThrow(error, {
throwErr: false,

@@ -1169,3 +1173,3 @@ })

this.on('upload-started', (file, upload) => {
this.on('upload-started', (file) => {
if (!this.getFile(file.id)) {

@@ -1186,3 +1190,3 @@ this.log(`Not setting progress for a file that has been removed: ${file.id}`)

this.on('upload-progress', this._calculateProgress)
this.on('upload-progress', this.calculateProgress)

@@ -1211,3 +1215,3 @@ this.on('upload-success', (file, uploadResp) => {

this._calculateTotalProgress()
this.calculateTotalProgress()
})

@@ -1271,3 +1275,3 @@

// Files may have changed--ensure progress is still accurate.
this._calculateTotalProgress()
this.calculateTotalProgress()
})

@@ -1313,2 +1317,3 @@

*/
// eslint-disable-next-line no-shadow
use (Plugin, opts) {

@@ -1421,3 +1426,3 @@ if (typeof Plugin !== 'function') {

this._storeUnsubscribe()
this.storeUnsubscribe()

@@ -1501,7 +1506,7 @@ this.iteratePlugins((plugin) => {

if (!this.getState().currentUploads[uploadID]) {
this._removeUpload(uploadID)
this.removeUpload(uploadID)
return Promise.reject(new Error('Nonexistent upload'))
}
return this._runUpload(uploadID)
return this.runUpload(uploadID)
}

@@ -1515,6 +1520,5 @@

*/
_createUpload (fileIDs, opts = {}) {
const {
forceAllowNewUpload = false, // uppy.retryAll sets this to true — when retrying we want to ignore `allowNewUpload: false`
} = opts
createUpload (fileIDs, opts = {}) {
// uppy.retryAll sets this to true — when retrying we want to ignore `allowNewUpload: false`
const { forceAllowNewUpload = false } = opts

@@ -1549,3 +1553,3 @@ const { allowNewUpload, currentUploads } = this.getState()

_getUpload (uploadID) {
getUpload (uploadID) {
const { currentUploads } = this.getState()

@@ -1563,7 +1567,7 @@

addResultData (uploadID, data) {
if (!this._getUpload(uploadID)) {
if (!this.getUpload(uploadID)) {
this.log(`Not setting result for an upload that has been removed: ${uploadID}`)
return
}
const currentUploads = this.getState().currentUploads
const { currentUploads } = this.getState()
const currentUpload = { ...currentUploads[uploadID], result: { ...currentUploads[uploadID].result, ...data } }

@@ -1580,3 +1584,3 @@ this.setState({

*/
_removeUpload (uploadID) {
removeUpload (uploadID) {
const currentUploads = { ...this.getState().currentUploads }

@@ -1595,3 +1599,3 @@ delete currentUploads[uploadID]

*/
_runUpload (uploadID) {
runUpload (uploadID) {
const uploadData = this.getState().currentUploads[uploadID]

@@ -1633,4 +1637,5 @@ const restoreStep = uploadData.step

// Otherwise when more metadata may be added to the upload this would keep getting more parameters
// eslint-disable-next-line consistent-return
return fn(updatedUpload.fileIDs, uploadID)
}).then((result) => {
}).then(() => {
return null

@@ -1644,3 +1649,3 @@ })

this.emit('error', err, uploadID)
this._removeUpload(uploadID)
this.removeUpload(uploadID)
})

@@ -1687,7 +1692,8 @@

const currentUpload = currentUploads[uploadID]
const result = currentUpload.result
const { result } = currentUpload
this.emit('complete', result)
this._removeUpload(uploadID)
this.removeUpload(uploadID)
// eslint-disable-next-line consistent-return
return result

@@ -1712,3 +1718,3 @@ }).then((result) => {

let files = this.getState().files
let { files } = this.getState()

@@ -1731,5 +1737,5 @@ const onBeforeUploadResult = this.opts.onBeforeUpload(files)

return Promise.resolve()
.then(() => this._checkMinNumberOfFiles(files))
.then(() => this.checkMinNumberOfFiles(files))
.catch((err) => {
this._showOrLogErrorAndThrow(err)
this.showOrLogErrorAndThrow(err)
})

@@ -1739,3 +1745,4 @@ .then(() => {

// get a list of files that are currently assigned to uploads
const currentlyUploadingFiles = Object.keys(currentUploads).reduce((prev, curr) => prev.concat(currentUploads[curr].fileIDs), [])
const currentlyUploadingFiles = Object.keys(currentUploads)
.reduce((prev, curr) => prev.concat(currentUploads[curr].fileIDs), [])

@@ -1751,7 +1758,7 @@ const waitingFileIDs = []

const uploadID = this._createUpload(waitingFileIDs)
return this._runUpload(uploadID)
const uploadID = this.createUpload(waitingFileIDs)
return this.runUpload(uploadID)
})
.catch((err) => {
this._showOrLogErrorAndThrow(err, {
this.showOrLogErrorAndThrow(err, {
showInformer: false,

@@ -1763,3 +1770,3 @@ })

module.exports = function (opts) {
module.exports = function core (opts) {
return new Uppy(opts)

@@ -1766,0 +1773,0 @@ }

@@ -0,1 +1,2 @@

/* eslint no-console: "off", no-restricted-syntax: "off" */
const fs = require('fs')

@@ -72,4 +73,3 @@ const path = require('path')

expect(() =>
core.use(InvalidPluginWithoutId)).toThrowErrorMatchingSnapshot()
expect(() => core.use(InvalidPluginWithoutId)).toThrowErrorMatchingSnapshot()
})

@@ -80,4 +80,3 @@

expect(() =>
core.use(InvalidPluginWithoutType)).toThrowErrorMatchingSnapshot()
expect(() => core.use(InvalidPluginWithoutType)).toThrowErrorMatchingSnapshot()
})

@@ -264,3 +263,3 @@

const fileIDs = Object.keys(core.getState().files)
const id = core._createUpload(fileIDs)
const id = core.createUpload(fileIDs)

@@ -313,9 +312,9 @@ expect(core.getState().currentUploads[id]).toBeDefined()

const core = new Core()
core.addPreProcessor((fileIDs, uploadID) => {
core.addPreProcessor((_, uploadID) => {
core.addResultData(uploadID, { pre: 'ok' })
})
core.addPostProcessor((fileIDs, uploadID) => {
core.addPostProcessor((_, uploadID) => {
core.addResultData(uploadID, { post: 'ok' })
})
core.addUploader((fileIDs, uploadID) => {
core.addUploader((_, uploadID) => {
core.addResultData(uploadID, { upload: 'ok' })

@@ -334,3 +333,3 @@ })

const core = new Core()
const preprocessor = function () {}
const preprocessor = () => {}
core.addPreProcessor(preprocessor)

@@ -342,5 +341,5 @@ expect(core.preProcessors[0]).toEqual(preprocessor)

const core = new Core()
const preprocessor1 = function () {}
const preprocessor2 = function () {}
const preprocessor3 = function () {}
const preprocessor1 = () => {}
const preprocessor2 = () => {}
const preprocessor3 = () => {}
core.addPreProcessor(preprocessor1)

@@ -465,3 +464,3 @@ core.addPreProcessor(preprocessor2)

const core = new Core()
const postprocessor = function () {}
const postprocessor = () => {}
core.addPostProcessor(postprocessor)

@@ -473,5 +472,5 @@ expect(core.postProcessors[0]).toEqual(postprocessor)

const core = new Core()
const postprocessor1 = function () {}
const postprocessor2 = function () {}
const postprocessor3 = function () {}
const postprocessor1 = () => {}
const postprocessor2 = () => {}
const postprocessor3 = () => {}
core.addPostProcessor(postprocessor1)

@@ -569,2 +568,25 @@ core.addPostProcessor(postprocessor2)

})
it('should report an error if post-processing a file fails', () => {
const core = new Core()
core.addFile({
source: 'jest',
name: 'foo.jpg',
type: 'image/jpeg',
data: new File([sampleImage], { type: 'image/jpeg' }),
})
const fileId = Object.keys(core.getState().files)[0]
const file = core.getFile(fileId)
core.emit('error', new Error('foooooo'), file)
expect(core.getState().error).toEqual('foooooo')
expect(core.upload()).resolves.toMatchObject({
failed: [
{ name: 'foo.jpg' },
],
})
})
})

@@ -575,3 +597,3 @@

const core = new Core()
const uploader = function () {}
const uploader = () => {}
core.addUploader(uploader)

@@ -583,5 +605,5 @@ expect(core.uploaders[0]).toEqual(uploader)

const core = new Core()
const uploader1 = function () {}
const uploader2 = function () {}
const uploader3 = function () {}
const uploader1 = () => {}
const uploader2 = () => {}
const uploader3 = () => {}
core.addUploader(uploader1)

@@ -724,6 +746,7 @@ core.addUploader(uploader2)

const core = new Core({
onBeforeFileAdded: (file, files) => {
onBeforeFileAdded: (file) => {
if (file.source === 'jest') {
return false
}
return true
},

@@ -843,3 +866,3 @@ })

const core = new Core()
core.addUploader((fileIDs) => Promise.resolve())
core.addUploader(() => Promise.resolve())

@@ -896,3 +919,3 @@ core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })

}
core.addUploader((fileIDs) => Promise.resolve())
core.addUploader(() => Promise.resolve())

@@ -908,4 +931,5 @@ core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() })

const core = new Core({
// eslint-disable-next-line consistent-return
onBeforeUpload: (files) => {
for (var fileId in files) {
for (const fileId in files) {
if (files[fileId].name === '123.foo') {

@@ -1291,3 +1315,3 @@ return false

core._calculateProgress.flush()
core.calculateProgress.flush()

@@ -1327,3 +1351,3 @@ expect(core.getFile(fileId).progress).toEqual({

core._calculateTotalProgress()
core.calculateTotalProgress()

@@ -1401,3 +1425,3 @@ const uploadPromise = core.upload()

core._calculateTotalProgress()
core.calculateTotalProgress()

@@ -1443,4 +1467,4 @@ // foo.jpg at 35%, bar.jpg at 0%

core._calculateTotalProgress()
core._calculateProgress.flush()
core.calculateTotalProgress()
core.calculateProgress.flush()

@@ -1482,4 +1506,4 @@ expect(core.getState().totalProgress).toEqual(66)

core._calculateTotalProgress()
core._calculateProgress.flush()
core.calculateTotalProgress()
core.calculateProgress.flush()

@@ -1618,4 +1642,4 @@ expect(core.getState().totalProgress).toEqual(66)

} catch (err) {
expect(err).toMatchObject(new Error('This file exceeds maximum allowed size of 1.2 KB'))
expect(core.getState().info.message).toEqual('This file exceeds maximum allowed size of 1.2 KB')
expect(err).toMatchObject(new Error('foo.jpg exceeds maximum allowed size of 1.2 KB'))
expect(core.getState().info.message).toEqual('foo.jpg exceeds maximum allowed size of 1.2 KB')
}

@@ -1667,3 +1691,3 @@ })

}).toThrowError(
new Error('This file exceeds maximum allowed size of 33 KB')
new Error('foo1.jpg exceeds maximum allowed size of 33 KB')
)

@@ -1726,7 +1750,9 @@ })

}
const errorMessage = `${core.i18n('exceedsSize')} ${prettierBytes(maxFileSize)}`
const errorMessage = `${core.i18n('exceedsSize', { file: file.name })} ${prettierBytes(maxFileSize)}`
try {
core.on('restriction-failed', restrictionsViolatedEventMock)
core.addFile(file)
} catch (err) {}
} catch (err) {
// something
}

@@ -1913,3 +1939,3 @@ expect(restrictionsViolatedEventMock.mock.calls.length).toEqual(1)

core._createUpload(Object.keys(core.getState().files))
core.createUpload(Object.keys(core.getState().files))
const uploadId = Object.keys(core.getState().currentUploads)[0]

@@ -1936,3 +1962,3 @@ const currentUploadsState = {}

expect(core.i18n('exceedsSize')).toBe('This file exceeds maximum allowed size of')
expect(core.i18n('exceedsSize')).toBe('%{file} exceeds maximum allowed size of')
expect(core.i18n('test')).toBe('beep boop')

@@ -1939,0 +1965,0 @@ })

@@ -150,13 +150,13 @@ import UppyUtils = require('@uppy/utils')

type UploadSuccessCallback<T> = (file: UppyFile<T>, body: any, uploadURL: string) => void
type UploadCompleteCallback<T> = (result: UploadResult<T>) => void
class Uppy<TUseStrictTypes extends TypeChecking = TypeChecking> {
constructor(opts?: UppyOptions)
on<TMeta extends IndexedObject<any> = {}>(
event: 'upload-success',
callback: (file: UppyFile<TMeta>, body: any, uploadURL: string) => void
): this
on<TMeta extends IndexedObject<any> = {}>(
event: 'complete',
callback: (result: UploadResult<TMeta>) => void
): this
on<TMeta extends IndexedObject<any> = {}>(event: 'upload-success', callback: UploadSuccessCallback<TMeta>): this
on<TMeta extends IndexedObject<any> = {}>(event: 'complete', callback: UploadCompleteCallback<TMeta>): this
on(event: Event, callback: (...args: any[]) => void): this
once<TMeta extends IndexedObject<any> = {}>(event: 'upload-success', callback: UploadSuccessCallback<TMeta>): this
once<TMeta extends IndexedObject<any> = {}>(event: 'complete', callback: UploadCompleteCallback<TMeta>): this
once(event: Event, callback: (...args: any[]) => void): this
off(event: Event, callback: (...args: any[]) => void): this

@@ -163,0 +163,0 @@ /**

@@ -84,9 +84,13 @@ import { expectError, expectType } from 'tsd'

// can register listners for internal events
// can register listeners for internal events
uppy.on('upload', () => {})
uppy.on('complete', () => {})
uppy.on('error', () => {})
uppy.once('upload', () => {})
uppy.once('complete', () => {})
uppy.once('error', () => {})
// can register listners on custom events
// can register listeners on custom events
uppy.on('dashboard:modal-closed', () => {})
uppy.once('dashboard:modal-closed', () => {})
}

@@ -93,0 +97,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc