server: relative image request resolution (to session-path)
This commit is contained in:
parent
59e2b22a70
commit
ef5fca667f
5 changed files with 35 additions and 8 deletions
|
|
@ -6,6 +6,8 @@
|
|||
- launcher: spaces not properly escaped in quoted strings
|
||||
- widgets
|
||||
- sliders: `default` and `spring` properties are now dynamic
|
||||
- server
|
||||
- images urls are now resolved relatively to the session path directory by default (fallback to absolute path resolution if not found)
|
||||
|
||||
## 0.46.2
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class Ipc extends EventEmitter {
|
|||
this.socket.send('["pong"]')
|
||||
})
|
||||
|
||||
document.cookie = 'client_id=' + uuid
|
||||
|
||||
try {
|
||||
this.open()
|
||||
} catch(e) {
|
||||
|
|
@ -42,6 +44,7 @@ class Ipc extends EventEmitter {
|
|||
console.log(e)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
|
|
@ -110,7 +113,7 @@ class Ipc extends EventEmitter {
|
|||
id: 'ipc_state',
|
||||
duration: Infinity
|
||||
})
|
||||
|
||||
|
||||
this.disconnected = true
|
||||
|
||||
clearTimeout(this.reconnect)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ var SessionManager = class SessionManager {
|
|||
loader.close()
|
||||
new Popup({title: locales('session_parsingerror'), content: err.message, icon: 'exclamation-triangle', closable:true})
|
||||
this.lock = false
|
||||
ipc.send('sessionSetPath', {path: this.sessionPath})
|
||||
throw err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ module.exports = {
|
|||
|
||||
module.exports.fileRead(data, clientId, true, (result)=>{
|
||||
|
||||
ipc.clients[clientId].sessionPath = data.path // for resolving local file requests
|
||||
ipc.send('sessionOpen', {path: data.path, session: result}, clientId)
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var path = require('path'),
|
||||
var urlparser = require('url'),
|
||||
path = require('path'),
|
||||
send = require('send'),
|
||||
http = require('http'),
|
||||
server = http.createServer(httpRoute),
|
||||
|
|
@ -12,14 +13,21 @@ var path = require('path'),
|
|||
clients = {}
|
||||
|
||||
function httpRoute(req, res) {
|
||||
|
||||
res.sendFile = (path)=>{
|
||||
send(req, path.split('?')[0]).pipe(res)
|
||||
}
|
||||
|
||||
if (req.url === '/' || req.url.indexOf('/?') === 0) {
|
||||
var url = req.url
|
||||
|
||||
if (url === '/' || url.indexOf('/?') === 0) {
|
||||
|
||||
res.sendFile(path.resolve(__dirname + '/../client/index.html'))
|
||||
|
||||
} else {
|
||||
if (req.url.indexOf('theme.css') != -1) {
|
||||
|
||||
if (url.indexOf('theme.css') != -1) {
|
||||
|
||||
res.setHeader('Content-Type', 'text/css')
|
||||
if (settings.read('theme')) {
|
||||
var str = theme.get(),
|
||||
|
|
@ -29,23 +37,35 @@ function httpRoute(req, res) {
|
|||
res.write('')
|
||||
}
|
||||
res.end()
|
||||
} else if (/^\/(assets|client)\//.test(req.url)){
|
||||
res.sendFile(path.resolve(__dirname + '/..' + req.url))
|
||||
|
||||
} else if (/^\/(assets|client)\//.test(url)){
|
||||
|
||||
res.sendFile(path.resolve(__dirname + '/..' + url))
|
||||
|
||||
} else {
|
||||
var url = req.url
|
||||
|
||||
// windows absolute path fix
|
||||
url = url.replace('_:_', ':') // escaped drive colon
|
||||
url = url.replace(/^\/([^/]*:)/, '$1') // strip leading slash
|
||||
|
||||
if (url.match(/.(jpg|jpeg|png|apng|gif|webp|tiff|xbm|bmp|ico)(\?[0-9]*)?$/i)) {
|
||||
res.sendFile(path.resolve(url))
|
||||
try {
|
||||
// relative resolution (session path)
|
||||
var id = urlparser.parse('?' + req.headers.cookie, true).query.client_id,
|
||||
sessionPath = path.dirname(ipc.clients[id].sessionPath)
|
||||
|
||||
res.sendFile(path.resolve(sessionPath + url))
|
||||
} catch(e) {
|
||||
// absolute resolution (session path)
|
||||
res.sendFile(path.resolve(url))
|
||||
}
|
||||
} else {
|
||||
res.writeHead(403)
|
||||
res.end()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue