Comparing version 3.5.0 to 3.6.0
# @uppy/url | ||
## 3.6.0 | ||
Released: 2024-03-27 | ||
Included in: Uppy v3.24.0 | ||
- @uppy/url: migrate to TS (Merlijn Vos / #4980) | ||
## 3.1.0 | ||
@@ -4,0 +11,0 @@ |
190
lib/Url.js
@@ -0,1 +1,2 @@ | ||
var _class; | ||
import { h } from 'preact'; | ||
@@ -6,7 +7,10 @@ import { UIPlugin } from '@uppy/core'; | ||
import UrlUI from "./UrlUI.js"; | ||
import forEachDroppedOrPastedUrl from './utils/forEachDroppedOrPastedUrl.js'; | ||
import forEachDroppedOrPastedUrl from "./utils/forEachDroppedOrPastedUrl.js"; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore We don't want TS to generate types for the package.json | ||
const packageJson = { | ||
"version": "3.5.0" | ||
"version": "3.6.0" | ||
}; | ||
import locale from './locale.js'; | ||
import locale from "./locale.js"; | ||
function UrlIcon() { | ||
@@ -39,8 +43,3 @@ return h("svg", { | ||
function checkIfCorrectURL(url) { | ||
if (!url) return false; | ||
const protocol = url.match(/^([a-z0-9]+):\/\//)[1]; | ||
if (protocol !== 'http' && protocol !== 'https') { | ||
return false; | ||
} | ||
return true; | ||
return (url == null ? void 0 : url.startsWith('http://')) || (url == null ? void 0 : url.startsWith('https://')); | ||
} | ||
@@ -54,9 +53,84 @@ function getFileNameFromUrl(url) { | ||
/** | ||
* Url | ||
* | ||
/* | ||
* Response from the /url/meta Companion endpoint. | ||
* Has to be kept in sync with `getURLMeta` in `companion/src/server/helpers/request.js`. | ||
*/ | ||
export default class Url extends UIPlugin { | ||
constructor(uppy, opts) { | ||
super(uppy, opts); | ||
this.getMeta = url => { | ||
return this.client.post('url/meta', { | ||
url | ||
}).then(res => { | ||
// TODO: remove this handler in the next major | ||
if (res.error) { | ||
this.uppy.log('[URL] Error:'); | ||
this.uppy.log(res.error); | ||
throw new Error('Failed to fetch the file'); | ||
} | ||
return res; | ||
}); | ||
}; | ||
this.addFile = async (protocollessUrl, optionalMeta) => { | ||
const url = addProtocolToURL(protocollessUrl); | ||
if (!checkIfCorrectURL(url)) { | ||
this.uppy.log(`[URL] Incorrect URL entered: ${url}`); | ||
this.uppy.info(this.i18n('enterCorrectUrl'), 'error', 4000); | ||
return undefined; | ||
} | ||
try { | ||
const meta = await this.getMeta(url); | ||
const tagFile = { | ||
meta: optionalMeta, | ||
source: this.id, | ||
name: meta.name || 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 | ||
}, | ||
requestClientId: Url.requestClientId | ||
} | ||
}; | ||
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; | ||
} | ||
}; | ||
this.handleRootDrop = e => { | ||
forEachDroppedOrPastedUrl(e.dataTransfer, 'drop', url => { | ||
this.uppy.log(`[URL] Adding file from dropped url: ${url}`); | ||
this.addFile(url); | ||
}); | ||
}; | ||
this.handleRootPaste = e => { | ||
forEachDroppedOrPastedUrl(e.clipboardData, 'paste', url => { | ||
this.uppy.log(`[URL] Adding file from pasted url: ${url}`); | ||
this.addFile(url); | ||
}); | ||
}; | ||
this.id = this.opts.id || 'Url'; | ||
@@ -69,7 +143,2 @@ this.title = this.opts.title || 'Link'; | ||
this.defaultLocale = locale; | ||
const defaultOptions = {}; | ||
this.opts = { | ||
...defaultOptions, | ||
...opts | ||
}; | ||
this.i18nInit(); | ||
@@ -80,9 +149,5 @@ this.hostname = this.opts.companionUrl; | ||
} | ||
// 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, { | ||
pluginId: this.id, | ||
provider: 'url', | ||
companionUrl: this.opts.companionUrl, | ||
@@ -94,78 +159,2 @@ companionHeaders: this.opts.companionHeaders, | ||
} | ||
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; | ||
}); | ||
} | ||
async addFile(protocollessUrl, optionalMeta) { | ||
if (optionalMeta === void 0) { | ||
optionalMeta = undefined; | ||
} | ||
const url = addProtocolToURL(protocollessUrl); | ||
if (!checkIfCorrectURL(url)) { | ||
this.uppy.log(`[URL] Incorrect URL entered: ${url}`); | ||
this.uppy.info(this.i18n('enterCorrectUrl'), 'error', 4000); | ||
return undefined; | ||
} | ||
try { | ||
const meta = await this.getMeta(url); | ||
const tagFile = { | ||
meta: optionalMeta, | ||
source: this.id, | ||
name: meta.name || 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 | ||
}, | ||
requestClientId: Url.requestClientId | ||
} | ||
}; | ||
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; | ||
} | ||
} | ||
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() { | ||
@@ -192,4 +181,5 @@ return h(UrlUI, { | ||
// we still want it available on the prototype so the Dashboard can access it. | ||
_class = Url; | ||
Url.VERSION = packageJson.version; | ||
Url.requestClientId = Url.name; | ||
Url.requestClientId = _class.name; | ||
Url.prototype.canHandleRootDrop = canHandleRootDrop; |
@@ -56,6 +56,2 @@ import toArray from '@uppy/utils/lib/toArray'; | ||
* Finds all links dropped/pasted from one browser window to another. | ||
* | ||
* @param {object} dataTransfer - DataTransfer instance, e.g. e.clipboardData, or e.dataTransfer | ||
* @param {string} isDropOrPaste - either 'drop' or 'paste' | ||
* @param {Function} callback - (urlString) => {} | ||
*/ | ||
@@ -62,0 +58,0 @@ export default function forEachDroppedOrPastedUrl(dataTransfer, isDropOrPaste, callback) { |
{ | ||
"name": "@uppy/url", | ||
"description": "The Url plugin lets users import files from the Internet. Paste any URL and it’ll be added!", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"license": "MIT", | ||
@@ -26,4 +26,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/companion-client": "^3.7.0", | ||
"@uppy/utils": "^5.7.0", | ||
"@uppy/companion-client": "^3.8.0", | ||
"@uppy/utils": "^5.7.5", | ||
"nanoid": "^4.0.0", | ||
@@ -33,4 +33,4 @@ "preact": "^10.5.13" | ||
"peerDependencies": { | ||
"@uppy/core": "^3.8.0" | ||
"@uppy/core": "^3.10.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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54706
737
2
Updated@uppy/utils@^5.7.5