1
0
Fork 0
peertube/server/models/poolRequests.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict'
2016-02-04 15:10:33 -05:00
2016-03-16 17:29:27 -04:00
const mongoose = require('mongoose')
2016-02-04 15:10:33 -05:00
2016-03-16 17:29:27 -04:00
const logger = require('../helpers/logger')
2016-02-04 15:10:33 -05:00
// ---------------------------------------------------------------------------
2016-02-04 15:10:33 -05:00
2016-03-16 17:29:27 -04:00
const poolRequestsSchema = mongoose.Schema({
type: String,
id: String, // Special id to find duplicates (video created we want to remove...)
request: mongoose.Schema.Types.Mixed
})
2016-03-16 17:29:27 -04:00
const PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
2016-02-04 15:10:33 -05:00
// ---------------------------------------------------------------------------
2016-02-04 15:10:33 -05:00
2016-03-16 17:29:27 -04:00
const PoolRequests = {
create: create,
findById: findById,
list: list,
removeRequestById: removeRequestById,
removeRequests: removeRequests
}
2016-02-04 15:10:33 -05:00
function create (id, type, request, callback) {
PoolRequestsDB.create({ id: id, type: type, request: request }, callback)
}
2016-02-04 15:10:33 -05:00
function findById (id, callback) {
PoolRequestsDB.findOne({ id: id }, callback)
}
2016-02-04 15:10:33 -05:00
function list (callback) {
PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback)
}
2016-02-04 15:10:33 -05:00
function removeRequestById (id, callback) {
PoolRequestsDB.remove({ id: id }, callback)
}
function removeRequests (ids) {
PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
if (err) {
logger.error('Cannot remove requests from the pool requests database.', { error: err })
return // Abort
}
2016-02-04 15:10:33 -05:00
logger.info('Pool requests flushed.')
})
}
2016-02-04 15:10:33 -05:00
// ---------------------------------------------------------------------------
2016-02-04 15:10:33 -05:00
module.exports = PoolRequests