Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a way for them to know they need to create a directory.

  • Loading branch information...
commit 2139ede126f867f11a079631130fbb8c3c2f8539 1 parent c8e126f
@travist travist authored
Showing with 24 additions and 9 deletions.
  1. +8 −3 app/controllers/files_controller.js
  2. +16 −6 app/models/file.js
View
11 app/controllers/files_controller.js
@@ -26,9 +26,14 @@ action('create', function () {
action('index', function () {
File.find(function (err, files) {
- this.files = files;
- this.title = 'Files index';
- render();
+ if (err) {
+ send(err);
+ }
+ else {
+ this.files = files;
+ this.title = 'Files index';
+ render();
+ }
}.bind(this));
});
View
22 app/models/file.js
@@ -4,13 +4,23 @@ function File(name) {
this.id = this.name = name;
}
+// The directory to upload files too.
+File.directory = app.root + '/data';
+
File.find = function (cb) {
var files = [];
- fs.readdir(app.root + '/data', function (err, fileNames) {
- fileNames.forEach(function (file) {
- files.push(new File(file));
- });
- cb(err, files);
+ fs.exists(File.directory, function(exists) {
+ if (exists) {
+ fs.readdir(File.directory, function (err, fileNames) {
+ fileNames.forEach(function (file) {
+ files.push(new File(file));
+ });
+ cb(err, files);
+ });
+ }
+ else {
+ cb('You must create the directory ' + File.directory + '.');
+ }
});
};
@@ -23,7 +33,7 @@ File.prototype.remove = function (cb) {
};
File.prototype.filename = function () {
- return app.root + '/data/' + this.name;
+ return File.directory + '/' + this.name;
};
File.prototype.upload = function (name, path, cb) {
Please sign in to comment.
Something went wrong with that request. Please try again.