Added libraryCollections on server
This commit is contained in:
@@ -8,6 +8,7 @@ import '/imports/api/users/methods/updateFileStorageUsed.js';
|
||||
|
||||
import { some } from 'lodash';
|
||||
const defaultLibraries = process.env.DEFAULT_LIBRARIES && process.env.DEFAULT_LIBRARIES.split(',') || [];
|
||||
const defaultLibraryCollections = process.env.DEFAULT_LIBRARY_COLLECTIONS && process.env.DEFAULT_LIBRARY_COLLECTIONS.split(',') || [];
|
||||
|
||||
const userSchema = new SimpleSchema({
|
||||
username: {
|
||||
@@ -74,6 +75,15 @@ const userSchema = new SimpleSchema({
|
||||
},
|
||||
'subscribedLibraries.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
subscribedLibraryCollections: {
|
||||
type: Array,
|
||||
defaultValue: defaultLibraryCollections,
|
||||
max: 100,
|
||||
},
|
||||
'subscribedLibraryCollections.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
subscribedCharacters: {
|
||||
@@ -270,6 +280,36 @@ Meteor.users.subscribeToLibrary = new ValidatedMethod({
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.users.subscribeToLibraryCollection = new ValidatedMethod({
|
||||
name: 'users.subscribeToLibraryCollection',
|
||||
validate: new SimpleSchema({
|
||||
libraryCollectionId:{
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
subscribe: {
|
||||
type: Boolean,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 5,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({libraryCollectionId, subscribe}){
|
||||
if (!this.userId) throw 'Can only subscribe if logged in';
|
||||
if (subscribe){
|
||||
return Meteor.users.update(this.userId, {
|
||||
$addToSet: {subscribedLibraryCollections: libraryCollectionId},
|
||||
});
|
||||
} else {
|
||||
return Meteor.users.update(this.userId, {
|
||||
$pullAll: {subscribedLibraryCollections: libraryCollectionId},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.users.findUserByUsernameOrEmail = new ValidatedMethod({
|
||||
name: 'users.findUserByUsernameOrEmail',
|
||||
validate: new SimpleSchema({
|
||||
|
||||
Reference in New Issue
Block a user