// * ———————————————————————————————————————————————————————— * //
// * 	Enduro admin upload handler
// * ———————————————————————————————————————————————————————— * //
var admin_file_upload_handler = function () {}

// vendor dependencies
var Promise = require('bluebird')
var fs = require('fs')

// local dependencies
var enduro_helpers = require(ENDURO_FOLDER + '/libs/flat_utilities/enduro_helpers')
var kiska_logger = require(ENDURO_FOLDER + '/libs/kiska_logger')

// constants
var UPLOADS_FOLDER = '/assets/img/uploaded'

admin_file_upload_handler.prototype.upload = function(file) {
	return new Promise(function(resolve, reject){

		var destination_path = CMD_FOLDER + UPLOADS_FOLDER + '/' + file.name
		var destination_url = UPLOADS_FOLDER + '/' + file.name

		enduro_helpers.ensureDirectoryExistence(destination_path)
			.then(() => {
				//fs.rename(file.path, destination_path, function(err) {
				console.log('copyying file', file.path, destination_path)
				fs.createReadStream(file.path)
					.pipe(fs.createWriteStream(destination_path))
					.on("close", function(err) {
						if(err) {
							console.log(err)
							return reject(err);
						}
						kiska_logger.timestamp('file was uploaded','file_uploading')
						resolve(destination_url)
					});
			})

	})
}


module.exports = new admin_file_upload_handler()
@@ -701,16 +701,96 @@
 le.name%0A
+%09%09var destination_src_path = CMD_FOLDER + UPLOADS_FOLDER + '/_src/' + file.name%0A
 %09%09var de
@@ -838,16 +838,16 @@
 le.name%0A
-
 %0A%09%09endur
@@ -1039,20 +1039,39 @@
 n_path)%0A
+%0A
 %09%09%09%09
+var read_stream = 
 fs.creat
@@ -1093,21 +1093,93 @@
 e.path)%0A
+%0A
 %09%09%09%09
-%09
+read_stream.pipe(fs.createWriteStream(destination_path))%0A%09%09%09%09read_stream
 .pipe(fs
@@ -1201,32 +1201,36 @@
 eam(destination_
+src_
 path))%0A%09%09%09%09%09.on(

split img upload stream upload into two output streams