Permalink
Browse files

fix(server): use changed style of mongoose connection

  • Loading branch information...
mycoboco committed Aug 14, 2018
1 parent 3a23b12 commit 26dd28ca6f56e0a7197d1dfc018ce48639ad6a74
Showing with 43 additions and 33 deletions.
  1. +19 −14 server/lib/db.mongo.js
  2. +24 −19 server/server.js
View
@@ -13,7 +13,7 @@ var mongoose = require('mongoose'),
var grid = require('gridfs-stream')
var hodgepodge = {
logger: require('hodgepodge-node/logger'),
mongoose: require('hodgepodge-node/mongoose')
mongoose: require('hodgepodge-node/mongoose')(mongoose)
}
var infoSchema = new Schema({
@@ -24,7 +24,7 @@ var infoSchema = new Schema({
version: Number,
dbId: String
}),
Info = mongoose.model('Info', infoSchema)
Info
var songSchema = new Schema({
id: {
@@ -47,10 +47,10 @@ var songSchema = new Schema({
path: String,
mtime: Date
}),
Song = mongoose.model('Song', songSchema)
Song
var log, gfs, conf
var log, db, gfs, conf
function init(_conf, cb) {
@@ -71,19 +71,26 @@ function init(_conf, cb) {
level: (conf.debug)? 'info': 'error'
})
hodgepodge.mongoose = hodgepodge.mongoose(mongoose, log)
hodgepodge.mongoose.connect(conf.db)
hodgepodge.mongoose.init(log)
hodgepodge.mongoose.connect(conf.db, function (err, _db) {
if (err) {
cb(err)
return
}
db = _db
Info = db.model('Info', infoSchema)
Song = db.model('Song', songSchema)
grid.mongo = mongoose.mongo
gfs = grid(db.db)
grid.mongo = mongoose.mongo
mongoose.connection.once('open', function () {
gfs = grid(mongoose.connection.db)
cb()
})
}
function close() {
hodgepodge.mongoose.close && hodgepodge.mongoose.close()
hodgepodge.mongoose.close()
}
@@ -260,11 +267,9 @@ function cacheExist(name, metas, cb) {
function cacheClear(cb) {
var db = mongoose.connection.db // uses underlying driver
var funcs = [ 'fs.files', 'fs.chucks' ].map(function (name) {
var funcs = [ 'fs.files', 'fs.chunks' ].map(function (name) {
return function (callback) {
db.collection(name).drop(function (err) {
db.db.collection(name).drop(function (err) { // uses underlying driver
err && log.warning(err)
callback() // errors ignored
})
View
@@ -277,7 +277,30 @@ function usage() {
db.init({
db: conf.db,
debug: conf.server.debug
}, function () {
}, function (err) {
if (err) {
log.error(err)
exit()
}
mdns.init(db, function (err, id) {
err && log.warning(err)
log.info('database id to advertise is '+id)
if (conf.server.mdns === 'auto') {
log.info('detecting tools for service advertisement')
publishService([ 'avahi', 'dns-sd', 'mdns-js' ])
} else if (conf.server.mdns !== 'off') {
if (typeof mdns[conf.server.mdns] === 'function') {
publishService([ conf.server.mdns, 'mdns-js' ])
} else {
log.error('\''+conf.server.mdns+'\' not supported for service advertisement')
log.warning('trying to auto-detect')
publishService([ 'avahi', 'dns-sd', 'mdns-js' ])
}
}
})
api.init(db, daap, {
server: conf.server,
debug: conf.server.debug
@@ -293,24 +316,6 @@ function usage() {
log.info('%s listening on port %s', server.name, conf.server.port)
})
})
mdns.init(db, function (err, id) {
err && log.warning(err)
log.info('database id to advertise is '+id)
if (conf.server.mdns === 'auto') {
log.info('detecting tools for service advertisement')
publishService([ 'avahi', 'dns-sd', 'mdns-js' ])
} else if (conf.server.mdns !== 'off') {
if (typeof mdns[conf.server.mdns] === 'function') {
publishService([ conf.server.mdns, 'mdns-js' ])
} else {
log.error('\''+conf.server.mdns+'\' not supported for service advertisement')
log.warning('trying to auto-detect')
publishService([ 'avahi', 'dns-sd', 'mdns-js' ])
}
}
})
}()
// end of server.js

0 comments on commit 26dd28c

Please sign in to comment.