added handling for development server file system
This commit is contained in:
parent
c271052be3
commit
4be6210134
|
@ -95,18 +95,14 @@ var FormSchema = new Schema({
|
|||
|
||||
},
|
||||
font: String,
|
||||
<<<<<<< HEAD
|
||||
backgroundImage: { type: Schema.Types.Mixed }
|
||||
=======
|
||||
backgroundImage: type: Schema.Types.Mixed
|
||||
>>>>>>> 33243bea2a1f74f8f417b240f5ad068c1d05c6bd
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Delete template PDF of current Form
|
||||
FormSchema.pre('remove', function (next) {
|
||||
if(this.pdf){
|
||||
if(this.pdf && process.env.NODE_ENV === 'development'){
|
||||
//Delete template form
|
||||
fs.unlink(this.pdf.path, function(err){
|
||||
if (err) throw err;
|
||||
|
|
|
@ -106,23 +106,26 @@ UserSchema.virtual('displayName').get(function () {
|
|||
|
||||
//Create folder for user's pdfs
|
||||
UserSchema.pre('save', function (next) {
|
||||
if(!this.username || this.username !== this.email){
|
||||
this.username = this.email;
|
||||
}
|
||||
var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')),
|
||||
stat = null;
|
||||
if(process.env.NODE_ENV === 'development'){
|
||||
if(!this.username || this.username !== this.email){
|
||||
this.username = this.email;
|
||||
}
|
||||
var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')),
|
||||
stat = null;
|
||||
|
||||
try {
|
||||
stat = fs.statSync(newDestination);
|
||||
} catch (err) {
|
||||
fs.mkdirSync(newDestination);
|
||||
}
|
||||
if (stat && !stat.isDirectory()) {
|
||||
// console.log('Directory cannot be created');
|
||||
next( new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"') );
|
||||
}else{
|
||||
next();
|
||||
}
|
||||
try {
|
||||
stat = fs.statSync(newDestination);
|
||||
} catch (err) {
|
||||
fs.mkdirSync(newDestination);
|
||||
}
|
||||
if (stat && !stat.isDirectory()) {
|
||||
// console.log('Directory cannot be created');
|
||||
next( new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"') );
|
||||
}else{
|
||||
next();
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue