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

@uppy/url

Package Overview
Dependencies
Maintainers
8
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/url - npm Package Compare versions

Comparing version 2.0.5 to 2.1.0

lib/package.json

7

CHANGELOG.md
# @uppy/url
## 2.1.0
Released: 2022-05-14
Included in: Uppy v2.10.0
- @uppy/url: refactor to ESM (Antoine du Hamel / #3713)
## 2.0.5

@@ -4,0 +11,0 @@

221

lib/index.js
"use strict";
var _class, _temp;
const {
UIPlugin
} = require('@uppy/core');
const {
h
} = require('preact');
const {
RequestClient
} = require('@uppy/companion-client');
const toArray = require('@uppy/utils/lib/toArray');
const UrlUI = require('./UrlUI.js');
const forEachDroppedOrPastedUrl = require('./utils/forEachDroppedOrPastedUrl');
const locale = require('./locale');
function UrlIcon() {
return h("svg", {
"aria-hidden": "true",
focusable: "false",
width: "32",
height: "32",
viewBox: "0 0 32 32"
}, h("g", {
fill: "none",
fillRule: "evenodd"
}, h("rect", {
className: "uppy-ProviderIconBg",
fill: "#FF753E",
width: "32",
height: "32",
rx: "16"
}), h("path", {
d: "M22.788 15.389l-2.199 2.19a3.184 3.184 0 0 1-.513.437c-.806.584-1.686.876-2.638.876a4.378 4.378 0 0 1-3.519-1.752c-.22-.292-.146-.802.147-1.021.293-.22.806-.146 1.026.146.953 1.313 2.785 1.532 4.105.583a.571.571 0 0 0 .293-.292l2.199-2.189c1.1-1.167 1.1-2.992-.073-4.086a2.976 2.976 0 0 0-4.105 0l-1.246 1.24a.71.71 0 0 1-1.026 0 .703.703 0 0 1 0-1.022l1.246-1.24a4.305 4.305 0 0 1 6.083 0c1.833 1.605 1.906 4.451.22 6.13zm-7.183 5.035l-1.246 1.24a2.976 2.976 0 0 1-4.105 0c-1.172-1.094-1.172-2.991-.073-4.086l2.2-2.19.292-.291c.66-.438 1.393-.657 2.2-.584.805.146 1.465.51 1.905 1.168.22.292.733.365 1.026.146.293-.22.367-.73.147-1.022-.733-.949-1.76-1.532-2.859-1.678-1.1-.22-2.272.073-3.225.802l-.44.438-2.199 2.19c-1.686 1.75-1.612 4.524.074 6.202.88.803 1.979 1.241 3.078 1.241 1.1 0 2.199-.438 3.079-1.24l1.246-1.241a.703.703 0 0 0 0-1.022c-.294-.292-.807-.365-1.1-.073z",
fill: "#FFF",
fillRule: "nonzero"
})));
}
/**
* Url
*
*/
module.exports = (_temp = _class = class Url extends UIPlugin {
constructor(uppy, opts) {
super(uppy, opts);
this.id = this.opts.id || 'Url';
this.title = this.opts.title || 'Link';
this.type = 'acquirer';
this.icon = () => h(UrlIcon, null); // Set default options and locale
this.defaultLocale = locale;
const defaultOptions = {};
this.opts = { ...defaultOptions,
...opts
};
this.i18nInit();
this.hostname = this.opts.companionUrl;
if (!this.hostname) {
throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion');
} // Bind all event handlers for referencability
this.getMeta = this.getMeta.bind(this);
this.addFile = this.addFile.bind(this);
this.handleRootDrop = this.handleRootDrop.bind(this);
this.handleRootPaste = this.handleRootPaste.bind(this);
this.client = new RequestClient(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionCookiesRule: this.opts.companionCookiesRule
});
}
getFileNameFromUrl(url) {
return url.substring(url.lastIndexOf('/') + 1);
}
checkIfCorrectURL(url) {
if (!url) return false;
const protocol = url.match(/^([a-z0-9]+):\/\//)[1];
if (protocol !== 'http' && protocol !== 'https') {
return false;
}
return true;
}
addProtocolToURL(url) {
const protocolRegex = /^[a-z0-9]+:\/\//;
const defaultProtocol = 'http://';
if (protocolRegex.test(url)) {
return url;
}
return defaultProtocol + url;
}
getMeta(url) {
return this.client.post('url/meta', {
url
}).then(res => {
if (res.error) {
this.uppy.log('[URL] Error:');
this.uppy.log(res.error);
throw new Error('Failed to fetch the file');
}
return res;
});
}
addFile(url) {
url = this.addProtocolToURL(url);
if (!this.checkIfCorrectURL(url)) {
this.uppy.log(`[URL] Incorrect URL entered: ${url}`);
this.uppy.info(this.i18n('enterCorrectUrl'), 'error', 4000);
return;
}
return this.getMeta(url).then(meta => {
const tagFile = {
source: this.id,
name: this.getFileNameFromUrl(url),
type: meta.type,
data: {
size: meta.size
},
isRemote: true,
body: {
url
},
remote: {
companionUrl: this.opts.companionUrl,
url: `${this.hostname}/url/get`,
body: {
fileId: url,
url
},
providerOptions: this.client.opts
}
};
return tagFile;
}).then(tagFile => {
this.uppy.log('[Url] Adding remote file');
try {
return this.uppy.addFile(tagFile);
} catch (err) {
if (!err.isRestriction) {
this.uppy.log(err);
}
return err;
}
}).catch(err => {
this.uppy.log(err);
this.uppy.info({
message: this.i18n('failedToFetch'),
details: err
}, 'error', 4000);
return err;
});
}
canHandleRootDrop(e) {
const items = toArray(e.dataTransfer.items);
const urls = items.filter(item => item.kind === 'string' && item.type === 'text/uri-list');
return urls.length > 0;
}
handleRootDrop(e) {
forEachDroppedOrPastedUrl(e.dataTransfer, 'drop', url => {
this.uppy.log(`[URL] Adding file from dropped url: ${url}`);
this.addFile(url);
});
}
handleRootPaste(e) {
forEachDroppedOrPastedUrl(e.clipboardData, 'paste', url => {
this.uppy.log(`[URL] Adding file from pasted url: ${url}`);
this.addFile(url);
});
}
render() {
return h(UrlUI, {
i18n: this.i18n,
addFile: this.addFile
});
}
install() {
const {
target
} = this.opts;
if (target) {
this.mount(target, this);
}
}
uninstall() {
this.unmount();
}
}, _class.VERSION = "2.0.5", _temp);
module.exports = require("./Url.js");
"use strict";
const {
h,
Component
} = require('preact');
var _preact = require("preact");
class UrlUI extends Component {
class UrlUI extends _preact.Component {
constructor(props) {

@@ -20,4 +17,8 @@ super(props);

handleKeyPress(ev) {
const {
addFile
} = this.props;
if (ev.keyCode === 13) {
this.props.addFile(this.input.value);
addFile(this.input.value);
}

@@ -27,13 +28,19 @@ }

handleClick() {
this.props.addFile(this.input.value);
const {
addFile
} = this.props;
addFile(this.input.value);
}
render() {
return h("div", {
const {
i18n
} = this.props;
return (0, _preact.h)("div", {
className: "uppy-Url"
}, h("input", {
}, (0, _preact.h)("input", {
className: "uppy-u-reset uppy-c-textInput uppy-Url-input",
type: "text",
"aria-label": this.props.i18n('enterUrlToImport'),
placeholder: this.props.i18n('enterUrlToImport'),
"aria-label": i18n('enterUrlToImport'),
placeholder: i18n('enterUrlToImport'),
onKeyUp: this.handleKeyPress,

@@ -44,7 +51,7 @@ ref: input => {

"data-uppy-super-focusable": true
}), h("button", {
}), (0, _preact.h)("button", {
className: "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Url-importButton",
type: "button",
onClick: this.handleClick
}, this.props.i18n('import')));
}, i18n('import')));
}

@@ -51,0 +58,0 @@

"use strict";
const toArray = require('@uppy/utils/lib/toArray');
const toArray = require("@uppy/utils/lib/toArray");
/*

@@ -64,3 +64,3 @@ SITUATION

module.exports = function forEachDroppedOrPastedUrl(dataTransfer, isDropOrPaste, callback) {
function forEachDroppedOrPastedUrl(dataTransfer, isDropOrPaste, callback) {
const items = toArray(dataTransfer.items);

@@ -97,2 +97,4 @@ let urlItems;

});
};
}
module.exports = forEachDroppedOrPastedUrl;
{
"name": "@uppy/url",
"description": "The Url plugin lets users import files from the Internet. Paste any URL and it’ll be added!",
"version": "2.0.5",
"version": "2.1.0",
"license": "MIT",

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

"types": "types/index.d.ts",
"type": "module",
"keywords": [

@@ -26,9 +27,9 @@ "file uploader",

"dependencies": {
"@uppy/companion-client": "^2.0.4",
"@uppy/utils": "^4.0.4",
"@uppy/companion-client": "^2.1.0",
"@uppy/utils": "^4.0.7",
"preact": "^10.5.13"
},
"peerDependencies": {
"@uppy/core": "^2.1.3"
"@uppy/core": "^2.2.0"
}
}

@@ -1,189 +0,1 @@

const { UIPlugin } = require('@uppy/core')
const { h } = require('preact')
const { RequestClient } = require('@uppy/companion-client')
const toArray = require('@uppy/utils/lib/toArray')
const UrlUI = require('./UrlUI.js')
const forEachDroppedOrPastedUrl = require('./utils/forEachDroppedOrPastedUrl')
const locale = require('./locale')
function UrlIcon () {
return (
<svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
<g fill="none" fillRule="evenodd">
<rect className="uppy-ProviderIconBg" fill="#FF753E" width="32" height="32" rx="16" />
<path d="M22.788 15.389l-2.199 2.19a3.184 3.184 0 0 1-.513.437c-.806.584-1.686.876-2.638.876a4.378 4.378 0 0 1-3.519-1.752c-.22-.292-.146-.802.147-1.021.293-.22.806-.146 1.026.146.953 1.313 2.785 1.532 4.105.583a.571.571 0 0 0 .293-.292l2.199-2.189c1.1-1.167 1.1-2.992-.073-4.086a2.976 2.976 0 0 0-4.105 0l-1.246 1.24a.71.71 0 0 1-1.026 0 .703.703 0 0 1 0-1.022l1.246-1.24a4.305 4.305 0 0 1 6.083 0c1.833 1.605 1.906 4.451.22 6.13zm-7.183 5.035l-1.246 1.24a2.976 2.976 0 0 1-4.105 0c-1.172-1.094-1.172-2.991-.073-4.086l2.2-2.19.292-.291c.66-.438 1.393-.657 2.2-.584.805.146 1.465.51 1.905 1.168.22.292.733.365 1.026.146.293-.22.367-.73.147-1.022-.733-.949-1.76-1.532-2.859-1.678-1.1-.22-2.272.073-3.225.802l-.44.438-2.199 2.19c-1.686 1.75-1.612 4.524.074 6.202.88.803 1.979 1.241 3.078 1.241 1.1 0 2.199-.438 3.079-1.24l1.246-1.241a.703.703 0 0 0 0-1.022c-.294-.292-.807-.365-1.1-.073z" fill="#FFF" fillRule="nonzero" />
</g>
</svg>
)
}
/**
* Url
*
*/
module.exports = class Url extends UIPlugin {
static VERSION = require('../package.json').version
constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'Url'
this.title = this.opts.title || 'Link'
this.type = 'acquirer'
this.icon = () => <UrlIcon />
// Set default options and locale
this.defaultLocale = locale
const defaultOptions = {}
this.opts = { ...defaultOptions, ...opts }
this.i18nInit()
this.hostname = this.opts.companionUrl
if (!this.hostname) {
throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion')
}
// Bind all event handlers for referencability
this.getMeta = this.getMeta.bind(this)
this.addFile = this.addFile.bind(this)
this.handleRootDrop = this.handleRootDrop.bind(this)
this.handleRootPaste = this.handleRootPaste.bind(this)
this.client = new RequestClient(uppy, {
companionUrl: this.opts.companionUrl,
companionHeaders: this.opts.companionHeaders,
companionCookiesRule: this.opts.companionCookiesRule,
})
}
getFileNameFromUrl (url) {
return url.substring(url.lastIndexOf('/') + 1)
}
checkIfCorrectURL (url) {
if (!url) return false
const protocol = url.match(/^([a-z0-9]+):\/\//)[1]
if (protocol !== 'http' && protocol !== 'https') {
return false
}
return true
}
addProtocolToURL (url) {
const protocolRegex = /^[a-z0-9]+:\/\//
const defaultProtocol = 'http://'
if (protocolRegex.test(url)) {
return url
}
return defaultProtocol + url
}
getMeta (url) {
return this.client.post('url/meta', { url })
.then((res) => {
if (res.error) {
this.uppy.log('[URL] Error:')
this.uppy.log(res.error)
throw new Error('Failed to fetch the file')
}
return res
})
}
addFile (url) {
url = this.addProtocolToURL(url)
if (!this.checkIfCorrectURL(url)) {
this.uppy.log(`[URL] Incorrect URL entered: ${url}`)
this.uppy.info(this.i18n('enterCorrectUrl'), 'error', 4000)
return
}
return this.getMeta(url)
.then((meta) => {
const tagFile = {
source: this.id,
name: this.getFileNameFromUrl(url),
type: meta.type,
data: {
size: meta.size,
},
isRemote: true,
body: {
url,
},
remote: {
companionUrl: this.opts.companionUrl,
url: `${this.hostname}/url/get`,
body: {
fileId: url,
url,
},
providerOptions: this.client.opts,
},
}
return tagFile
})
.then((tagFile) => {
this.uppy.log('[Url] Adding remote file')
try {
return this.uppy.addFile(tagFile)
} catch (err) {
if (!err.isRestriction) {
this.uppy.log(err)
}
return err
}
})
.catch((err) => {
this.uppy.log(err)
this.uppy.info({
message: this.i18n('failedToFetch'),
details: err,
}, 'error', 4000)
return err
})
}
canHandleRootDrop (e) {
const items = toArray(e.dataTransfer.items)
const urls = items.filter((item) => item.kind === 'string'
&& item.type === 'text/uri-list')
return urls.length > 0
}
handleRootDrop (e) {
forEachDroppedOrPastedUrl(e.dataTransfer, 'drop', (url) => {
this.uppy.log(`[URL] Adding file from dropped url: ${url}`)
this.addFile(url)
})
}
handleRootPaste (e) {
forEachDroppedOrPastedUrl(e.clipboardData, 'paste', (url) => {
this.uppy.log(`[URL] Adding file from pasted url: ${url}`)
this.addFile(url)
})
}
render () {
return <UrlUI i18n={this.i18n} addFile={this.addFile} />
}
install () {
const { target } = this.opts
if (target) {
this.mount(target, this)
}
}
uninstall () {
this.unmount()
}
}
export { default } from './Url.jsx'

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

module.exports = {
export default {
strings: {

@@ -3,0 +3,0 @@ // Label for the "Import" button.

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

const toArray = require('@uppy/utils/lib/toArray')
import toArray from '@uppy/utils/lib/toArray'

@@ -61,3 +61,3 @@ /*

*/
module.exports = function forEachDroppedOrPastedUrl (dataTransfer, isDropOrPaste, callback) {
export default function forEachDroppedOrPastedUrl (dataTransfer, isDropOrPaste, callback) {
const items = toArray(dataTransfer.items)

@@ -64,0 +64,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

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