server: fix @imports from theme (don't serve it from osc_asset dir to let imports load from user locations)

This commit is contained in:
jean-emmanuel 2026-01-09 09:28:32 +01:00
parent 750f89b6ce
commit a425d8156c
2 changed files with 75 additions and 76 deletions

View file

@ -10,7 +10,7 @@
<meta name="theme-color" content="black">
<link rel="apple-touch-icon" href="/__APP_DIR__/assets/logo.png" />
<link rel="stylesheet" type="text/css" href="/__APP_DIR__/assets/open-stage-control.css" hot-reload/>
<link rel="stylesheet" type="text/css" href="/__APP_DIR__/assets/theme.css" hot-reload/>
<link rel="stylesheet" type="text/css" href="/__APP_THEME__.css" hot-reload/>
<link rel="stylesheet" type="text/css" href="/__APP_DIR__/assets/fonts/fontawesome.min.css"/>
<link rel="stylesheet" type="text/css" href="/__APP_DIR__/assets/fonts/fa-solid.css"/>
<link rel="stylesheet" type="text/css" href="/__APP_DIR__/assets/fonts/roboto.css"/>

View file

@ -154,6 +154,9 @@ class WebServer extends EventEmitter {
var url = req.url
if (url === '/qrcode'){
// qrcode image
res.setHeader('Content-Type', 'image/svg+xml')
let str = this.qrcode,
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
@ -162,6 +165,8 @@ class WebServer extends EventEmitter {
} else if (url === '/' || url.indexOf('/?') === 0) {
// index.html
var ip = req.connection.remoteAddress.replace('::ffff:', '')
var clientOptions = {}
@ -184,99 +189,93 @@ class WebServer extends EventEmitter {
</script></body>`))
.pipe(res)
} else if (url.indexOf('__APP_THEME__.css') != -1) {
// user theme(s)
res.setHeader('Content-Type', 'text/css')
var etag = settings.read('theme') ? theme.hash : 'empty-theme'
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('ETag', etag)
if (req.headers['if-none-match'] && req.headers['if-none-match'] === etag) {
res.statusCode = 304
res.end()
return
}
if (settings.read('theme')) {
let str = theme.get(),
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
res.write(buf)
} else {
res.write('')
}
res.end()
} else if (url.match(/^\/+__APP_DIR__\//)) {
// osc asset files
try {
res.sendFile(path.resolve(__dirname + '/../../' + url.replace('__APP_DIR__/', '')))
return true
} catch(e) {}
console.error(`(ERROR, HTTP) File not found: ${url}`)
if (url.match(/\/client\/index.*\.js/)) {
console.warn('(WARNING) It seems a client attempted to load an older version of the app,',
'this may occur when using a homescreen bookmark on mobile devices.',
'If that\'s the case, please delete it and browse to the app\'s url again.')
}
res.writeHead(404)
res.end()
} else {
if (
url.match(/^\/+__APP_DIR__\//)
) {
// user files
// osc asset files
// windows absolute path fix
url = url.replace('_:_', ':') // escaped drive colon
url = url.replace(/^\/([^/]*:)/, '$1') // strip leading slash
if (url.indexOf('theme.css') != -1) {
if (url.match(/.(svg|jpg|jpeg|png|apng|gif|webp|tiff|xbm|bmp|ico|ttf|otf|woff|woff2|html|css|js)(\?[0-9]*)?$/i)) {
res.setHeader('Content-Type', 'text/css')
// Resolution order: session path, theme path, absolute path
var id
if (req.headers.cookie) {
id = (req.headers.cookie.match(/client_id=([^;]+)/) || [])[1]
}
var etag = settings.read('theme') ? theme.hash : 'empty-theme'
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('ETag', etag)
if (req.headers['if-none-match'] && req.headers['if-none-match'] === etag) {
res.statusCode = 304
res.end()
return
}
if (settings.read('theme')) {
let str = theme.get(),
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
res.write(buf)
} else {
res.write('')
}
res.end()
} else {
var resolvedPath = this.resolvePath(decodeURI(url), id)
if (resolvedPath) {
try {
res.sendFile(path.resolve(__dirname + '/../../' + url.replace('__APP_DIR__/', '')))
res.sendFile(resolvedPath)
return true
} catch(e) {}
}
if (!this.ignoredNotFound.includes(url)) {
console.error(`(ERROR, HTTP) File not found: ${url}`)
if (url.match(/\/client\/index.*\.js/)) {
console.warn('(WARNING) It seems a client attempted to load an older version of the app,',
'this may occur when using a homescreen bookmark on mobile devices.',
'If that\'s the case, please delete it and browse to the app\'s url again.')
}
res.writeHead(404)
res.end()
}
res.writeHead(404)
res.end()
} else if (url.includes('/osc-ping')) {
this.httpCheck(true)
} else {
// user files
// windows absolute path fix
url = url.replace('_:_', ':') // escaped drive colon
url = url.replace(/^\/([^/]*:)/, '$1') // strip leading slash
if (url.match(/.(svg|jpg|jpeg|png|apng|gif|webp|tiff|xbm|bmp|ico|ttf|otf|woff|woff2|html|css|js)(\?[0-9]*)?$/i)) {
// Resolution order: session path, theme path, absolute path
var id
if (req.headers.cookie) {
id = (req.headers.cookie.match(/client_id=([^;]+)/) || [])[1]
}
var resolvedPath = this.resolvePath(decodeURI(url), id)
if (resolvedPath) {
try {
res.sendFile(resolvedPath)
return true
} catch(e) {}
}
if (!this.ignoredNotFound.includes(url)) {
console.error(`(ERROR, HTTP) File not found: ${url}`)
}
res.writeHead(404)
res.end()
} else if (url.includes('/osc-ping')) {
this.httpCheck(true)
} else {
res.writeHead(403)
res.end()
}
res.writeHead(403)
res.end()
}
}
}
httpCheck(ok, error) {