Skip to content
Browse files

writeInfo stuff

  • Loading branch information...
1 parent 4fa8bd6 commit b881231453168b00f57935fa0da81cc8931b3334 @astro astro committed Jan 15, 2011
Showing with 12 additions and 3 deletions.
  1. +12 −2 files.js
  2. +0 −1 server.js
View
14 files.js
@@ -12,6 +12,7 @@ try {
console.error(e.message);
files = [];
}
+
exports.getFiles = function() {
return files;
};
@@ -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;
@@ -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);
};
@@ -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);
};
View
1 server.js
@@ -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;

0 comments on commit b881231

Please sign in to comment.
Something went wrong with that request. Please try again.