-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADDED: The start of a storage module
- Loading branch information
Chris Cartlidge
authored and
Chris Cartlidge
committed
Jan 8, 2015
1 parent
cf97017
commit 7347f6c
Showing
6 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var util = require('util'); | ||
var fs = require('fs'); | ||
|
||
Storage = function (root, tenant, domain) { | ||
this.root = root; | ||
this.tenant = tenant; | ||
this.domain = domain; | ||
}; | ||
|
||
var getPath = function(context, address, name){ | ||
if (name === undefined){ | ||
return util.format( | ||
'/%s/%s/%s/%s/', | ||
context.root, | ||
context.tenant, | ||
context.domain, | ||
address); | ||
}else { | ||
return util.format( | ||
'/%s/%s/%s/%s/%s', | ||
context.root, | ||
context.tenant, | ||
context.domain, | ||
address, | ||
name); | ||
} | ||
} | ||
|
||
Storage.prototype.getAll = function (address, callback) { | ||
var path = getPath(this, address); | ||
this.exists(address, function(){ | ||
fs.readdir(path, function(err, files){ | ||
for(var file in files){ | ||
console.dir(file); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
Storage.prototype.get = function (address, name, callback) { | ||
}; | ||
|
||
Storage.prototype.add = function (stream, address, name, callback) { | ||
|
||
}; | ||
|
||
Storage.prototype.exists = function (address, success, fail) { | ||
fs.exists(getPath(this, address), function (exists) { | ||
if (exists) { | ||
success(); | ||
} | ||
else { | ||
fail() | ||
}; | ||
}); | ||
}; | ||
|
||
|
||
|
||
module.exports = Storage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var express = require('express'); | ||
var multer = require('multer'); | ||
var storage = require('../modules/storage/storage'); | ||
var router = express.Router(); | ||
|
||
/* GET home page. */ | ||
router.post('/upload', function(req, res) { | ||
|
||
var bob = new Storage('/Users/chriscartlidge/storage/', 'hello', 'world'); | ||
|
||
bob.getAll('8ab99f6f-e5cf-4b32-a051-551e1bf3a3fa',function(){}); | ||
|
||
console.dir(req.files); | ||
res.end("File uploaded."); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters