server: support ~/ path prefix in /{SESSION,STATE}/{OPEN,SAVE}

This commit is contained in:
bordun 2020-10-24 17:25:34 +02:00
parent 7f0b66f7df
commit 4c0a574695
2 changed files with 13 additions and 0 deletions

View file

@ -146,6 +146,12 @@ module.exports = {
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
if (data.path && data.path.startsWith('~')) {
// Resolve '~' to user's home directory
var p = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']
if (p) data.path = data.path.replace( '~', p )
}
fs.readFile(data.path, 'utf8', (err, result)=>{
var error
@ -186,6 +192,12 @@ module.exports = {
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
if (data.path.startsWith('~')) {
// Resolve '~' to user's home directory
var p = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']
if (p) data.path = data.path.replace( '~', p )
}
var root = settings.read('remote-root')
if (root && !data.path.includes(root)) {
console.error('(ERROR) Could not save: path outside of remote-root')