-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (37 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const colors = require("colors");
const express = require("express");
const fs = require("fs");
const VirtualMachine = require("scratch-vm");
const process = require("process");
const PORT = process.env.PORT || 3000;
// Mute consoles because of scratch-vm's overuse thereof
console.log = () => {};
/* Converts an individual project from SB2 to SB3.
* Takes in an sb2 data structure and options.
*
* Returns an sb3 data structure. False if failed.
*/
let convert = function(sb2, options, res) {
if (options["verbose"]) {
console.log("Converting".blue);
}
let vm = new VirtualMachine();
vm.setCompatibilityMode(true);
vm.clear();
let loaded = vm.loadProject(sb2);
loaded.then(() => {
res.json(vm.toJSON());
}).catch(() => {
console.log("Trouble".red);
res.json(false);
});
};
let app = express();
app.use(express.json());
app.post("/convert", function(req, res){
convert(req.body, {"verbose": true}, res);
});
// Listen on port
app.listen(PORT);
console.log("Now listening on port", PORT + ".");
console.log("Hit CTRL-C to exit server application.");