Vulcan/packages/telescope-post-by-feed/lib/feeds.js

75 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-12-19 14:32:25 +09:00
var feedSchema = new SimpleSchema({
2014-12-18 10:47:37 +09:00
url: {
type: String,
regEx: SimpleSchema.RegEx.Url
}
});
2014-12-19 14:32:25 +09:00
Feeds = new Meteor.Collection("feeds");
Feeds.attachSchema(feedSchema);
2014-12-18 10:47:37 +09:00
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-31 11:54:38 +09:00
// Settings
var enableFeeds = {
propertyName: 'enableFeeds',
propertySchema: {
type: Boolean,
optional: true,
autoform: {
group: 'feeds',
instructions: 'Enable posting from RSS feeds (requires restart).'
}
}
}
addToSettingsSchema.push(enableFeeds);
2014-12-18 10:47:37 +09:00
Meteor.startup(function () {
Feeds.allow({
2014-12-19 14:39:43 +09:00
insert: isAdminById,
2014-12-19 14:32:25 +09:00
update: isAdminById,
2014-12-18 10:47:37 +09:00
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);
}
});
});