2017-05-29 21:50:03 +03:00
|
|
|
import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
|
2020-01-16 20:01:12 +03:00
|
|
|
import RESTAdapter from '@ember-data/adapter/rest';
|
2016-05-24 15:06:59 +03:00
|
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-09-24 01:52:50 +03:00
|
|
|
import {underscore} from '@ember/string';
|
2015-11-04 18:20:11 +03:00
|
|
|
|
2021-04-12 15:21:57 +03:00
|
|
|
export default RESTAdapter.extend(AjaxServiceSupport, {
|
2014-12-26 03:01:02 +03:00
|
|
|
host: window.location.origin,
|
|
|
|
namespace: ghostPaths().apiRoot.slice(1),
|
|
|
|
|
2017-10-30 12:38:01 +03:00
|
|
|
session: service(),
|
2015-11-04 18:20:11 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
shouldBackgroundReloadRecord() {
|
2015-10-19 18:35:17 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
query(store, type, query) {
|
|
|
|
let id;
|
2014-12-26 03:01:02 +03:00
|
|
|
|
|
|
|
if (query.id) {
|
|
|
|
id = query.id;
|
|
|
|
delete query.id;
|
|
|
|
}
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
return this.ajax(this.buildURL(type.modelName, id), 'GET', {data: query});
|
2014-12-26 03:01:02 +03:00
|
|
|
},
|
|
|
|
|
2021-09-24 01:52:50 +03:00
|
|
|
pathForType() {
|
|
|
|
const type = this._super(...arguments);
|
|
|
|
return underscore(type);
|
|
|
|
},
|
|
|
|
|
2016-01-13 17:47:10 +03:00
|
|
|
buildURL() {
|
2014-12-26 03:01:02 +03:00
|
|
|
// Ensure trailing slashes
|
2016-01-13 17:47:10 +03:00
|
|
|
let url = this._super(...arguments);
|
2020-07-24 17:02:42 +03:00
|
|
|
let parsedUrl = new URL(url);
|
2014-12-26 03:01:02 +03:00
|
|
|
|
2020-07-24 17:02:42 +03:00
|
|
|
if (!parsedUrl.pathname.endsWith('/')) {
|
|
|
|
parsedUrl.pathname += '/';
|
2014-12-26 03:01:02 +03:00
|
|
|
}
|
|
|
|
|
2020-07-24 17:02:42 +03:00
|
|
|
return parsedUrl.toString();
|
2014-12-26 03:01:02 +03:00
|
|
|
}
|
|
|
|
});
|