1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
;(function () {
'use strict'
var config = require('config')
var mongoose = require('mongoose')
var constants = require('./constants')
var logger = require('./logger')
var dbname = 'peertube' + config.get('database.suffix')
var host = config.get('database.host')
var port = config.get('database.port')
// ----------- Videos -----------
var videosSchema = mongoose.Schema({
name: String,
namePath: String,
description: String,
magnetUri: String,
podUrl: String
})
var VideosDB = mongoose.model('videos', videosSchema)
// ----------- Pods -----------
var podsSchema = mongoose.Schema({
url: String,
publicKey: String,
score: { type: Number, max: constants.FRIEND_BASE_SCORE }
})
var PodsDB = mongoose.model('pods', podsSchema)
// ----------- PoolRequests -----------
var poolRequestsSchema = mongoose.Schema({
type: String,
id: String, // Special id to find duplicates (video created we want to remove...)
request: mongoose.Schema.Types.Mixed
})
var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
// ----------- Connection -----------
mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
mongoose.connection.on('error', function () {
logger.error('Mongodb connection error.')
process.exit(0)
})
mongoose.connection.on('open', function () {
logger.info('Connected to mongodb.')
})
// ----------- Export -----------
module.exports = {
VideosDB: VideosDB,
PodsDB: PodsDB,
PoolRequestsDB: PoolRequestsDB
}
})()
|