Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
bs893 committed Feb 15, 2021
1 parent a8d5142 commit a41f339
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 96 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const port = 3000;

const nodeSlicer = require("./slicers/slic3r/slic3r");
const prusaSlicer = require("./slicers/prusaslicer/prusaslicer");
const curaEngine = require("./slicers/curaengine/curaengine");
const converter = require("./utils/converter");
const database = require("./utils/database");

Expand Down Expand Up @@ -59,6 +60,8 @@ app.post("/upload/:slicerType", function (req, res) {
slicerToUse = nodeSlicer;
} else if (req.params.slicerType === "prusaslicer") {
slicerToUse = prusaSlicer;
} else if (req.params.slicerType === "curaengine") {
slicerToUse = curaEngine;
} else {
return res.status(500).send("Wrong parameter");
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"clone": "^0.2.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dockerode": "^3.2.1",
"events": "^3.2.0",
"express": "^4.17.1",
"express-fileupload": "^1.1.7-alpha.4",
Expand Down
23 changes: 23 additions & 0 deletions slicers/curaengine/curaengine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var fs = require('fs');
var Docker = require('dockerode');
var docker = new Docker(); //defaults to above if env variables are not used

var nodeCuraEngine = {};

nodeCuraEngine.render = function (options, callback) {

if (options.verbose)
console.log(options)

docker.pull('dimfacion/curaengine:latest', function (err, stream) {
docker.run('dimfacion/curaengine:latest', ['slice', '-j', '/usr/definitions/creality_ender3.def.json', '-l', options.inputFile, '-o', options.outputFile], process.stdout, {"Binds": [ "/tmp:/tmp:rw" ]}, function (err, data, container) {
if (err){
return callback({ message: err })
}

callback()
});
});
}

module.exports = nodeCuraEngine;
59 changes: 11 additions & 48 deletions slicers/prusaslicer/prusaslicer.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,23 @@
var fs = require('fs'),
childProcess = require('child_process'),
var fs = require('fs');
var Docker = require('dockerode');
var docker = new Docker(); //defaults to above if env variables are not used

nodePrusaSlicer = {}

function getShellCommand (o) {

var shellCommand

shellCommand = [
'slic3r-prusa3d',
'--output ' + o.outputFile,

// Output options
o.outputFilenameFormat ?
'--output-filename-format ' + o.outputFilenameFormat : '',

// Transform options
o.scale ? '--scale ' + o.scale : '',
o.rotate ? '--rotate ' + o.rotate : '',
o.duplicate ? '--duplicate ' + o.duplicate : '',
o.duplicateGrid ? '--duplicate-grid ' + o.duplicateGrid : '',
o.duplicateDistance ? '--duplicate-distance ' + o.duplicateDistance : '',

//Input options
o.inputFile ? o.inputFile : '',

//Load config file
o.configFile ? '--load ' + o.configFile : ''
]

return shellCommand.join(' ')
}
nodePrusaSlicer = {}

nodePrusaSlicer.render = function (options, callback) {

var shellCommand

shellCommand = getShellCommand(options)

if (options.verbose)
console.log(shellCommand)

childProcess.exec(
shellCommand,
function (error, stdout, stderr) {
console.log(options)

if (stderr){
return callback({ message: stderr })
docker.pull('dimfacion/prusaslicer', function (err, stream) {
docker.run('dimfacion/prusaslicer', ['-g', options.inputFile], process.stdout, {"Binds": [ "/tmp:/tmp:rw" ]}, function (err, data, container) {
if (err){
return callback({ message: err })
}

if (error)
return callback(error)

callback()
}
)
});
});
}

module.exports = nodePrusaSlicer;
59 changes: 11 additions & 48 deletions slicers/slic3r/slic3r.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,23 @@
var fs = require('fs'),
childProcess = require('child_process'),

nodeSlicer = {}
var fs = require('fs');
var Docker = require('dockerode');
var docker = new Docker(); //defaults to above if env variables are not used

function getShellCommand (o) {

var shellCommand

shellCommand = [
'slic3r',
'--output ' + o.outputFile,

// Output options
o.outputFilenameFormat ?
'--output-filename-format ' + o.outputFilenameFormat : '',

// Transform options
o.scale ? '--scale ' + o.scale : '',
o.rotate ? '--rotate ' + o.rotate : '',
o.duplicate ? '--duplicate ' + o.duplicate : '',
o.duplicateGrid ? '--duplicate-grid ' + o.duplicateGrid : '',
o.duplicateDistance ? '--duplicate-distance ' + o.duplicateDistance : '',

//Input options
o.inputFile ? o.inputFile : '',

//Load config file
o.configFile ? '--load ' + o.configFile : ''
]

return shellCommand.join(' ')
}
var nodeSlicer = {};

nodeSlicer.render = function (options, callback) {

var shellCommand

shellCommand = getShellCommand(options)

if (options.verbose)
console.log(shellCommand)
console.log(options)

childProcess.exec(
shellCommand,
function (error, stdout, stderr) {

if (stderr){
return callback({ message: stderr })
docker.pull('dimfacion/slic3r', function (err, stream) {
docker.run('dimfacion/slic3r', ['--no-gui', options.inputFile], process.stdout, {"Binds": [ "/tmp:/tmp:rw" ]}, function (err, data, container) {
if (err){
return callback({ message: err })
}

if (error)
return callback(error)

callback()
}
)
});
});
}

module.exports = nodeSlicer;

0 comments on commit a41f339

Please sign in to comment.