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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ try {
console.error(e.message);
files = [];
}

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

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


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

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

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

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

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

0 comments on commit b881231

Please sign in to comment.