-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (74 loc) · 2.06 KB
/
Copy pathindex.js
File metadata and controls
91 lines (74 loc) · 2.06 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import cors from 'cors';
import dotenv from "dotenv";
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import main from './src/main.js';
dotenv.config()
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const app = express()
const port = process.env.PORT || 3000
await main.init()
app.use(cors())
app.use(express.json());
app.use("/static", express.static(path.join(__dirname, 'manager/build')));
app.get('/', (req, res) => {
console.log("revieved message")
res.send(200)
})
app.get('/keyboard/get', async (req, res) => {
console.log('getting themes')
res.json({
themes: main.keyboard.themeStore.getAll(),
current: main.keyboard.themeStore.findById(main.keyboard.currentTheme)
})
})
app.post('/keyboard/delete', async (req, res) => {
const {_id} = req.body
if (_id) {
const result = main.keyboard.deleteTheme(_id)
if (result) {
return res.send(200)
}
}
res.send(400)
})
app.get('/keyboard/set/:id', async (req, res) => {
console.log(req.params)
const theme = req.params.id
if (!theme) {
res.send(400)
} else {
// ensure theme exists
await main.keyboard.setTheme(theme)
}
res.send(200)
})
app.get('/keyboard/reset', async (req, res) => {
main.keyboard.removeTheme()
res.send(200)
})
app.post('/keyboard/install', async (req, res) => {
const {_id, url, name} = req.body
if (url && name) {
const result = await main.keyboard.installTheme({_id, url, name})
if (result) {
res.send(200)
} else {
res.send(500)
}
}
})
// keyboard theme handling ready
app.get('/internal/keyboard/ready', async (req, res) => {
// ensure theme exists
console.log("keyboard theme loading ready")
await main.keyboard.loadCurrentTheme()
res.send(200)
})
app.use("/static/*", (req, res) => {
res.sendFile(path.resolve(__dirname, "manager/build", "index.html"))
})
app.listen(port, () => {
console.log(`Listening ${port}`)
})