mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
755a3a320e
closes https://github.com/TryGhost/Team/issues/893 - We need a place to store email-only flag and posts_meta is the best place for it
43 lines
988 B
JavaScript
43 lines
988 B
JavaScript
const ghostBookshelf = require('./base');
|
|
const urlUtils = require('../../shared/url-utils');
|
|
|
|
const PostsMeta = ghostBookshelf.Model.extend({
|
|
tableName: 'posts_meta',
|
|
|
|
defaults: function defaults() {
|
|
return {
|
|
email_only: false
|
|
};
|
|
},
|
|
|
|
formatOnWrite(attrs) {
|
|
['og_image', 'twitter_image'].forEach((attr) => {
|
|
if (attrs[attr]) {
|
|
attrs[attr] = urlUtils.toTransformReady(attrs[attr]);
|
|
}
|
|
});
|
|
|
|
return attrs;
|
|
},
|
|
|
|
parse() {
|
|
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
|
|
|
|
['og_image', 'twitter_image'].forEach((attr) => {
|
|
if (attrs[attr]) {
|
|
attrs[attr] = urlUtils.transformReadyToAbsolute(attrs[attr]);
|
|
}
|
|
});
|
|
|
|
return attrs;
|
|
}
|
|
}, {
|
|
post() {
|
|
return this.belongsTo('Post');
|
|
}
|
|
});
|
|
|
|
module.exports = {
|
|
PostsMeta: ghostBookshelf.model('PostsMeta', PostsMeta)
|
|
};
|