aboutsummaryrefslogtreecommitdiff
path: root/htdocs/public/metranslator/api/index.ejs
blob: 388331be5454a25b4bc138fa6928dc87d7fd9781 (plain)
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
<%

    res.writeHead(200, {'Content-Type': "application/json"});

    if (get['t']) {
        if (get['t'] === "en") {
            target = "en";
        } else {
            target = "mt";
        }
    } else {
        res.end();
    }

    if (get['u']) {
        text = get['u'];

        if (text.length > 500) {
            res.end();
        }

        text = text.split("\"").join("''");
    } else {
        res.end();
    }

    aw = JSON.parse(child_process.execSync(`cd /mnt/metranslator-api && node index.js api ${target} "${text}"`).toString());
    last = child_process.execSync("cd /mnt/metranslator-api && git log -1 --pretty=format:'%an'").toString()
    aw["system"]["version"] = aw["system"]["version"] + "-" + fs.readFileSync("/mnt/metranslator-api/.git/refs/heads/trunk").toString().substr(0, 8);
    aw["system"]["last_author"] = last;
    aw["call"] = "cd /mnt/metranslator-api && node index.js api {$target} \"{$text}\"";

    %><%- JSON.stringify(aw); %>