Example #1
0
    describe('join', function () {
        let {join} = ghostPaths().url;

        it('should join two or more paths, normalizing slashes', function () {
            let path;

            path = join('/one/', '/two/');
            expect(path).to.equal('/one/two/');

            path = join('/one', '/two/');
            expect(path).to.equal('/one/two/');

            path = join('/one/', 'two/');
            expect(path).to.equal('/one/two/');

            path = join('/one/', 'two/', '/three/');
            expect(path).to.equal('/one/two/three/');

            path = join('/one/', 'two', 'three/');
            expect(path).to.equal('/one/two/three/');
        });

        it('should not change the slash at the beginning', function () {
            let path;

            path = join('one/');
            expect(path).to.equal('one/');
            path = join('one/', 'two');
            expect(path).to.equal('one/two/');
            path = join('/one/', 'two');
            expect(path).to.equal('/one/two/');
            path = join('one/', 'two', 'three');
            expect(path).to.equal('one/two/three/');
            path = join('/one/', 'two', 'three');
            expect(path).to.equal('/one/two/three/');
        });

        it('should always return a slash at the end', function () {
            let path;

            path = join();
            expect(path).to.equal('/');
            path = join('');
            expect(path).to.equal('/');
            path = join('one');
            expect(path).to.equal('one/');
            path = join('one/');
            expect(path).to.equal('one/');
            path = join('one', 'two');
            expect(path).to.equal('one/two/');
            path = join('one', 'two/');
            expect(path).to.equal('one/two/');
        });
    });
 uploadUrl: computed(function () {
     return `${ghostPaths().apiRoot}/subscribers/csv/`;
 }),
        } else if (error.errors && !isBlank(error.errors[0].message)) {
            message = error.errors[0].message;
        } else {
            message = 'Something went wrong :(';
        }

        this.set('failureMessage', message);
        invokeAction(this, 'uploadFailed', error);
    },

    generateRequest() {
        let ajax = this.get('ajax');
        let formData = this.get('formData');
        let uploadUrl = this.get('uploadUrl');
        // CASE: we want to upload an icon and we have to POST it to a different endpoint, expecially for icons
        let url = `${ghostPaths().apiRoot}${uploadUrl}`;

        this._uploadStarted();

        ajax.post(url, {
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'text',
            xhr: () => {
                let xhr = new window.XMLHttpRequest();

                xhr.upload.addEventListener('progress', (event) => {
                    this._uploadProgress(event);
                }, false);
Example #4
0
    name:    'ghost-oauth2',
    baseUrl: computed(function () {
        return `${this.get('config.ghostAuthUrl')}/oauth2/authorize/`;
    }),
    apiKey: computed(function () {
        return this.get('config.ghostAuthId');
    }),

    optionalUrlParams: ['type', 'email'],

    responseParams: ['code'],

    // we want to redirect to the ghost admin app by default
    init() {
        this._super(...arguments);
        let adminPath = ghostPaths().adminRoot;
        let redirectUri = `${window.location.protocol}//${window.location.host}`;

        redirectUri += adminPath;

        this.set('redirectUri', redirectUri);
    },

    open(options) {
        if (options.type) {
            this.set('type', options.type);
        }
        if (options.email) {
            this.set('email', options.email);
        }
        return this._super(...arguments);
Example #5
0
    _uploadFile: task(function* (tracker, file, index) {
        let ajax = this.ajax;
        let formData = this._getFormData(file);
        let url = `${ghostPaths().apiRoot}${this.uploadUrl}`;

        try {
            this.onUploadStart(file);

            let response = yield ajax.post(url, {
                data: formData,
                processData: false,
                contentType: false,
                dataType: 'text',
                xhr: () => {
                    let xhr = new window.XMLHttpRequest();

                    xhr.upload.addEventListener('progress', (event) => {
                        run(() => {
                            tracker.update(event);
                            this._updateProgress();
                        });
                    }, false);

                    return xhr;
                }
            });

            // force tracker progress to 100% in case we didn't get a final event,
            // eg. when using mirage
            tracker.update({loaded: file.size, total: file.size});
            this._updateProgress();

            let uploadResponse;
            let responseUrl;

            try {
                uploadResponse = JSON.parse(response);
            } catch (e) {
                if (!(e instanceof SyntaxError)) {
                    throw e;
                }
            }

            if (uploadResponse) {
                let resource = get(uploadResponse, this.resourceName);
                if (resource && isArray(resource) && resource[0]) {
                    responseUrl = get(resource[0], 'url');
                }
            }

            let result = {
                url: responseUrl,
                fileName: file.name
            };

            this.uploadUrls[index] = result;
            this.onUploadSuccess(result);

            return true;
        } catch (error) {
            // grab custom error message if present
            let message = error.payload.errors && error.payload.errors[0].message || '';
            let context = error.payload.errors && error.payload.errors[0].context || '';

            // fall back to EmberData/ember-ajax default message for error type
            if (!message) {
                message = error.message;
            }

            let result = {
                message,
                context,
                fileName: file.name
            };

            // TODO: check for or expose known error types?
            this.errors.pushObject(result);
            this.onUploadFailure(result);
        }
    }).maxConcurrency(MAX_SIMULTANEOUS_UPLOADS).enqueue(),
 uploadUrl: computed(function () {
     return `${ghostPaths().apiRoot}/themes/upload/`;
 }),
Example #7
0
import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import RESTAdapter from 'ember-data/adapters/rest';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {inject as service} from '@ember/service';

export default RESTAdapter.extend(DataAdapterMixin, AjaxServiceSupport, {
    host: window.location.origin,
    namespace: ghostPaths().apiRoot.slice(1),

    session: service(),

    shouldBackgroundReloadRecord() {
        return false;
    },

    /* eslint-disable camelcase */
    authorize(xhr) {
        if (this.get('session.isAuthenticated')) {
            let {access_token} = this.get('session.data.authenticated');
            xhr.setRequestHeader('Authorization', `Bearer ${access_token}`);
        }
    },
    /* eslint-enable camelcase */

    query(store, type, query) {
        let id;

        if (query.id) {
            id = query.id;
            delete query.id;
Example #8
0
import Ember from 'ember';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import documentTitle from 'ghost-admin/utils/document-title';
import config from './config/environment';

const {
    Router,
    inject: {service},
    on
} = Ember;

const GhostRouter = Router.extend({
    location: config.locationType, // use HTML5 History API instead of hash-tag based URLs
    rootURL: ghostPaths().adminRoot, // admin interface lives under sub-directory /ghost

    notifications: service(),

    displayDelayedNotifications: on('didTransition', function () {
        this.get('notifications').displayDelayed();
    })
});

documentTitle();

GhostRouter.map(function () {
  this.route('setup', function () {
      this.route('one');
      this.route('two');
      this.route('three');
  });
        } else if (isRequestEntityTooLargeError(error)) {
            message = 'The image you uploaded was larger than the maximum file size your server allows.';
        } else if (error.errors && !isBlank(error.errors[0].message)) {
            message = error.errors[0].message;
        } else {
            message = 'Something went wrong :(';
        }

        this.set('failureMessage', message);
        invokeAction(this, 'uploadFailed', error);
    },

    generateRequest() {
        let ajax = this.get('ajax');
        let formData = this.get('formData');
        let url = `${ghostPaths().apiRoot}/uploads/`;

        this._uploadStarted();

        ajax.post(url, {
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'text',
            xhr: () => {
                let xhr = new window.XMLHttpRequest();

                xhr.upload.addEventListener('progress', (event) => {
                    this._uploadProgress(event);
                }, false);
Example #10
0
            return subscriber.destroyRecord().then(() => {
                this.set('subscriberToDelete', null);
                this.get('table').removeRow(subscriber);
                this.decrementProperty('total');
            });
        },

        cancelDeleteSubscriber() {
            this.set('subscriberToDelete', null);
        },

        reset() {
            this.get('table').setRows([]);
            this.send('loadFirstPage');
        },

        exportData() {
            let exportUrl = ghostPaths().url.api('subscribers/csv');
            let accessToken = this.get('session.data.authenticated.access_token');
            let downloadURL = `${exportUrl}?access_token=${accessToken}`;
            let iframe = $('#iframeDownload');

            if (iframe.length === 0) {
                iframe = $('<iframe>', {id: 'iframeDownload'}).hide().appendTo('body');
            }

            iframe.attr('src', downloadURL);
        }
    }
});