Skip to content

Commit

Permalink
writeInfo stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jan 15, 2011
1 parent 4fa8bd6 commit b881231
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 12 additions & 2 deletions files.js
Expand Up @@ -12,6 +12,7 @@ try {
console.error(e.message); console.error(e.message);
files = []; files = [];
} }

exports.getFiles = function() { exports.getFiles = function() {
return files; return files;
}; };
Expand All @@ -25,6 +26,12 @@ exports.getFile = function(id) {
return r; return r;
}; };


function writeInfo() {
/* TODO: delay */
fs.writeFile(DB_PATH, JSON.stringify(files));
}


var maxId = 0, totalSize = 0; var maxId = 0, totalSize = 0;
files.forEach(function(file) { files.forEach(function(file) {
totalSize += file.size; totalSize += file.size;
Expand Down Expand Up @@ -65,10 +72,11 @@ exports.addFile = function(info) {


info.size = size; info.size = size;
files.unshift(info); files.unshift(info);
fs.writeFile(DB_PATH, JSON.stringify(files)); writeInfo();
}; };
out.discard = function() { out.discard = function() {
this.end(); this.end();

console.log('rm incomplete ' + path); console.log('rm incomplete ' + path);
fs.unlink(path); fs.unlink(path);
}; };
Expand All @@ -77,8 +85,10 @@ exports.addFile = function(info) {


exports.readFile = function(id) { exports.readFile = function(id) {
var info = exports.getFile(id); var info = exports.getFile(id);
if (info) if (info) {
info.downloads++; info.downloads++;
writeInfo();
}


return fs.createReadStream(FILES_PATH + '/' + id); return fs.createReadStream(FILES_PATH + '/' + id);
}; };
1 change: 0 additions & 1 deletion server.js
Expand Up @@ -27,7 +27,6 @@ function app(app) {
mime: part.mime mime: part.mime
} }); } });
var out = files.addFile({ name: part.filename, var out = files.addFile({ name: part.filename,
size: 0 /*TODO*/,
type: part.mime type: part.mime
}); });
var received = 0; var received = 0;
Expand Down

0 comments on commit b881231

Please sign in to comment.