Socket
Socket
Sign inDemoInstall

cloudinary-core

Package Overview
Dependencies
1
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.12.2 to 2.12.3

2

package.json
{
"name": "cloudinary-core",
"version": "2.12.2",
"version": "2.12.3",
"description": "Cloudinary Client Side JS library. Cloudinary streamlines your web application’s image manipulation needs. Cloudinary's cloud-based servers automate image uploading, resizing, cropping, optimizing, sprite generation and more.",

@@ -5,0 +5,0 @@ "main": "cloudinary-core.js",

/**
* Reject on timeout
* @param maxTimeoutMS
* @param reject
* @returns {number} timerID
*/
function rejectOnTimeout(maxTimeoutMS, reject) {
return setTimeout(() => {
reject({
status: 'error',
message: 'Timeout loading Blob URL'
});
}, maxTimeoutMS);
}
/**
* @description Converts a URL to a BLOB URL

@@ -13,25 +28,18 @@ * @param {string} urlToLoad

*/
function getBlobFromURL(urlToLoad, max_timeout_ms) {
function getBlobFromURL(urlToLoad, maxTimeoutMS) {
return new Promise((resolve, reject) => {
let timerID = setTimeout(() => {
reject({
status: 'error',
message: 'Timeout loading Blob URL'
});
}, max_timeout_ms);
const timerID = rejectOnTimeout(maxTimeoutMS, reject);
let xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function (response) {
clearTimeout(timerID); // clear timeout reject error
// If fetch exists, use it to fetch blob, otherwise use XHR.
// XHR causes issues on safari 14.1 so we prefer fetch
const fetchBlob = (typeof fetch !== 'undefined' && fetch) ? loadUrlUsingFetch : loadUrlUsingXhr;
fetchBlob(urlToLoad).then((blob) => {
resolve({
status: 'success',
payload: {
blobURL: URL.createObjectURL(xhr.response)
blobURL: URL.createObjectURL(blob)
}
});
};
xhr.onerror = function () {
clearTimeout(timerID); // clear timeout reject error
}).catch(() => {
reject({

@@ -41,3 +49,43 @@ status: 'error',

});
}).finally(() => {
// Clear the timeout timer on fail or success.
clearTimeout(timerID);
});
});
}
/**
* Use fetch function to fetch file
* @param urlToLoad
* @returns {Promise<unknown>}
*/
function loadUrlUsingFetch(urlToLoad) {
return new Promise((resolve, reject) => {
fetch(urlToLoad).then((response) => {
response.blob().then((blob) => {
resolve(blob);
});
}).catch(() => {
reject('error');
});
});
}
/**
* Use XHR to fetch file
* @param urlToLoad
* @returns {Promise<unknown>}
*/
function loadUrlUsingXhr(urlToLoad) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function (response) {
resolve(xhr.response);
};
xhr.onerror = function () {
reject('error');
};
xhr.open('GET', urlToLoad, true);

@@ -44,0 +92,0 @@ xhr.send();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc