Last active
August 29, 2015 14:23
-
-
Save deepakkumarsharma/96d253814bf23b84bfea to your computer and use it in GitHub Desktop.
Meteor throw error problem.
This file contains 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
/* Client Side */ | |
Template.cfsUploader.events({ | |
'change #fileInput': function(event, temp) | |
{ | |
uploadFile(event, temp); | |
} | |
}); | |
function uploadFile(event, temp) | |
{ | |
FS.Utility.eachFile(event, function(file) { | |
var fileId; | |
var fsFile = new FS.File(file); | |
fsFile.owner = Meteor.userId(); | |
fsFile.converted = false; | |
fsFile.timeUploaded = new Date(); | |
fsFile.about = "The model " + fsFile.name() + " was uploaded on " + fsFile.timeUploaded; | |
fsFile.thumbnail = new FS.File(); | |
fsFile.lovers = []; | |
Meteor.call('convertFile', fileId, function (error) { | |
if (error.error === "logg") { | |
alert("Error"); | |
} else { | |
ModelFiles.insert(fsFile,function(err,fileObj) { | |
if (err) { | |
sAlert.error("Upload .g or .obj file only"); | |
} else { | |
sAlert.info("File Uploaded, and will appear in file manager after it's converted", {effect: 'flip', onRouteClose: false, stack: false, timeout: 4000, position: 'top'}); | |
Router.go("/description/" +fileObj._id); | |
} | |
}); | |
} | |
}); | |
}); | |
} |
This file contains 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
/* Server Side */ | |
Meteor.methods({ | |
convertFile:function(fileId) | |
{ | |
var sys = Npm.require('sys'), | |
fs = Npm.require('fs'), | |
exec = Npm.require('child_process').exec; | |
var modelObj = ModelFiles.findOne(fileId), | |
readStream = modelObj.createReadStream('modelFiles'), | |
filePath = readStream.path, | |
objects, | |
objPath = [], | |
settings = OgvSettings.findOne(), | |
mgedPath = settings.mgedPath, | |
g_objPath = settings.gobjPath, | |
cmd = mgedPath + " -c " + filePath +" ls -a 2>&1", | |
uploadDirPath = filePath.substring(0, filePath.lastIndexOf("/")); | |
child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { | |
sys.print('stdout' + stdout); | |
objects = stdout.split(" "); | |
console.log(objects); | |
sys.print('stderr' + stderr); | |
if (error != null) { | |
console.log('exec error: ' + error); | |
} else { | |
for (i = 1; i < objects.length; i++) { | |
var counter = 0; | |
(function(i) { | |
objPath[i] = uploadDirPath + "/" + objects[i] + ".obj"; | |
cmd = g_objPath + " -n 10 -o " + objPath[i] + " " + filePath + " " + objects[i]; | |
console.log(cmd); | |
child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { | |
if (error) { | |
throw (new Meteor.Error("logg", "There's some error in converting file" + error)); | |
} else { | |
console.log("File has been converted" + objects[i] + i); | |
objFS = new FS.File(objPath[i]); | |
objFS.gFile = fileId; | |
OBJFiles.insert(objFS, function (err, objFile) { | |
if (err) { | |
console.log(err); | |
} else { | |
counter = counter + 1; | |
var convertPercentage = (counter/(objects.length - 2)) *100; | |
console.log("done " + convertPercentage + " %"); | |
if (convertPercentage > 70) { | |
modelObj.update({$set: {converted: true}}); | |
console.log(modelObj); | |
} else if ( convertPercentage < 70) { | |
throw new Meteor.Error(404, "Cannot convert file"); | |
} else { | |
console.log("aa"); | |
} | |
} | |
}); | |
} | |
})); | |
})(i); | |
} | |
} | |
})); | |
} | |
}); |
This file contains 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
<template name="cfsUploader"> | |
<div class="container"> | |
<h2> Upload File </h2> | |
<p class = "help-text"> Add .g file that you want to upload </p> | |
<input type="file" class="form-control" id="fileInput" accept=".g"/><br /> | |
<div id="dropzone" class="dropzone"> | |
<div class="dropzone-text">Drag and Drop your model here to upload</div> | |
</div> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment