mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Trigger a background download request when Unsplash images are inserted
no issue - update to match Unsplash's new API guidelines https://medium.com/unsplash/unsplash-api-guidelines-triggering-a-download-c39b24e99e02
This commit is contained in:
parent
c00232ca92
commit
78c34830cd
@ -57,6 +57,7 @@ export default Component.extend(ShortcutsMixin, {
|
||||
},
|
||||
|
||||
insert(photo) {
|
||||
this.get('unsplash').triggerDownload(photo);
|
||||
this.insert(photo);
|
||||
this.close();
|
||||
},
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Service, {inject as service} from '@ember/service';
|
||||
import fetch from 'fetch';
|
||||
import {assign} from '@ember/polyfills';
|
||||
import {isEmpty} from '@ember/utils';
|
||||
import {or} from '@ember/object/computed';
|
||||
import {reject, resolve} from 'rsvp';
|
||||
@ -64,6 +65,14 @@ export default Service.extend({
|
||||
}
|
||||
},
|
||||
|
||||
// let Unsplash know that the photo was inserted
|
||||
// https://medium.com/unsplash/unsplash-api-guidelines-triggering-a-download-c39b24e99e02
|
||||
triggerDownload(photo) {
|
||||
if (photo.links.download_location) {
|
||||
this._makeRequest(photo.links.download_location, {ignoreErrors: true});
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
updateSearch(term) {
|
||||
if (term === this.get('searchTerm')) {
|
||||
@ -156,8 +165,12 @@ export default Service.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_makeRequest(url) {
|
||||
_makeRequest(url, _options = {}) {
|
||||
let defaultOptions = {ignoreErrors: false};
|
||||
let headers = {};
|
||||
let options = {};
|
||||
|
||||
assign(options, defaultOptions, _options);
|
||||
|
||||
// clear any previous error
|
||||
this.set('error', '');
|
||||
@ -177,7 +190,7 @@ export default Service.extend({
|
||||
.then((response) => this._addPhotosFromResponse(response))
|
||||
.catch(() => {
|
||||
// if the error text isn't already set then we've get a connection error from `fetch`
|
||||
if (!this.get('error')) {
|
||||
if (!options.ignoreErrors && !this.get('error')) {
|
||||
this.set('error', 'Uh-oh! Trouble reaching the Unsplash API, please check your connection');
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user