Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 fix file uploads (#301)
Browse files Browse the repository at this point in the history
no issue
- pin `ember-ajax` on a version that contains related fixes (ember-cli/ember-ajax#147)
- update our `ajax` service so that it defaults to `application/json` content-type rather than forcing it
  • Loading branch information
kevinansfield authored and acburdine committed Oct 3, 2016
1 parent f829ad1 commit 59cc700
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/services/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import config from 'ghost-admin/config/environment';
const JSONContentType = 'application/json';

function isJSONContentType(header) {
if (isNone(header)) {
if (!header || isNone(header)) {
return false;
}
return header.indexOf(JSONContentType) === 0;
Expand Down Expand Up @@ -112,15 +112,14 @@ export function isThemeValidationError(errorOrStatus, payload) {

/* end: custom error types */

export default AjaxService.extend({
let ajaxService = AjaxService.extend({
session: injectService(),

headers: computed('session.isAuthenticated', function () {
let session = this.get('session');
let headers = {};

headers['X-Ghost-Version'] = config.APP.version;
headers['Content-Type'] = `${JSONContentType}; charset=utf-8`;

if (session.get('isAuthenticated')) {
session.authorize('authorizer:oauth2', (headerName, headerValue) => {
Expand All @@ -133,8 +132,8 @@ export default AjaxService.extend({

// ember-ajax recognises `application/vnd.api+json` as a JSON-API request
// and formats appropriately, we want to handle `application/json` the same
_makeRequest(url, hash) {
if (isJSONContentType(hash.headers['Content-Type']) && hash.type !== 'GET') {
_makeRequest(hash) {
if (isJSONContentType(hash.contentType) && hash.type !== 'GET') {
if (typeof hash.data === 'object') {
hash.data = JSON.stringify(hash.data);
}
Expand Down Expand Up @@ -213,3 +212,10 @@ export default AjaxService.extend({
return isThemeValidationError(status, payload);
}
});

// we need to reopen so that internal methods use the correct contentType
ajaxService.reopen({
contentType: 'application/json; charset=UTF-8'
});

export default ajaxService;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"chalk": "1.1.3",
"codemirror": "5.18.2",
"csscomb": "3.1.8",
"ember-ajax": "2.5.1",
"ember-ajax": "ember-cli/ember-ajax#b32b9ee5ede69e09a162eb98d354f7de6297f679",
"ember-cli": "2.7.0",
"ember-cli-app-version": "2.0.0",
"ember-cli-babel": "5.1.10",
Expand Down

0 comments on commit 59cc700

Please sign in to comment.