Skip to content

Commit

Permalink
Add first removal functionality
Browse files Browse the repository at this point in the history
Still requires a restart of the app before changes are applied
  • Loading branch information
jacobrask committed Jan 7, 2012
1 parent ef2b1ae commit 39aed18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/db.coffee
Expand Up @@ -7,7 +7,7 @@ _ = require './utils'

db = new Db 'bragi-mediaserver',
new Server 'localhost',
Connection.DEFAULT_PORT
Connection.DEFAULT_PORT

exports.init = (cb = ->) ->
db.open (err) ->
Expand All @@ -31,7 +31,11 @@ action = (collName, errback, callback) ->
callback coll

add = (collName, obj, cb) -> action collName, cb, (coll) ->
coll.insert obj, safe: true, cb
obj2 = _.clone obj
coll.findAndModify obj2, [['_id', 'asc']], { $set: obj2 }, { safe: on, upsert: on, new: yes }, cb

remove = (collName, obj, cb) -> action collName, cb, (coll) ->
coll.remove obj, cb

update = (collName, filter, updateAction, cb) -> action collName, cb, (coll) ->
coll.update filter, updateAction, safe: true, cb
Expand All @@ -48,6 +52,9 @@ getProperty = (filter, prop, cb) ->
exports.addPath = (path, cb) ->
add 'paths', { path }, cb

exports.removePath = (path, cb) ->
remove 'paths', { path }, cb

exports.getPath = (id, cb) ->
getProperty { _id: new ObjectID id.toString() }, 'path', cb

Expand Down
7 changes: 7 additions & 0 deletions lib/web.coffee
Expand Up @@ -42,6 +42,13 @@ io.sockets.on 'connection', (socket) ->
media.addPath dir, cb
(err) -> console.log err.message if err?

socket.on 'removePath', (root, cb) ->
files.traverse root,
(dir, cb) ->
db.removePath dir, cb
(err) -> console.log err.message if err?


app.get '/', (req, res) ->
getDirData '/', (err, dirs) ->
res.render 'index', { dirs }
Expand Down

0 comments on commit 39aed18

Please sign in to comment.