2017-08-02 10:05:59 +03:00
|
|
|
/* eslint-disable camelcase */
|
2020-01-16 20:01:12 +03:00
|
|
|
import Transform from '@ember-data/serializer/transform';
|
2017-08-02 10:05:59 +03:00
|
|
|
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
|
|
|
|
|
2017-09-21 12:13:31 +03:00
|
|
|
const DEFAULT_SETTINGS = {
|
|
|
|
isActive: true
|
|
|
|
};
|
|
|
|
|
2017-08-02 10:05:59 +03:00
|
|
|
export default Transform.extend({
|
|
|
|
deserialize(serialized) {
|
|
|
|
if (serialized) {
|
|
|
|
let settingsObject;
|
|
|
|
try {
|
2017-09-21 12:13:31 +03:00
|
|
|
settingsObject = JSON.parse(serialized) || DEFAULT_SETTINGS;
|
2017-08-02 10:05:59 +03:00
|
|
|
} catch (e) {
|
2017-09-21 12:13:31 +03:00
|
|
|
settingsObject = DEFAULT_SETTINGS;
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return UnsplashObject.create(settingsObject);
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:13:31 +03:00
|
|
|
return DEFAULT_SETTINGS;
|
2017-08-02 10:05:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
2017-09-21 12:13:31 +03:00
|
|
|
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_SETTINGS);
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
|
|
|
});
|