Ghost/ghost/admin/app/transforms/unsplash-settings.js

29 lines
752 B
JavaScript
Raw Normal View History

/* eslint-disable camelcase */
import Transform from 'ember-data/transform';
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
const DEFAULT_SETTINGS = {
isActive: true
};
export default Transform.extend({
deserialize(serialized) {
if (serialized) {
let settingsObject;
try {
settingsObject = JSON.parse(serialized) || DEFAULT_SETTINGS;
} catch (e) {
settingsObject = DEFAULT_SETTINGS;
}
return UnsplashObject.create(settingsObject);
}
return DEFAULT_SETTINGS;
},
serialize(deserialized) {
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_SETTINGS);
}
});