2019-09-16 11:45:55 +03:00
|
|
|
const ghostBookshelf = require('./base');
|
2020-05-28 13:57:02 +03:00
|
|
|
const urlUtils = require('../../shared/url-utils');
|
2019-09-16 11:45:55 +03:00
|
|
|
|
|
|
|
const PostsMeta = ghostBookshelf.Model.extend({
|
2019-10-09 15:38:08 +03:00
|
|
|
tableName: 'posts_meta',
|
|
|
|
|
2021-08-03 09:15:49 +03:00
|
|
|
defaults: function defaults() {
|
|
|
|
return {
|
|
|
|
email_only: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-03-23 12:11:24 +03:00
|
|
|
formatOnWrite(attrs) {
|
2021-03-18 20:16:37 +03:00
|
|
|
['og_image', 'twitter_image'].forEach((attr) => {
|
|
|
|
if (attrs[attr]) {
|
|
|
|
attrs[attr] = urlUtils.toTransformReady(attrs[attr]);
|
2019-10-09 15:38:08 +03:00
|
|
|
}
|
2021-03-18 20:16:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return attrs;
|
|
|
|
},
|
|
|
|
|
|
|
|
parse() {
|
|
|
|
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
|
2019-10-09 15:38:08 +03:00
|
|
|
|
2021-03-18 20:16:37 +03:00
|
|
|
['og_image', 'twitter_image'].forEach((attr) => {
|
|
|
|
if (attrs[attr]) {
|
|
|
|
attrs[attr] = urlUtils.transformReadyToAbsolute(attrs[attr]);
|
2019-10-09 15:38:08 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-18 20:16:37 +03:00
|
|
|
return attrs;
|
2019-10-09 15:38:08 +03:00
|
|
|
}
|
2019-09-16 11:45:55 +03:00
|
|
|
}, {
|
|
|
|
post() {
|
|
|
|
return this.belongsTo('Post');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
PostsMeta: ghostBookshelf.model('PostsMeta', PostsMeta)
|
|
|
|
};
|