forked from svt/bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
63 lines (55 loc) · 1.41 KB
/
server.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
59
60
61
62
63
// SPDX-FileCopyrightText: 2025 Sveriges Television AB
//
// SPDX-License-Identifier: MIT
const DIController = require('../shared/DIController')
class Server {
#props
/**
* Uris for
* static assets
*
* @type {{
* STYLE_RESET: String
* }}
*/
get uris () {
return Object.freeze({
STYLE_RESET: '/bridge.bundle.css'
})
}
constructor (props) {
this.#props = props
}
/**
* Serve a static file
* through the web server
* @param { String } filePath An absolute path to the file to serve
* @returns { Promise.<String> } A path to the file as served by the web server
*/
serveFile (filePath) {
return this.#props.Commands.executeCommand('server.serveFile', filePath)
.then(hash => `/api/v1/serve/${hash}`)
}
/**
* Serve a string as a static file
* through the web server
* @param { String } str A string to serve as a file
* @returns { Promise.<String> } A path to the file as served by the web server
*/
serveString (str) {
return this.#props.Commands.executeCommand('server.serveString', str)
.then(hash => `/api/v1/serve/${hash}`)
}
/**
* Stop serving a file through
* the web server by its id
* @param { String } id
* @returns { Promise.<Boolean> }
*/
unserve (id) {
return this.#props.Commands.executeCommand('server.unserve', id)
}
}
DIController.main.register('Server', Server, [
'Commands'
])