@positivegrid/pg-mongoose-schema 27.8.5 → 28.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5161 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +1288 -0
- package/dist/index.mjs +5128 -0
- package/package.json +52 -4
- package/index.js +0 -28
- package/models/banks.js +0 -42
- package/models/device.js +0 -51
- package/models/featuredList.js +0 -91
- package/models/hardware.js +0 -256
- package/models/homeConfig.js +0 -97
- package/models/oauth.js +0 -52
- package/models/partner.js +0 -265
- package/models/payment.js +0 -899
- package/models/pgConfig.js +0 -88
- package/models/preset.js +0 -845
- package/models/promotion.js +0 -590
- package/models/redeem.js +0 -26
- package/models/toneTheme.js +0 -78
- package/models/toneThemeFeaturedList.js +0 -49
- package/models/user.js +0 -639
- package/models/userTrack.js +0 -107
package/models/preset.js
DELETED
|
@@ -1,845 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash')
|
|
4
|
-
const moment = require('moment')
|
|
5
|
-
const debug = require('debug')('model:preset')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal method - _parsePresetForm
|
|
9
|
-
* All query should gothrough this handler before search for compatible issue
|
|
10
|
-
*/
|
|
11
|
-
function _queryCompatibilityHandler(query) {
|
|
12
|
-
let formatQuery = {}
|
|
13
|
-
if (_.has(query, 'preset_for') && query['preset_for'] === 'amp2') {
|
|
14
|
-
formatQuery = _.assign({}, query, { preset_for: { $in: ['amp2', 'bias'] } })
|
|
15
|
-
} else if (!_.has(query, 'preset_for') || query['preset_for'] === '') {
|
|
16
|
-
formatQuery = _.assign({}, query, { preset_for: 'jamup' })
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (_.isEmpty(formatQuery)) {
|
|
20
|
-
formatQuery = _.clone(query)
|
|
21
|
-
}
|
|
22
|
-
debug('_queryCompatibilityHandler %o', formatQuery)
|
|
23
|
-
return formatQuery
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// version_comparison follow the same format as mongodb query comparsion:
|
|
27
|
-
// https://docs.mongodb.com/manual/reference/operator/query-comparison/
|
|
28
|
-
// only support BIAS FX preset for now
|
|
29
|
-
//
|
|
30
|
-
// HardCode: useragent == iPad then only show preset_version <= 1.7
|
|
31
|
-
function _handlePresetVersion(queryObj, req) {
|
|
32
|
-
const supportVersionComparison = ['eq', 'gt', 'gte', 'lt', 'lte', 'ne']
|
|
33
|
-
if (!_.has(req.query, 'preset_for') || (_.has(req.query, 'preset_for') && req.query['preset_for'] !== 'live')) {
|
|
34
|
-
return _.clone(queryObj)
|
|
35
|
-
} else if (_.has(req.query, 'preset_version') && _.has(req.query, 'version_comparison')) {
|
|
36
|
-
if (_.indexOf(supportVersionComparison, req.query['version_comparison']) !== -1) {
|
|
37
|
-
const tmpVersionQuery = _.clone(queryObj)
|
|
38
|
-
const versionQuery = _buildPresetVersionQuery(req.query['preset_version'], req.query['version_comparison'])
|
|
39
|
-
if (versionQuery) {
|
|
40
|
-
return _.merge(tmpVersionQuery, versionQuery)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return _.clone(queryObj)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _buildPresetVersionQuery(version, comparison) {
|
|
49
|
-
const tmpAttrs = String(version).split('.')
|
|
50
|
-
let major = 0
|
|
51
|
-
let minor = 0
|
|
52
|
-
if (tmpAttrs.length !== 2) {
|
|
53
|
-
debug('ERROR:_buildPresetVersionQuery:Incorrect version %s', version)
|
|
54
|
-
return false
|
|
55
|
-
} else {
|
|
56
|
-
major = parseInt(tmpAttrs[0], 10)
|
|
57
|
-
minor = parseInt(tmpAttrs[1], 10)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
switch (comparison) {
|
|
61
|
-
case 'eq':
|
|
62
|
-
return {
|
|
63
|
-
'$and': [
|
|
64
|
-
{ 'version.major': major },
|
|
65
|
-
{ 'version.minor': minor }
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
case 'gt':
|
|
69
|
-
case 'gte':
|
|
70
|
-
case 'lt':
|
|
71
|
-
case 'lte':
|
|
72
|
-
const compareOper = '$' + comparison
|
|
73
|
-
const minorQuery = {}
|
|
74
|
-
minorQuery[compareOper] = minor
|
|
75
|
-
return {
|
|
76
|
-
'$and': [
|
|
77
|
-
{ 'version.major': major },
|
|
78
|
-
{ 'version.minor': minorQuery }
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
default:
|
|
82
|
-
debug('ERROR:_buildPresetVersionQuery:Not support format %s %s', version, comparison)
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function _buildSortQuery(orderParam) {
|
|
88
|
-
let sortQuery = {}
|
|
89
|
-
switch (orderParam) {
|
|
90
|
-
case 'popular':
|
|
91
|
-
sortQuery = { num_likes: -1 }
|
|
92
|
-
break
|
|
93
|
-
case 'alphabet':
|
|
94
|
-
sortQuery = { name: 1 }
|
|
95
|
-
break
|
|
96
|
-
case 'hot':
|
|
97
|
-
sortQuery = { num_downloads: -1 }
|
|
98
|
-
break
|
|
99
|
-
case 'latest':
|
|
100
|
-
default:
|
|
101
|
-
sortQuery = { created_on: -1 }
|
|
102
|
-
}
|
|
103
|
-
return sortQuery
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Filter presets with license_tier parameter, but need to consider backward compatibility.
|
|
108
|
-
* e.g., license_tier == 'elite' then need to get elite/pro/std and all others presets
|
|
109
|
-
* However, expansion need to be considered out of normal license tier,
|
|
110
|
-
* so we use expansionData/allExpansion to controll it.
|
|
111
|
-
* @param {String} licenseTierParams
|
|
112
|
-
*/
|
|
113
|
-
function _buildLicenseTierQuery(licenseTierParam) {
|
|
114
|
-
const tmpLicenseTier = String(licenseTierParam).split(',')
|
|
115
|
-
|
|
116
|
-
let tmpData = new Set()
|
|
117
|
-
let expansionData = new Set()
|
|
118
|
-
let allExpansion = new Set(['celestion', 'classic'])
|
|
119
|
-
_.forEach(tmpLicenseTier, lic => {
|
|
120
|
-
switch (lic) {
|
|
121
|
-
case 'celestion':
|
|
122
|
-
case 'classic':
|
|
123
|
-
expansionData.add(lic)
|
|
124
|
-
allExpansion.delete(lic)
|
|
125
|
-
break
|
|
126
|
-
case 'elite':
|
|
127
|
-
tmpData.add('elite')
|
|
128
|
-
tmpData.add('pro')
|
|
129
|
-
tmpData.add('std')
|
|
130
|
-
tmpData.add(null)
|
|
131
|
-
break
|
|
132
|
-
case 'pro':
|
|
133
|
-
tmpData.add('pro')
|
|
134
|
-
tmpData.add('std')
|
|
135
|
-
tmpData.add(null)
|
|
136
|
-
break
|
|
137
|
-
case 'std':
|
|
138
|
-
tmpData.add('std')
|
|
139
|
-
tmpData.add(null)
|
|
140
|
-
break
|
|
141
|
-
case 'lite':
|
|
142
|
-
case 'demo':
|
|
143
|
-
tmpData.add(null)
|
|
144
|
-
break
|
|
145
|
-
default:
|
|
146
|
-
debug('ERROR:_buildLicenseTierQuery %s', licenseTierParam)
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
const output = (expansionData.size > 0)
|
|
151
|
-
? {
|
|
152
|
-
'$and': [{
|
|
153
|
-
'license_tier': { '$in': Array.from(tmpData) }
|
|
154
|
-
}, {
|
|
155
|
-
'license_tier': { '$in': _.concat(Array.from(tmpData), Array.from(expansionData)) }
|
|
156
|
-
}, {
|
|
157
|
-
'license_tier': { '$nin': Array.from(allExpansion) }
|
|
158
|
-
}]
|
|
159
|
-
}
|
|
160
|
-
: {
|
|
161
|
-
'$and': [{
|
|
162
|
-
'license_tier': { '$in': Array.from(tmpData) }
|
|
163
|
-
}, {
|
|
164
|
-
'license_tier': { '$nin': Array.from(allExpansion) }
|
|
165
|
-
}]
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
debug('_buildLicenseTierQuery:%j', output)
|
|
169
|
-
return output
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
module.exports = function (mongoose) {
|
|
173
|
-
const Schema = mongoose.Schema
|
|
174
|
-
const ObjectId = Schema.Types.ObjectId
|
|
175
|
-
const deepPopulate = require('mongoose-deep-populate')(mongoose)
|
|
176
|
-
|
|
177
|
-
const filterKeyword = (keyword) => {
|
|
178
|
-
return String(keyword).replace(/[/\\@%&]+/g, '')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const parsePageParams = function (data) {
|
|
182
|
-
debug('parsePageParams', data)
|
|
183
|
-
let pageParams = {
|
|
184
|
-
page_size: 12,
|
|
185
|
-
page: 1
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (data && _.has(data, 'page_size')) {
|
|
189
|
-
let pageSize = Array.isArray(data['page_size'])
|
|
190
|
-
? parseInt(data['page_size'].pop(), 10)
|
|
191
|
-
: parseInt(data['page_size'], 10)
|
|
192
|
-
|
|
193
|
-
if (pageSize >= 1) {
|
|
194
|
-
pageParams = _.merge(pageParams, { page_size: pageSize })
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (data && _.has(data, 'page')) {
|
|
199
|
-
let page = (Array.isArray(data['page']))
|
|
200
|
-
? parseInt(data['page'].pop(), 10)
|
|
201
|
-
: parseInt(data['page'], 10)
|
|
202
|
-
|
|
203
|
-
if (page > 1) {
|
|
204
|
-
pageParams = _.merge(pageParams, { page: page })
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
debug('parsePageParams:output', pageParams)
|
|
209
|
-
return pageParams
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const PresetSchema = new Schema({
|
|
213
|
-
name: { type: String, index: true, required: true },
|
|
214
|
-
creator_id: { type: ObjectId, ref: 'User', required: true },
|
|
215
|
-
preset_for: { type: String, required: true },
|
|
216
|
-
status: { type: Number, default: 0, required: true }, // 0:alive, 1:delete, 2: offline, 3: special(limited), 4: processing (Spark: PVN)
|
|
217
|
-
description: { type: String },
|
|
218
|
-
tags: { type: [{ type: String }], default: () => null },
|
|
219
|
-
is_featured: { type: Boolean, default: false },
|
|
220
|
-
category: { type: String, index: true },
|
|
221
|
-
active_effects: { type: String },
|
|
222
|
-
preset_data: { type: String },
|
|
223
|
-
preset_features: { type: Schema.Types.Mixed, default: null }, // match (1:enable, 2:disable)
|
|
224
|
-
version: {
|
|
225
|
-
major: { type: Number },
|
|
226
|
-
minor: { type: Number }
|
|
227
|
-
},
|
|
228
|
-
preset_meta: { type: Schema.Types.Mixed },
|
|
229
|
-
preset_scene: { type: Array }, // fx2
|
|
230
|
-
license_tier: { type: [{ type: String }], index: true, default: () => null }, // amp2: std/pro/elite pack:celestion
|
|
231
|
-
// only () => null can set empty array as null: https://github.com/Automattic/mongoose/issues/1335#issuecomment-321817528
|
|
232
|
-
num_comments: { type: Number, default: 0 },
|
|
233
|
-
num_downloads: { type: Number, default: 0 },
|
|
234
|
-
num_likes: { type: Number, default: 0 },
|
|
235
|
-
rating_sum: { type: Number, default: 0 },
|
|
236
|
-
rating_avg: { type: Number, default: 0 },
|
|
237
|
-
rating_count: { type: Number, default: 0 },
|
|
238
|
-
image_url: { type: String },
|
|
239
|
-
thumb_url: { type: String },
|
|
240
|
-
signal_chain_type: {
|
|
241
|
-
type: String,
|
|
242
|
-
enum: ['in1', 'in2']
|
|
243
|
-
},
|
|
244
|
-
created_on: { type: Date, default: Date.now },
|
|
245
|
-
updated_on: { type: Date, default: Date.now }
|
|
246
|
-
}, { collection: 'jamup_preset', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
247
|
-
PresetSchema.index({
|
|
248
|
-
name: 1,
|
|
249
|
-
description: 1,
|
|
250
|
-
category: 1
|
|
251
|
-
})
|
|
252
|
-
PresetSchema.index({
|
|
253
|
-
preset_for: 1,
|
|
254
|
-
status: 1
|
|
255
|
-
})
|
|
256
|
-
PresetSchema.index({
|
|
257
|
-
preset_for: 1,
|
|
258
|
-
signal_chain_type: 1,
|
|
259
|
-
status: 1
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
const PresetSongMappingSchema = new Schema({
|
|
263
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
264
|
-
song_id: { type: String, required: true },
|
|
265
|
-
created_on: { type: Date, default: Date.now }
|
|
266
|
-
}, { collection: 'preset_song_mapping' })
|
|
267
|
-
PresetSongMappingSchema.index({
|
|
268
|
-
song_id: 1
|
|
269
|
-
})
|
|
270
|
-
PresetSongMappingSchema.index({
|
|
271
|
-
preset_id: 1,
|
|
272
|
-
song_id: 1
|
|
273
|
-
}, { unique: true })
|
|
274
|
-
|
|
275
|
-
const PresetTagsMetaSchema = new Schema({
|
|
276
|
-
name: { type: String, required: true },
|
|
277
|
-
count: { type: Number, default: 0, required: true },
|
|
278
|
-
preset_for: { type: String, required: true },
|
|
279
|
-
created_on: { type: Date, default: Date.now }
|
|
280
|
-
}, { collection: 'preset_tags_meta' })
|
|
281
|
-
PresetTagsMetaSchema.index({
|
|
282
|
-
name: 1,
|
|
283
|
-
preset_for: 1
|
|
284
|
-
}, { unique: true })
|
|
285
|
-
PresetTagsMetaSchema.index({
|
|
286
|
-
count: -1
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
var PresetUserComment = new Schema({
|
|
290
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
291
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
292
|
-
comment_text: { type: String, required: true },
|
|
293
|
-
preset_for: { type: String },
|
|
294
|
-
status: { type: Number, default: 1, required: true }, // 1:Active 2:Delete
|
|
295
|
-
date_comment: { type: Date, default: Date.now }
|
|
296
|
-
}, { collection: 'jamup_userpresetcomment' })
|
|
297
|
-
|
|
298
|
-
var PresetUserLike = new Schema({
|
|
299
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
300
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
301
|
-
preset_for: { type: String },
|
|
302
|
-
date_like: { type: Date, default: Date.now }
|
|
303
|
-
}, { collection: 'jamup_userpresetlike' })
|
|
304
|
-
const FakePresetLikeSchema = new Schema({
|
|
305
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
306
|
-
likes: { type: Number, default: 0 }
|
|
307
|
-
}, { collection: 'fake_userpresetlike' })
|
|
308
|
-
|
|
309
|
-
let PresetUserDownload = new Schema({
|
|
310
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
311
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
312
|
-
preset_for: { type: String, reqired: true },
|
|
313
|
-
date_download: { type: Date, default: Date.now },
|
|
314
|
-
updated_on: { type: Date, default: Date.now }
|
|
315
|
-
}, { collection: 'jamup_userpresetdownload' })
|
|
316
|
-
|
|
317
|
-
let PopularPresetList = new Schema({
|
|
318
|
-
preset_for: { type: String, required: true },
|
|
319
|
-
popular_range: { type: String, required: true },
|
|
320
|
-
popular_preset_list: [{ type: ObjectId, ref: 'Preset', required: true }],
|
|
321
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
322
|
-
}, { collection: 'jamup_popularpresetlist' })
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Plugin
|
|
326
|
-
*/
|
|
327
|
-
PresetSchema.plugin(deepPopulate, {})
|
|
328
|
-
PresetUserLike.plugin(deepPopulate, {})
|
|
329
|
-
PresetUserComment.plugin(deepPopulate, {})
|
|
330
|
-
|
|
331
|
-
PresetSchema.static({
|
|
332
|
-
getPresetByUserId: function (userId, cb) {
|
|
333
|
-
this.find({ creator_id: userId })
|
|
334
|
-
.sort({ created_on: -1 })
|
|
335
|
-
.exec(cb)
|
|
336
|
-
},
|
|
337
|
-
getPresetByQuery: async function (req, opts = {}) {
|
|
338
|
-
let pageParams = {}
|
|
339
|
-
let searchCondition = []
|
|
340
|
-
let shouldCondition = []
|
|
341
|
-
|
|
342
|
-
debug('getPresetByQuery:input:%j', req.query)
|
|
343
|
-
if (!_.has(req.query, 'keyword') || !_.isString(req.query.keyword)) {
|
|
344
|
-
throw new Error('missing the searching term')
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
pageParams = parsePageParams(req.query)
|
|
348
|
-
searchCondition = {
|
|
349
|
-
preset_for: (req.query.preset_for) ? req.query.preset_for : 'jamup',
|
|
350
|
-
status: 0
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Build license_tier query rule, default would be license_tier: null
|
|
354
|
-
// The detail of the rule can jump to _buildLicenseTierQuery
|
|
355
|
-
if (_.has(req.query, 'license_tier')) {
|
|
356
|
-
const tmpQuery = _.clone(searchCondition)
|
|
357
|
-
searchCondition = _.merge(tmpQuery, _buildLicenseTierQuery(req.query['license_tier']))
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (_.has(req.query, 'order') && req.query.order === 'hot') {
|
|
361
|
-
searchCondition = _.assign({}, searchCondition, { created_on: { $gte: moment().subtract(1, 'month').toDate() } })
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
searchCondition = _handlePresetVersion(searchCondition, req)
|
|
365
|
-
shouldCondition.push({
|
|
366
|
-
text: {
|
|
367
|
-
path: 'name',
|
|
368
|
-
query: req.query.keyword,
|
|
369
|
-
fuzzy: {
|
|
370
|
-
maxEdits: 1,
|
|
371
|
-
prefixLength: 1,
|
|
372
|
-
maxExpansions: 30
|
|
373
|
-
},
|
|
374
|
-
score: {
|
|
375
|
-
boost: {
|
|
376
|
-
value: 3
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}, {
|
|
381
|
-
text: {
|
|
382
|
-
path: ['description', 'category'],
|
|
383
|
-
query: req.query.keyword,
|
|
384
|
-
fuzzy: {
|
|
385
|
-
maxEdits: 2,
|
|
386
|
-
prefixLength: 0,
|
|
387
|
-
maxExpansions: 50
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
debug('INFO:getPresetByQuery:%j:%j', searchCondition, shouldCondition)
|
|
393
|
-
const aggregatePipeline = [{
|
|
394
|
-
$search: {
|
|
395
|
-
index: 'default',
|
|
396
|
-
compound: {
|
|
397
|
-
should: shouldCondition,
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}, {
|
|
401
|
-
$match: searchCondition
|
|
402
|
-
}, {
|
|
403
|
-
$skip: ((pageParams.page - 1) * pageParams.page_size)
|
|
404
|
-
}, {
|
|
405
|
-
$limit: pageParams.page_size
|
|
406
|
-
}]
|
|
407
|
-
if (!_.has(opts, 'full')) {
|
|
408
|
-
aggregatePipeline.push({
|
|
409
|
-
$project: {
|
|
410
|
-
preset_data: 0
|
|
411
|
-
}
|
|
412
|
-
})
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const result = await this.aggregate(aggregatePipeline)
|
|
416
|
-
return result
|
|
417
|
-
},
|
|
418
|
-
getPresetsBySearch: async function (req) {
|
|
419
|
-
let pageParams = {}
|
|
420
|
-
let searchCondition = {}
|
|
421
|
-
let sortCondition = _buildSortQuery(req.query.order)
|
|
422
|
-
let selectOps = {}
|
|
423
|
-
|
|
424
|
-
debug('getPresetsBySearch:input', req.query)
|
|
425
|
-
pageParams = parsePageParams(req.query)
|
|
426
|
-
searchCondition = {
|
|
427
|
-
'preset_for': (req.query['preset_for']) ? req.query['preset_for'] : 'jamup',
|
|
428
|
-
'status': 0
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (!_.has(req.query, 'detail') || req.query.detail !== 'yes') {
|
|
432
|
-
// selectOps = '-preset_data'
|
|
433
|
-
selectOps = { preset_data: 0 }
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
if (_.has(req.query, 'pids')) {
|
|
437
|
-
const pids = req.query.pids.split(',')
|
|
438
|
-
searchCondition['_id'] = {
|
|
439
|
-
'$in': pids
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (_.has(req.query, 'category')) {
|
|
444
|
-
const categories = String(req.query['category']).split(',')
|
|
445
|
-
searchCondition['category'] = {
|
|
446
|
-
'$in': categories
|
|
447
|
-
}
|
|
448
|
-
} else if (_.has(req.query, 'except_cateogry')) {
|
|
449
|
-
const exceptCategories = String(req.query['except_cateogry']).split(',')
|
|
450
|
-
searchCondition['category'] = {
|
|
451
|
-
'$nin': exceptCategories
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
if (_.has(req.query, 'pedal_type')) {
|
|
456
|
-
searchCondition['preset_meta.pedal_type'] = req.query['pedal_type']
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// featureKey1:Val1,featureKey2:Val2
|
|
460
|
-
if (_.has(req.query, 'preset_features')) {
|
|
461
|
-
let params = req.query['preset_features'].split(',')
|
|
462
|
-
let featureQuery = {}
|
|
463
|
-
_.forEach(params, (param) => {
|
|
464
|
-
let tmpParams = param.split(':')
|
|
465
|
-
if (tmpParams.length === 2) {
|
|
466
|
-
featureQuery[tmpParams[0]] = parseInt(tmpParams[1], 10)
|
|
467
|
-
}
|
|
468
|
-
})
|
|
469
|
-
searchCondition['preset_features'] = featureQuery
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// created_after/created_before - assign preset created_on date
|
|
473
|
-
let createQuery = {}
|
|
474
|
-
if (_.has(req.query, 'create_after')) {
|
|
475
|
-
let verifyDate = moment(req.query['create_after'])
|
|
476
|
-
if (verifyDate.isValid()) {
|
|
477
|
-
createQuery['$gte'] = verifyDate.toDate()
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
if (_.has(req.query, 'create_before')) {
|
|
482
|
-
let verifyDate = moment(req.query['create_before'])
|
|
483
|
-
if (verifyDate.isValid()) {
|
|
484
|
-
createQuery['$lte'] = verifyDate.toDate()
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (!_.isEmpty(createQuery)) {
|
|
488
|
-
searchCondition['created_on'] = createQuery
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// updated_after/updated_before - assign preset updated_on date
|
|
492
|
-
let updateQuery = {}
|
|
493
|
-
if (_.has(req.query, 'update_after')) {
|
|
494
|
-
let verifyDate = moment(req.query['update_after'])
|
|
495
|
-
if (verifyDate.isValid()) {
|
|
496
|
-
updateQuery['$gte'] = verifyDate.toDate()
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if (_.has(req.query, 'update_before')) {
|
|
500
|
-
let verifyDate = moment(req.query['update_before'])
|
|
501
|
-
if (verifyDate.isValid()) {
|
|
502
|
-
updateQuery['$lte'] = verifyDate.toDate()
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (!_.isEmpty(updateQuery)) {
|
|
506
|
-
searchCondition['updated_on'] = updateQuery
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// Build license_tier query rule, default would be license_tier: null
|
|
510
|
-
// The detail of the rule can jump to _buildLicenseTierQuery
|
|
511
|
-
if (_.has(req.query, 'license_tier')) {
|
|
512
|
-
const tmpQuery = _.clone(searchCondition)
|
|
513
|
-
searchCondition = _.merge(tmpQuery, _buildLicenseTierQuery(req.query['license_tier']))
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (_.has(req.query, 'order') && req.query.order === 'hot') {
|
|
517
|
-
searchCondition = _.assign({}, searchCondition, { created_on: { $gte: moment().subtract(1, 'month').toDate() } })
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// signal_chain_type query only works in Spark for now
|
|
521
|
-
if (searchCondition.preset_for === 'spark') {
|
|
522
|
-
if (_.has(req.query, 'signal_chain_type')) {
|
|
523
|
-
searchCondition.signal_chain_type = req.query.signal_chain_type
|
|
524
|
-
}
|
|
525
|
-
if (_.has(req.query, 'no_dspid')) {
|
|
526
|
-
searchCondition['preset_meta.dspId'] = { $nin: String(req.query.no_dspid).split(',') }
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
searchCondition = _handlePresetVersion(searchCondition, req)
|
|
531
|
-
|
|
532
|
-
debug('getPresetsBySearch:full_text %j %j', searchCondition, sortCondition)
|
|
533
|
-
if (
|
|
534
|
-
_.has(req, 'query.keyword') &&
|
|
535
|
-
!_.isEmpty(req.query.keyword)
|
|
536
|
-
) {
|
|
537
|
-
let result
|
|
538
|
-
// China cannot use Atlas Search, so we need to keep it used the old solution before find an alternative on Aliyun
|
|
539
|
-
if (_.has(process.env, 'IS_CHINA')) {
|
|
540
|
-
searchCondition['$or'] = [
|
|
541
|
-
{ 'name': new RegExp(`^${filterKeyword(req.query['keyword'])}`, 'i') },
|
|
542
|
-
{ 'description': new RegExp(`${filterKeyword(req.query['keyword'])}`, 'i') }
|
|
543
|
-
]
|
|
544
|
-
result = await this.aggregate([{
|
|
545
|
-
$match: _queryCompatibilityHandler(searchCondition)
|
|
546
|
-
}, {
|
|
547
|
-
$sort: sortCondition
|
|
548
|
-
}, {
|
|
549
|
-
$project: selectOps
|
|
550
|
-
}, {
|
|
551
|
-
$skip: ((pageParams.page - 1) * pageParams.page_size)
|
|
552
|
-
}, {
|
|
553
|
-
$limit: pageParams.page_size
|
|
554
|
-
}, {
|
|
555
|
-
$addFields: {
|
|
556
|
-
id: '$_id'
|
|
557
|
-
}
|
|
558
|
-
}])
|
|
559
|
-
} else {
|
|
560
|
-
result = await this.aggregate([{
|
|
561
|
-
$search: {
|
|
562
|
-
text: {
|
|
563
|
-
path: ['name', 'description'],
|
|
564
|
-
query: req.query.keyword
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
$match: _queryCompatibilityHandler(searchCondition)
|
|
569
|
-
}, {
|
|
570
|
-
$sort: sortCondition
|
|
571
|
-
}, {
|
|
572
|
-
$project: selectOps
|
|
573
|
-
}, {
|
|
574
|
-
$skip: ((pageParams.page - 1) * pageParams.page_size)
|
|
575
|
-
}, {
|
|
576
|
-
$limit: pageParams.page_size
|
|
577
|
-
}, {
|
|
578
|
-
$addFields: {
|
|
579
|
-
id: '$_id'
|
|
580
|
-
}
|
|
581
|
-
}])
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
return result
|
|
585
|
-
} else {
|
|
586
|
-
const result = await this.aggregate([{
|
|
587
|
-
$match: _queryCompatibilityHandler(searchCondition)
|
|
588
|
-
}, {
|
|
589
|
-
$sort: sortCondition
|
|
590
|
-
}, {
|
|
591
|
-
$project: selectOps
|
|
592
|
-
}, {
|
|
593
|
-
$skip: ((pageParams.page - 1) * pageParams.page_size)
|
|
594
|
-
}, {
|
|
595
|
-
$limit: pageParams.page_size
|
|
596
|
-
}, {
|
|
597
|
-
$addFields: {
|
|
598
|
-
id: '$_id'
|
|
599
|
-
}
|
|
600
|
-
}])
|
|
601
|
-
|
|
602
|
-
return result
|
|
603
|
-
}
|
|
604
|
-
},
|
|
605
|
-
getPresetsList: function (query, sort, req, cb) {
|
|
606
|
-
let pageParams = parsePageParams(req.query)
|
|
607
|
-
|
|
608
|
-
// only select preset status == 0
|
|
609
|
-
if (_.isObject(query)) {
|
|
610
|
-
query['status'] = 0
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
if (_.has(query, 'preset_for') && query['preset_for'] !== 'jamup') {
|
|
614
|
-
query['image_url'] = { $ne: null }
|
|
615
|
-
query['thumb_url'] = { $ne: null }
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
if (_.has(req.query, 'license_tier')) {
|
|
619
|
-
const tmpQuery = _.clone(query)
|
|
620
|
-
query = _.merge(tmpQuery, _buildLicenseTierQuery(req.query['license_tier']))
|
|
621
|
-
}
|
|
622
|
-
if (_.has(req.query, 'order')) {
|
|
623
|
-
sort = _buildSortQuery(req.query.order)
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
query = _handlePresetVersion(query, req)
|
|
627
|
-
debug('getPresetsList:%j', query)
|
|
628
|
-
this.find(_queryCompatibilityHandler(query))
|
|
629
|
-
.sort(sort)
|
|
630
|
-
.select('-preset_data')
|
|
631
|
-
.skip((pageParams['page'] - 1) * pageParams['page_size'])
|
|
632
|
-
.limit(pageParams['page_size'])
|
|
633
|
-
.exec(cb)
|
|
634
|
-
},
|
|
635
|
-
getPresetsListPromise: function (query, sort, req) {
|
|
636
|
-
const self = this
|
|
637
|
-
return new Promise((resolve, reject) => {
|
|
638
|
-
this.getPresetsList(query, sort, req, (err, likes) => {
|
|
639
|
-
return (err) ? reject(err) : resolve(likes)
|
|
640
|
-
})
|
|
641
|
-
})
|
|
642
|
-
},
|
|
643
|
-
getMyPresets: function (query, sort, req, cb) {
|
|
644
|
-
let pageParams = parsePageParams(req.query)
|
|
645
|
-
|
|
646
|
-
if (_.isObject(query)) {
|
|
647
|
-
query['status'] = { $in: [0, 2] }
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if (_.has(query, 'preset_for') && query['preset_for'] !== 'jamup') {
|
|
651
|
-
query['image_url'] = { $ne: null }
|
|
652
|
-
query['thumb_url'] = { $ne: null }
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
query = _handlePresetVersion(query, req)
|
|
656
|
-
debug('getMyPresets:%o', query)
|
|
657
|
-
this.find(_queryCompatibilityHandler(query))
|
|
658
|
-
.sort(sort)
|
|
659
|
-
.select('-preset_data')
|
|
660
|
-
.skip((pageParams['page'] - 1) * pageParams['page_size'])
|
|
661
|
-
.limit(pageParams['page_size'])
|
|
662
|
-
.exec(cb)
|
|
663
|
-
},
|
|
664
|
-
getOnePresetByCondition: function (query, opts, cb) {
|
|
665
|
-
let defaultSort = (_.has(opts, 'sort') && _.isObject(opts.sort)) ? opts.sort : { created_on: -1 }
|
|
666
|
-
let defaultSelect = (_.has(opts, 'select') && _.isString(opts.select)) ? opts.select : ''
|
|
667
|
-
|
|
668
|
-
this.findOne(_queryCompatibilityHandler(query))
|
|
669
|
-
.sort(defaultSort)
|
|
670
|
-
.select(defaultSelect)
|
|
671
|
-
.exec(cb)
|
|
672
|
-
},
|
|
673
|
-
getSinglePreset: function (id, cb) {
|
|
674
|
-
this.findOne({ '_id': id, 'status': 0 }).exec(cb)
|
|
675
|
-
},
|
|
676
|
-
getValidSinglePreset: function (id, cb) {
|
|
677
|
-
this.findOne({ '_id': id, 'status': { $in: [0, 2, 3] } }).exec(cb)
|
|
678
|
-
}
|
|
679
|
-
})
|
|
680
|
-
|
|
681
|
-
PresetUserComment.static({
|
|
682
|
-
getPresetComments: async function (presetId, req) {
|
|
683
|
-
try {
|
|
684
|
-
const pageParams = parsePageParams(req.query)
|
|
685
|
-
const ret = await this.aggregate([
|
|
686
|
-
{ $match: { preset_id: mongoose.Types.ObjectId(presetId), status: 1 } },
|
|
687
|
-
{ $sort: { date_comment: -1 } },
|
|
688
|
-
{ $skip: (pageParams['page'] - 1) * pageParams['page_size'] },
|
|
689
|
-
{ $limit: pageParams['page_size'] },
|
|
690
|
-
{
|
|
691
|
-
$lookup: {
|
|
692
|
-
from: 'auth_user',
|
|
693
|
-
localField: 'user_id',
|
|
694
|
-
foreignField: '_id',
|
|
695
|
-
as: 'tmpUser'
|
|
696
|
-
}
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
$lookup: {
|
|
700
|
-
from: 'jamup_userprofile',
|
|
701
|
-
localField: 'user_id',
|
|
702
|
-
foreignField: 'user_id',
|
|
703
|
-
as: 'tmpProfile'
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
{ $unwind: '$tmpUser' },
|
|
707
|
-
{ $unwind: '$tmpProfile' },
|
|
708
|
-
{
|
|
709
|
-
$project: {
|
|
710
|
-
preset_id: 1,
|
|
711
|
-
comment_text: 1,
|
|
712
|
-
date_comment: 1,
|
|
713
|
-
user: {
|
|
714
|
-
_id: '$tmpUser._id',
|
|
715
|
-
email: '$tmpUser.email',
|
|
716
|
-
date_joined: '$tmpUser.date_joined',
|
|
717
|
-
full_name: '$tmpProfile.full_name',
|
|
718
|
-
first_name: '$tmpProfile.first_name',
|
|
719
|
-
last_name: '$tmpProfile.last_name',
|
|
720
|
-
profile_image_url: '$tmpProfile.profile_image_url',
|
|
721
|
-
profile_thumb_url: '$tmpProfile.profile_thumb_url'
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
]).exec()
|
|
726
|
-
|
|
727
|
-
return ret
|
|
728
|
-
} catch (err) {
|
|
729
|
-
debug('ERR:getPresetComment:%o', err)
|
|
730
|
-
throw err
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
})
|
|
734
|
-
|
|
735
|
-
PresetUserLike.static({
|
|
736
|
-
getCountByPresetCondition: function (query, condition, cb) {
|
|
737
|
-
this.find(query)
|
|
738
|
-
.populate('preset_id')
|
|
739
|
-
.exec((err, result) => {
|
|
740
|
-
debug('getCountByPresetCondition', query, condition, result, result.length)
|
|
741
|
-
if (err) {
|
|
742
|
-
return cb(err)
|
|
743
|
-
} else {
|
|
744
|
-
let filterVal = _.filter(result, (item) => {
|
|
745
|
-
let tmpObj = item.toObject()
|
|
746
|
-
return _.has(tmpObj['preset_id'], condition)
|
|
747
|
-
})
|
|
748
|
-
return cb(null, filterVal.length)
|
|
749
|
-
}
|
|
750
|
-
})
|
|
751
|
-
},
|
|
752
|
-
getPresetLikeList: function (query, sort, req, cb) {
|
|
753
|
-
const pageParams = parsePageParams(req.query)
|
|
754
|
-
const defaultPresetCondition = {
|
|
755
|
-
'preset.status': { '$eq': 0 }
|
|
756
|
-
}
|
|
757
|
-
let filterQuery = {}
|
|
758
|
-
if (_.has(query, 'no_dspid')) {
|
|
759
|
-
defaultPresetCondition['preset.preset_meta.dspId'] = { '$nin': String(query.no_dspid).split(',') }
|
|
760
|
-
filterQuery = _.omit(query, ['no_dspid'])
|
|
761
|
-
} else {
|
|
762
|
-
filterQuery = _.clone(query)
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
const aggregateQuery = [{
|
|
766
|
-
'$match': _.assign({}, _queryCompatibilityHandler(filterQuery), { user_id: mongoose.Types.ObjectId(filterQuery['user_id']) })
|
|
767
|
-
}, {
|
|
768
|
-
'$lookup': {
|
|
769
|
-
'from': 'jamup_preset',
|
|
770
|
-
'localField': 'preset_id',
|
|
771
|
-
'foreignField': '_id',
|
|
772
|
-
'as': 'preset'
|
|
773
|
-
}
|
|
774
|
-
}, {
|
|
775
|
-
'$unwind': '$preset'
|
|
776
|
-
}, {
|
|
777
|
-
'$match': defaultPresetCondition
|
|
778
|
-
}]
|
|
779
|
-
const presetQuery = _handlePresetVersion({}, req)
|
|
780
|
-
if (_.isEmpty(presetQuery)) {
|
|
781
|
-
debug('getPresetLikeList:%j:%o', aggregateQuery, sort)
|
|
782
|
-
this.aggregate(aggregateQuery)
|
|
783
|
-
.sort({ date_like: -1 })
|
|
784
|
-
.skip((pageParams['page'] - 1) * pageParams['page_size'])
|
|
785
|
-
.limit(pageParams['page_size'])
|
|
786
|
-
.exec(cb)
|
|
787
|
-
} else {
|
|
788
|
-
if (_.has(presetQuery, '$and') && _.isArray(presetQuery['$and'])) {
|
|
789
|
-
_.forEach(presetQuery['$and'], item => {
|
|
790
|
-
let newQuery = { '$match': {} }
|
|
791
|
-
const objKey = _.keys(item)
|
|
792
|
-
const objVal = _.values(item)
|
|
793
|
-
if (objKey.length === 1 && objVal.length === 1) {
|
|
794
|
-
newQuery['$match'][`preset.${objKey[0]}`] = objVal[0]
|
|
795
|
-
aggregateQuery.push(newQuery)
|
|
796
|
-
}
|
|
797
|
-
})
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
debug('getPresetLikeListAggregate:%j:%o:%j', query, sort, aggregateQuery)
|
|
801
|
-
this.aggregate(aggregateQuery)
|
|
802
|
-
.sort({ date_like: -1 })
|
|
803
|
-
.skip((pageParams['page'] - 1) * pageParams['page_size'])
|
|
804
|
-
.limit(pageParams['page_size'])
|
|
805
|
-
.exec(cb)
|
|
806
|
-
}
|
|
807
|
-
},
|
|
808
|
-
getPresetLikeListPromise: function (query, sort, req) {
|
|
809
|
-
const self = this
|
|
810
|
-
return new Promise((resolve, reject) => {
|
|
811
|
-
this.getPresetLikeList(query, sort, req, (err, likes) => {
|
|
812
|
-
return (err) ? reject(err) : resolve(likes)
|
|
813
|
-
})
|
|
814
|
-
})
|
|
815
|
-
}
|
|
816
|
-
})
|
|
817
|
-
|
|
818
|
-
PresetSchema.virtual('id').get(function () {
|
|
819
|
-
return this._id.toHexString()
|
|
820
|
-
})
|
|
821
|
-
PresetSchema.virtual('preset_version')
|
|
822
|
-
.get(function () {
|
|
823
|
-
return (Number.isInteger(this.version.major) &&
|
|
824
|
-
Number.isInteger(this.version.minor))
|
|
825
|
-
? `${this.version.major}.${this.version.minor}`
|
|
826
|
-
: '1.0'
|
|
827
|
-
})
|
|
828
|
-
.set(function (presetVersion) {
|
|
829
|
-
this._versionDetail = presetVersion.split('.')
|
|
830
|
-
const major = this._versionDetail[0]
|
|
831
|
-
const minor = this._versionDetail[1]
|
|
832
|
-
|
|
833
|
-
this.set('version.major', parseInt(major, 10))
|
|
834
|
-
this.set('version.minor', parseInt(minor, 10))
|
|
835
|
-
})
|
|
836
|
-
|
|
837
|
-
mongoose.model('Preset', PresetSchema)
|
|
838
|
-
mongoose.model('PresetComment', PresetUserComment)
|
|
839
|
-
mongoose.model('PresetLike', PresetUserLike)
|
|
840
|
-
mongoose.model('PresetDownload', PresetUserDownload)
|
|
841
|
-
mongoose.model('PopularPresetList', PopularPresetList)
|
|
842
|
-
mongoose.model('FakePresetLike', FakePresetLikeSchema)
|
|
843
|
-
mongoose.model('PresetTagsMeta', PresetTagsMetaSchema)
|
|
844
|
-
mongoose.model('PresetSongMapping', PresetSongMappingSchema)
|
|
845
|
-
}
|