-
Notifications
You must be signed in to change notification settings - Fork 5
/
ui.js
60 lines (51 loc) · 1.43 KB
/
ui.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
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
const { join } = require("path");
const { existsSync } = require("fs");
const {
queueSave,
customLocations
} = require("./utils");
const pathname = "/infinityjournal/";
const getId = (() => { let id = 0; return () => id++; })();
const paramRegex = /(\d*)(\D*)/;
function getData(param) {
const data = param.match(paramRegex);
data.shift();
return data;
}
function api(req, res) {
const api = getData(req.params[0]);
switch(api[1]) {
case "L":
return res.status(200).json(customLocations);
case "T":
if (this.slotAtlas !== -1) {
this.tpTo = customLocations[Number(api[0])];
this.send("C_USE_PREMIUM_SLOT", 1, this.slotAtlas);
return res.status(200).json({ close: 1 });
}
else {
return res.status(200).json({ close: "You must have Elite status to teleport to a custom location." });
}
case "D":
customLocations.splice(Number(api[0]), 1);
queueSave();
return res.status(200).json("ok");
default:
return res.status(404).send("404");
}
}
function open() {
this.ui.open(`${pathname}${this.id}/`);
}
function webui(mod, ctx) {
const path = join(__dirname, "..", "ui", "index.js");
if (!existsSync(path)) return;
const UI = require(path);
const ui = UI(mod);
const id = getId();
ui.use(`${pathname}${id}/`, UI.static(join(__dirname, "ui")));
ui.get(`${pathname}${id}/api/*`, api.bind(ctx));
ctx.webui = { ui, id, open };
}
module.exports = webui;