diff --git a/app/adapters/application.js b/app/adapters/application.js index bef90047c7..6858d92982 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -1,5 +1,6 @@ import DS from 'ember-data'; +import AdapterFetch from 'ember-fetch/mixins/adapter-fetch'; -export default DS.RESTAdapter.extend({ +export default DS.RESTAdapter.extend(AdapterFetch, { namespace: 'api/v1', }); diff --git a/app/components/email-input.js b/app/components/email-input.js index 027f6d7450..78d2a98eae 100644 --- a/app/components/email-input.js +++ b/app/components/email-input.js @@ -2,9 +2,9 @@ import Component from '@ember/component'; import { empty } from '@ember/object/computed'; import { computed } from '@ember/object'; import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; export default Component.extend({ - ajax: service(), flashMessages: service(), type: '', @@ -96,7 +96,7 @@ export default Component.extend({ let user = this.get('user'); try { - await this.get('ajax').raw(`/api/v1/users/${user.id}/resend`, { method: 'PUT' }); + await ajax(`/api/v1/users/${user.id}/resend`, { method: 'PUT' }); this.set('disableResend', true); } catch(error) { if (error.payload) { diff --git a/app/controllers/dashboard.js b/app/controllers/dashboard.js index f3b5f8e01c..8f2e76bea7 100644 --- a/app/controllers/dashboard.js +++ b/app/controllers/dashboard.js @@ -1,14 +1,11 @@ import Controller from '@ember/controller'; import { A } from '@ember/array'; import { computed } from '@ember/object'; -import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; const TO_SHOW = 5; export default Controller.extend({ - - ajax: service(), - init() { this._super(...arguments); @@ -46,8 +43,7 @@ export default Controller.extend({ let page = (this.get('myFeed').length / 10) + 1; try { - let data = await this.get('ajax').request(`/api/v1/me/updates?page=${page}`); - + let data = await ajax(`/api/v1/me/updates?page=${page}`); let versions = data.versions.map(version => this.store.push(this.store.normalize('version', version))); this.get('myFeed').pushObjects(versions); diff --git a/app/controllers/index.js b/app/controllers/index.js index 4c8f3780fd..42e8c9cd43 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -1,13 +1,11 @@ import Controller from '@ember/controller'; import { computed } from '@ember/object'; import { readOnly } from '@ember/object/computed'; -import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; import { task } from 'ember-concurrency'; export default Controller.extend({ - ajax: service(), - model: readOnly('dataTask.lastSuccessful.value'), hasData: computed('dataTask.{lastSuccessful,isRunning}', function() { @@ -15,7 +13,7 @@ export default Controller.extend({ }), dataTask: task(function* () { - let data = yield this.get('ajax').request('/api/v1/summary'); + let data = yield ajax('/api/v1/summary'); addCrates(this.store, data.new_crates); addCrates(this.store, data.most_downloaded); diff --git a/app/controllers/me/index.js b/app/controllers/me/index.js index 9ba3f5f123..9a113bb787 100644 --- a/app/controllers/me/index.js +++ b/app/controllers/me/index.js @@ -8,8 +8,6 @@ export default Controller.extend({ sortedTokens: sort('model.api_tokens', 'tokenSort'), - ajax: service(), - flashMessages: service(), isResetting: false, diff --git a/app/routes/confirm.js b/app/routes/confirm.js index 126adcc224..0e4113e35c 100644 --- a/app/routes/confirm.js +++ b/app/routes/confirm.js @@ -1,14 +1,14 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; export default Route.extend({ flashMessages: service(), - ajax: service(), session: service(), async model(params) { try { - await this.get('ajax').raw(`/api/v1/confirm/${params.email_token}`, { method: 'PUT', data: {} }); + await ajax(`/api/v1/confirm/${params.email_token}`, { method: 'PUT', body: '{}' }); /* We need this block to reload the user model from the database, without which if we haven't submitted another GET /me after @@ -21,7 +21,7 @@ export default Route.extend({ Suggestions of a more ideomatic way to fix/test this are welcome! */ if (this.get('session.isLoggedIn')) { - this.get('ajax').request('/api/v1/me').then((response) => { + ajax('/api/v1/me').then((response) => { this.get('session').set('currentUser', this.store.push(this.store.normalize('user', response.user))); }); } diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 830534ffa9..a2492d3acc 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -2,8 +2,10 @@ import { observer } from '@ember/object'; import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import fetch from 'fetch'; +import ajax from 'ember-fetch/ajax'; + export default Route.extend({ - ajax: service(), session: service(), flashMessages: service(), @@ -45,7 +47,7 @@ export default Route.extend({ crate.get('documentation').substr(0, 16) === 'https://docs.rs/') { let crateName = crate.get('name'); let crateVersion = params.version_num; - this.get('ajax').request(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`) + ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`, { mode: 'cors' }) .then((r) => { if (r.length > 0 && r[0].build_status === true) { crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`); @@ -85,7 +87,7 @@ export default Route.extend({ controller.set('fetchingFollowing', true); if (this.get('session.currentUser')) { - this.get('ajax').request(`/api/v1/crates/${crate.get('name')}/following`) + ajax(`/api/v1/crates/${crate.get('name')}/following`) .then((d) => controller.set('following', d.following)) .finally(() => controller.set('fetchingFollowing', false)); } @@ -104,18 +106,13 @@ export default Route.extend({ versions.objectAt(0); if (result.get('readme_path')) { - this.get('ajax').request(result.get('readme_path')) - .then((r) => this.get('ajax').raw(r.url, { - method: 'GET', - dataType: 'html', - headers: { - // We need to force the Accept header, otherwise crates.io won't return - // the readme file when not using S3. - Accept: '*/*', - }, - })) - .then((r) => { - crate.set('readme', r.payload); + fetch(result.get('readme_path')) + .then(async (r) => { + if (r.ok) { + crate.set('readme', await r.text()); + } else { + crate.set('readme', null); + } }) .catch(() => { crate.set('readme', null); diff --git a/app/routes/github-authorize.js b/app/routes/github-authorize.js index 500c9becd7..2fd1914c93 100644 --- a/app/routes/github-authorize.js +++ b/app/routes/github-authorize.js @@ -1,5 +1,6 @@ import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; +import { serializeQueryParams } from 'ember-fetch/mixins/adapter-fetch'; /** * This route will be called from the GitHub OAuth flow once the user has @@ -15,12 +16,10 @@ import { inject as service } from '@ember/service'; * @see `/login` route */ export default Route.extend({ - - ajax: service(), - async beforeModel(transition) { try { - let d = await this.get('ajax').request(`/authorize`, { data: transition.queryParams }); + let queryParams = serializeQueryParams(transition.queryParams); + let d = await ajax(`/authorize?${queryParams}`); let item = JSON.stringify({ ok: true, data: d }); if (window.opener) { window.opener.github_response = item; diff --git a/app/routes/github-login.js b/app/routes/github-login.js index a33210dc45..8386a59318 100644 --- a/app/routes/github-login.js +++ b/app/routes/github-login.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; /** * Calling this route will query the `/authorize_url` API endpoint @@ -15,11 +15,8 @@ import { inject as service } from '@ember/service'; * @see `github-authorize` route */ export default Route.extend({ - - ajax: service(), - async beforeModel() { - let url = await this.get('ajax').request(`/authorize_url`); + let url = await ajax(`/authorize_url`); window.location = url.url; }, }); diff --git a/app/routes/logout.js b/app/routes/logout.js index 01e138494e..41122b7959 100644 --- a/app/routes/logout.js +++ b/app/routes/logout.js @@ -1,13 +1,13 @@ import { run } from '@ember/runloop'; import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; export default Route.extend({ - ajax: service(), session: service(), async activate() { - await this.get('ajax').delete(`/logout`); + await ajax(`/logout`, { method: 'DELETE' }); run(() => { this.get('session').logoutUser(); this.transitionTo('index'); diff --git a/app/services/session.js b/app/services/session.js index 27fed4b126..cb017916ca 100644 --- a/app/services/session.js +++ b/app/services/session.js @@ -1,4 +1,5 @@ import Service, { inject as service } from '@ember/service'; +import ajax from 'ember-fetch/ajax'; export default Service.extend({ savedTransition: null, @@ -7,7 +8,6 @@ export default Service.extend({ currentUser: null, currentUserDetected: false, - ajax: service(), store: service(), router: service(), @@ -64,7 +64,7 @@ export default Service.extend({ }, fetchUser() { - return this.get('ajax').request('/api/v1/me') + return ajax('/api/v1/me') .then((response) => { this.set('currentUser', this.get('store').push(this.get('store').normalize('user', response.user))); }); diff --git a/package-lock.json b/package-lock.json index fa94ffb5e4..f09985b80f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2595,6 +2595,95 @@ } } }, + "broccoli-templater": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/broccoli-templater/-/broccoli-templater-1.0.0.tgz", + "integrity": "sha1-fAVKrPWW0YaNGkQpH57HuQfTDs8=", + "dev": true, + "requires": { + "broccoli-filter": "0.1.14", + "broccoli-stew": "1.5.0", + "lodash.template": "3.6.2" + }, + "dependencies": { + "broccoli-filter": { + "version": "0.1.14", + "resolved": "https://registry.npmjs.org/broccoli-filter/-/broccoli-filter-0.1.14.tgz", + "integrity": "sha1-I8rjiR/567e019sAxtzwNTXa960=", + "dev": true, + "requires": { + "broccoli-kitchen-sink-helpers": "0.2.9", + "broccoli-writer": "0.1.1", + "mkdirp": "0.3.5", + "promise-map-series": "0.2.3", + "quick-temp": "0.1.8", + "rsvp": "3.6.1", + "symlink-or-copy": "1.1.8", + "walk-sync": "0.1.3" + } + }, + "broccoli-kitchen-sink-helpers": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/broccoli-kitchen-sink-helpers/-/broccoli-kitchen-sink-helpers-0.2.9.tgz", + "integrity": "sha1-peCYbtjXb7WYS2jD8EUNOpbjbsw=", + "dev": true, + "requires": { + "glob": "5.0.15", + "mkdirp": "0.5.1" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + } + } + }, + "lodash.template": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-3.6.2.tgz", + "integrity": "sha1-+M3sxhaaJVvpCYrosMU9N4kx0U8=", + "dev": true, + "requires": { + "lodash._basecopy": "3.0.1", + "lodash._basetostring": "3.0.1", + "lodash._basevalues": "3.0.0", + "lodash._isiterateecall": "3.0.9", + "lodash._reinterpolate": "3.0.0", + "lodash.escape": "3.2.0", + "lodash.keys": "3.1.2", + "lodash.restparam": "3.6.1", + "lodash.templatesettings": "3.1.1" + } + }, + "lodash.templatesettings": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-3.1.1.tgz", + "integrity": "sha1-+zB4RHU7Zrnxr6VOJix0UwfbqOU=", + "dev": true, + "requires": { + "lodash._reinterpolate": "3.0.0", + "lodash.escape": "3.2.0" + } + }, + "mkdirp": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", + "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", + "dev": true + }, + "walk-sync": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/walk-sync/-/walk-sync-0.1.3.tgz", + "integrity": "sha1-igcmGgC9ps+xviXp8QD61XVG9YM=", + "dev": true + } + } + }, "broccoli-unwatched-tree": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/broccoli-unwatched-tree/-/broccoli-unwatched-tree-0.1.3.tgz", @@ -3888,15 +3977,6 @@ } } }, - "ember-ajax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ember-ajax/-/ember-ajax-3.0.0.tgz", - "integrity": "sha1-jyHp2gwdQzz4eaqFX85GTVF+mrU=", - "dev": true, - "requires": { - "ember-cli-babel": "6.8.2" - } - }, "ember-app-scheduler": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/ember-app-scheduler/-/ember-app-scheduler-0.2.1.tgz", @@ -5480,6 +5560,28 @@ "ember-cli-babel": "6.8.2" } }, + "ember-fetch": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/ember-fetch/-/ember-fetch-3.4.4.tgz", + "integrity": "sha512-N81LZl/NEaQiK4KnLHuibrIZ7goxuIarrQ+A6ZBE/aQCI2x23IISL/YgX0U4bL2F+9I6Kg9ZO2gI+4tszGQSEQ==", + "dev": true, + "requires": { + "broccoli-funnel": "1.2.0", + "broccoli-stew": "1.5.0", + "broccoli-templater": "1.0.0", + "ember-cli-babel": "6.8.2", + "node-fetch": "2.1.2", + "whatwg-fetch": "2.0.3" + }, + "dependencies": { + "node-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=", + "dev": true + } + } + }, "ember-get-config": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/ember-get-config/-/ember-get-config-0.2.4.tgz", @@ -10108,6 +10210,18 @@ "lodash.isarray": "3.0.4" } }, + "lodash._basetostring": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz", + "integrity": "sha1-0YYdh3+CSlL2aYMtyvPuFVZqB9U=", + "dev": true + }, + "lodash._basevalues": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/lodash._basevalues/-/lodash._basevalues-3.0.0.tgz", + "integrity": "sha1-W3dXYoAr3j0yl1A+JjAIIP32Ybc=", + "dev": true + }, "lodash._bindcallback": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz", @@ -10143,6 +10257,12 @@ "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=", "dev": true }, + "lodash._root": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz", + "integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=", + "dev": true + }, "lodash.assign": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-3.2.0.tgz", @@ -10187,6 +10307,15 @@ "integrity": "sha1-vsECT4WxvZbL6kBbI8FK1kQ6b4E=", "dev": true }, + "lodash.escape": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-3.2.0.tgz", + "integrity": "sha1-mV7g3BjBtIzJLv+ucaEKq1tIdpg=", + "dev": true, + "requires": { + "lodash._root": "3.0.1" + } + }, "lodash.find": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz", @@ -14776,6 +14905,12 @@ "integrity": "sha1-domUmcGEtu91Q3fC27DNbLVdKec=", "dev": true }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=", + "dev": true + }, "whatwg-url-compat": { "version": "0.6.5", "resolved": "https://registry.npmjs.org/whatwg-url-compat/-/whatwg-url-compat-0.6.5.tgz", diff --git a/package.json b/package.json index cd0f376217..525d17d143 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "babel-plugin-transform-object-rest-spread": "^6.23.0", "broccoli-asset-rev": "2.5.0", "ember-a11y-testing": "^0.5.0", - "ember-ajax": "^3.0.0", "ember-cli": "~2.17.0", "ember-cli-app-version": "^3.1.3", "ember-cli-babel": "^6.8.2", @@ -53,6 +52,7 @@ "ember-disable-prototype-extensions": "^1.1.3", "ember-exam": "^1.0.0", "ember-export-application-global": "^2.0.0", + "ember-fetch": "^3.4.3", "ember-keyboard": "^3.0.2", "ember-load-initializers": "^1.0.0", "ember-maybe-import-regenerator": "^0.1.6",