Created
July 7, 2012 10:11
-
-
Save schamane/3065732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseRequestForMultipartFiles(req, arg, callback){ | |
var form = new formidable.IncomingForm(); | |
fs.mkdir(GLOBAL.basePthToSave + arg, function(e) { | |
form.uploadDir = GLOBAL.basePthToSave + arg; | |
form.parse(req, function(err, fields, files){ | |
callback(files); | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uploadPhoto : function(arg, req, cookies, callback){ | |
var callback = callback || function() {}; | |
userDao.getSession(cookies["JAUTHCOOKIE"], function(session, result){ | |
// Check session | |
if(!result || !session.length){ | |
this._askForAuth(callback); | |
return; | |
} | |
// Session valid | |
console.log("Session valid"); | |
arg = decrypt(arg); | |
if(!arg.length){ | |
// arg empty | |
this._renderError(callback, 'Извините, произошла ошибка.'); | |
return; | |
} | |
// arg valid | |
console.log("arg valid"); | |
parseRequestForMultipartFiles(req, arg, function(files){ | |
this._gotUploadedFiles(files, callback); | |
}); // upload files | |
}); // UserDao getSession | |
}, | |
_gotUploadedFiles: function(files, callback) { | |
console.log(files); | |
if(!files.length){ | |
// Files upload failed | |
this._renderError(callback, 'Не удалось загрузить выбранные файлы. Попробуйте еще раз.'); | |
return; | |
} | |
// lst files valid | |
albumsDao.addPhotoToAlbum(cookies["JAUTHCOOKIE"], files, function(dd, result){ | |
if(!result){ | |
// Error addPhotoToAlbum | |
this._renderError(callback, 'Извините, произошла ошибка.'); | |
return; | |
} | |
// Files added success | |
var data = { | |
title: 'Успешно', | |
msg: 'Файлы были загружены.', | |
user: dd[0].user | |
}; | |
view.renderView("success", data, function(data){ | |
callback(data, cookies); | |
}); | |
}); // albumsDao addPhotoToAlbum | |
}, | |
_renderError: function(callback, msg) { | |
var data = { | |
title: 'Ошибка', | |
msg: msg, | |
user: session[0].user | |
}; | |
view.renderView("error", data, function(data){ | |
callback(data, cookies); | |
}); | |
}, | |
_askForAuth: function(callback) { | |
var data = { | |
title: 'Авторизация', | |
}; | |
view.renderView("login", data, function(data){ | |
callback(data, cookies); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment