-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import from url #588
Merged
Merged
Import from url #588
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1596cf8
implement basic Import from URL
arturi 56fdc72
fetch meta
arturi 4b68223
Merge master into feature/import-from-url
arturi 24afc57
Implement getMeta and addFile
arturi ac43a6a
Add styles
arturi ed2406e
don’t use opacity for file source icons, it cuts a tiny piece off of …
arturi 4c18bf1
rename to Url
arturi 18583c3
Add docs for Url
arturi 53ccf3e
Focus on input first, add locale strings, text instead of icon on the…
arturi 4a833de
remove tape, update package-lock.json
arturi ce1e13d
Merge branch 'master' into feature/import-from-url
arturi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { h, Component } = require('preact') | ||
|
||
class UrlUI extends Component { | ||
constructor (props) { | ||
super(props) | ||
this.handleClick = this.handleClick.bind(this) | ||
} | ||
|
||
componentDidMount () { | ||
this.input.focus() | ||
} | ||
|
||
handleClick () { | ||
this.props.addFile(this.input.value) | ||
} | ||
|
||
render () { | ||
return <div class="uppy-Url"> | ||
<input | ||
class="uppy-Url-input" | ||
type="text" | ||
placeholder={this.props.i18n('enterUrlToImport')} | ||
ref={(input) => { this.input = input }} | ||
value="" /> | ||
<button | ||
class="uppy-Url-importButton" | ||
type="button" | ||
aria-label={this.props.i18n('addUrl')} | ||
onclick={this.handleClick}> | ||
{this.props.i18n('import')} | ||
</button> | ||
</div> | ||
} | ||
} | ||
|
||
module.exports = UrlUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
const Plugin = require('../../core/Plugin') | ||
const Translator = require('../../core/Translator') | ||
const { h } = require('preact') | ||
const Provider = require('../Provider') | ||
const UrlUI = require('./UrlUI.js') | ||
// const Utils = require('../../core/Utils') | ||
require('whatwg-fetch') | ||
|
||
/** | ||
* Link | ||
* | ||
*/ | ||
module.exports = class Link extends Plugin { | ||
constructor (uppy, opts) { | ||
super(uppy, opts) | ||
this.id = this.opts.id || 'Url' | ||
this.title = 'Url' | ||
this.type = 'acquirer' | ||
this.icon = () => <svg aria-hidden="true" class="UppyIcon UppyModalTab-icon" width="64" height="64" viewBox="0 0 64 64"> | ||
<circle cx="32" cy="32" r="31" /> | ||
<g fill-rule="nonzero" fill="#FFF"> | ||
<path d="M25.774 47.357a4.077 4.077 0 0 1-5.76 0L16.9 44.24a4.076 4.076 0 0 1 0-5.758l5.12-5.12-1.817-1.818-5.12 5.122a6.651 6.651 0 0 0 0 9.392l3.113 3.116a6.626 6.626 0 0 0 4.699 1.943c1.7 0 3.401-.649 4.697-1.943l10.241-10.243a6.591 6.591 0 0 0 1.947-4.696 6.599 6.599 0 0 0-1.947-4.696l-3.116-3.114-1.817 1.817 3.116 3.114a4.045 4.045 0 0 1 1.194 2.88 4.045 4.045 0 0 1-1.194 2.878L25.774 47.357z" /> | ||
<path d="M46.216 14.926a6.597 6.597 0 0 0-4.696-1.946h-.001a6.599 6.599 0 0 0-4.696 1.945L26.582 25.167a6.595 6.595 0 0 0-1.947 4.697 6.599 6.599 0 0 0 1.946 4.698l3.114 3.114 1.818-1.816-3.114-3.114a4.05 4.05 0 0 1-1.194-2.882c0-1.086.424-2.108 1.194-2.878L38.64 16.744a4.042 4.042 0 0 1 2.88-1.194c1.089 0 2.11.425 2.88 1.194l3.114 3.114a4.076 4.076 0 0 1 0 5.758l-5.12 5.12 1.818 1.817 5.12-5.122a6.649 6.649 0 0 0 0-9.393l-3.113-3.114-.003.002z" /> | ||
</g> | ||
</svg> | ||
|
||
// Set default options and locale | ||
const defaultLocale = { | ||
strings: { | ||
addUrl: 'Add url', | ||
import: 'Import', | ||
enterUrlToImport: 'Enter file url to import' | ||
} | ||
} | ||
|
||
const defaultOptions = { | ||
locale: defaultLocale | ||
} | ||
|
||
this.opts = Object.assign({}, defaultOptions, opts) | ||
|
||
this.locale = Object.assign({}, defaultLocale, this.opts.locale) | ||
this.locale.strings = Object.assign({}, defaultLocale.strings, this.opts.locale.strings) | ||
|
||
this.translator = new Translator({locale: this.locale}) | ||
this.i18n = this.translator.translate.bind(this.translator) | ||
|
||
this.hostname = this.opts.host | ||
|
||
// Bind all event handlers for referencability | ||
this.getMeta = this.getMeta.bind(this) | ||
this.addFile = this.addFile.bind(this) | ||
|
||
this[this.id] = new Provider(uppy, { | ||
host: this.opts.host, | ||
provider: 'url', | ||
authProvider: 'url' | ||
}) | ||
} | ||
|
||
getMeta (url) { | ||
return fetch(`${this.hostname}/url/meta`, { | ||
method: 'post', | ||
credentials: 'include', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
url: url | ||
}) | ||
}) | ||
.then(this[this.id].onReceiveResponse) | ||
.then((res) => res.json()) | ||
} | ||
|
||
getFileNameFromUrl (url) { | ||
return url.substring(url.lastIndexOf('/') + 1) | ||
} | ||
|
||
addFile (url) { | ||
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: url | ||
}, | ||
remote: { | ||
host: this.opts.host, | ||
url: `${this.hostname}/url/get`, | ||
body: { | ||
fileId: url, | ||
url: url | ||
} | ||
} | ||
} | ||
|
||
this.uppy.log('[Url] Adding remote file') | ||
this.uppy.addFile(tagFile) | ||
.then(() => { | ||
const dashboard = this.uppy.getPlugin('Dashboard') | ||
if (dashboard) dashboard.hideAllPanels() | ||
}) | ||
}) | ||
} | ||
|
||
render (state) { | ||
return <UrlUI | ||
i18n={this.i18n} | ||
addFile={this.addFile} /> | ||
} | ||
|
||
install () { | ||
const target = this.opts.target | ||
if (target) { | ||
this.mount(target, this) | ||
} | ||
} | ||
|
||
uninstall () { | ||
this.unmount() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.uppy-Url { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.uppy-Url-input { | ||
width: 80%; | ||
height: 50px; | ||
padding-left: 10px; | ||
font-size: 15px; | ||
border: 1px solid rgba($color-gray, 0.5); | ||
border-right: 0; | ||
} | ||
|
||
.uppy-Url-importButton { | ||
@include reset-button(); | ||
width: 100px; | ||
height: 50px; | ||
color: $color-white; | ||
background-color: $color-cornflower-blue; | ||
cursor: pointer; | ||
padding: 12px; | ||
} | ||
|
||
// .uppy-Url-importButton-icon { | ||
// width: 100%; | ||
// height: 100%; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on my suggestion 2. and 3. above, we can have this
fetch
done inApiCalls