mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Merge branch 'master' into suspect-wordlist
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
const mongoose = require('../mongoose');
|
||||
const mongoose = require('../services/mongoose');
|
||||
const uuid = require('uuid');
|
||||
const _ = require('lodash');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
+19
-9
@@ -1,4 +1,4 @@
|
||||
const mongoose = require('../mongoose');
|
||||
const mongoose = require('../services/mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const Setting = require('./setting');
|
||||
@@ -19,7 +19,7 @@ const AssetSchema = new Schema({
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'article'
|
||||
default: 'assets'
|
||||
},
|
||||
scraped: {
|
||||
type: Date,
|
||||
@@ -68,13 +68,6 @@ AssetSchema.index({
|
||||
background: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true if the asset is closed, false else.
|
||||
*/
|
||||
AssetSchema.virtual('isClosed').get(function() {
|
||||
return this.closedAt && this.closedAt.getTime() <= new Date().getTime();
|
||||
});
|
||||
|
||||
/**
|
||||
* Finds an asset by its id.
|
||||
* @param {String} id identifier of the asset (uuid).
|
||||
@@ -87,6 +80,13 @@ AssetSchema.statics.findById = (id) => Asset.findOne({id});
|
||||
*/
|
||||
AssetSchema.statics.findByUrl = (url) => Asset.findOne({url});
|
||||
|
||||
/**
|
||||
* Returns true if the asset is closed, false else.
|
||||
*/
|
||||
AssetSchema.virtual('isClosed').get(function() {
|
||||
return this.closedAt && this.closedAt.getTime() <= new Date().getTime();
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the settings given an asset query and rectifies it against the
|
||||
* global settings.
|
||||
@@ -156,6 +156,16 @@ AssetSchema.statics.search = (value) => value.length === 0 ? Asset.find({}) : As
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Finds multiple assets with matching ids
|
||||
* @param {Array} ids an array of Strings of asset_id
|
||||
* @return {Promise} resolves to list of Assets
|
||||
*/
|
||||
AssetSchema.statics.findMultipleById = function (ids) {
|
||||
const query = ids.map(id => ({id}));
|
||||
return Asset.find(query);
|
||||
};
|
||||
|
||||
const Asset = mongoose.model('Asset', AssetSchema);
|
||||
|
||||
module.exports = Asset;
|
||||
|
||||
+10
-1
@@ -1,4 +1,4 @@
|
||||
const mongoose = require('../mongoose');
|
||||
const mongoose = require('../services/mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
const _ = require('lodash');
|
||||
const uuid = require('uuid');
|
||||
@@ -324,6 +324,15 @@ CommentSchema.statics.removeAction = (item_id, user_id, action_type) => Action.r
|
||||
*/
|
||||
CommentSchema.statics.all = () => Comment.find();
|
||||
|
||||
/**
|
||||
* Returns all the comments by user
|
||||
* probably to be paginated at some point in the future
|
||||
* @return {Promise} array resolves to an array of comments by that user
|
||||
*/
|
||||
CommentSchema.statics.findByUserId = function (author_id) {
|
||||
return Comment.find({author_id});
|
||||
};
|
||||
|
||||
// Comment model.
|
||||
const Comment = mongoose.model('Comment', CommentSchema);
|
||||
|
||||
|
||||
+19
-3
@@ -1,7 +1,7 @@
|
||||
const mongoose = require('../mongoose');
|
||||
const mongoose = require('../services/mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
const _ = require('lodash');
|
||||
const cache = require('../cache');
|
||||
const cache = require('../services/cache');
|
||||
|
||||
const WordlistSchema = new Schema({
|
||||
banned: [String],
|
||||
@@ -46,6 +46,14 @@ const SettingSchema = new Schema({
|
||||
default: ''
|
||||
},
|
||||
wordlist: WordlistSchema,
|
||||
charCount: {
|
||||
type: Number,
|
||||
default: 5000
|
||||
},
|
||||
charCountEnable: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
@@ -83,7 +91,15 @@ SettingSchema.method('merge', function(src) {
|
||||
*/
|
||||
SettingSchema.method('filterForUser', function(user = false) {
|
||||
if (!user || !user.roles.includes('admin')) {
|
||||
return _.pick(this.toJSON(), ['moderation', 'infoBoxEnable', 'infoBoxContent']);
|
||||
return _.pick(this.toJSON(), [
|
||||
'moderation',
|
||||
'infoBoxEnable',
|
||||
'infoBoxContent',
|
||||
'closeTimeout',
|
||||
'closedMessage',
|
||||
'charCountEnable',
|
||||
'charCount'
|
||||
]);
|
||||
}
|
||||
|
||||
return this.toJSON();
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const mongoose = require('../mongoose');
|
||||
const mongoose = require('../services/mongoose');
|
||||
const uuid = require('uuid');
|
||||
const _ = require('lodash');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
Reference in New Issue
Block a user