2014-12-18 10:47:37 +09:00
|
|
|
// feedSchema schema
|
|
|
|
feedSchema = new SimpleSchema({
|
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
regEx: SimpleSchema.RegEx.Url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Feeds = new Meteor.Collection("feeds", {
|
|
|
|
schema: feedSchema
|
|
|
|
});
|
|
|
|
|
2014-12-18 16:01:18 +09:00
|
|
|
// used to keep track of which feed a post was imported from
|
|
|
|
var feedIdProperty = {
|
|
|
|
propertyName: 'feedId',
|
|
|
|
propertySchema: {
|
|
|
|
type: String,
|
|
|
|
label: 'feedId',
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addToPostSchema.push(feedIdProperty);
|
|
|
|
|
|
|
|
// the RSS ID of the post in its original feed
|
|
|
|
var feedItemIdProperty = {
|
|
|
|
propertyName: 'feedItemId',
|
|
|
|
propertySchema: {
|
|
|
|
type: String,
|
|
|
|
label: 'feedItemId',
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addToPostSchema.push(feedItemIdProperty);
|
|
|
|
|
2014-12-18 10:47:37 +09:00
|
|
|
Meteor.startup(function () {
|
|
|
|
Feeds.allow({
|
|
|
|
remove: isAdminById
|
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.methods({
|
|
|
|
insertFeed: function(feedUrl){
|
|
|
|
check(feedUrl, feedSchema);
|
|
|
|
|
|
|
|
if (Feeds.findOne({url: feedSchema.url}))
|
|
|
|
throw new Meteor.Error('already-exists', i18n.t('feed_already_exists'));
|
|
|
|
|
|
|
|
if (!Meteor.user() || !isAdmin(Meteor.user()))
|
|
|
|
throw new Meteor.Error('login-required', i18n.t('you_need_to_login_and_be_an_admin_to_add_a_new_feed'));
|
|
|
|
|
|
|
|
return Feeds.insert(feedUrl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|