remove-uploaded-files.js 542 B

12345678910111213141516171819202122232425262728
  1. function removeUploadedFiles (uploadedFiles, remove, cb) {
  2. var length = uploadedFiles.length
  3. var errors = []
  4. if (length === 0) return cb(null, errors)
  5. function handleFile (idx) {
  6. var file = uploadedFiles[idx]
  7. remove(file, function (err) {
  8. if (err) {
  9. err.file = file
  10. err.field = file.fieldname
  11. errors.push(err)
  12. }
  13. if (idx < length - 1) {
  14. handleFile(idx + 1)
  15. } else {
  16. cb(null, errors)
  17. }
  18. })
  19. }
  20. handleFile(0)
  21. }
  22. module.exports = removeUploadedFiles