unified workspace
This commit is contained in:
70
index.js
70
index.js
@@ -27,6 +27,12 @@ const minfileSaveFullPath = path.join(__dirname,'examples', minfilename)
|
||||
const sshconfigpath = path.resolve(process.env.HOME,'.ssh','config')
|
||||
const propath = path.resolve(process.env.HOME,'Prototypes')
|
||||
|
||||
const sshfsmounts = "sshfsmounts"
|
||||
|
||||
let workspaces = {}
|
||||
let mountPoints = []
|
||||
// note that stopping this process removes the mounts
|
||||
|
||||
// does not apply in a P2P fashion, must rely on local configuration here config.json
|
||||
let localServices = [ ]
|
||||
const configFilePath = path.resolve(__dirname, "config.json")
|
||||
@@ -231,7 +237,8 @@ app.get('/hmdlink', (req, res) => {
|
||||
})
|
||||
|
||||
app.get('/webxr', (req, res) => {
|
||||
res.redirect( '/local-metaverse-tooling/local-aframe-test.html' )
|
||||
res.redirect( '/spasca-offline/engine/index.html')
|
||||
//res.redirect( '/local-metaverse-tooling/local-aframe-test.html' )
|
||||
})
|
||||
|
||||
// user for /scan to populate foundPeers
|
||||
@@ -272,24 +279,57 @@ function scanpeers(){
|
||||
|
||||
app.get('/sshconfig', (req, res) => {
|
||||
res.json( getSshConfig() )
|
||||
// should filter on foundPeers to avoid offline peers
|
||||
})
|
||||
|
||||
// note that stopping this process removes the mounts
|
||||
app.get('/sshconfig/live', (req, res) => {
|
||||
res.json( getSshConfig().filter( i => foundPeers.map( e => subclass+e ).filter( x => i.connectionString.match(x) ).length ) )
|
||||
})
|
||||
|
||||
app.get('/unifiedworkspaces', (req, res) => {
|
||||
res.json( workspaces )
|
||||
})
|
||||
|
||||
function getUnifiedworkspaces(){
|
||||
mountPoints.map( mp => {
|
||||
let dir = path.resolve(__dirname, sshfsmounts, mp)
|
||||
workspaces[mp] = fs.readdirSync( dir )
|
||||
console.log('reading', mp, workspaces.mp)
|
||||
})
|
||||
return workspaces
|
||||
}
|
||||
|
||||
function mountAll(){
|
||||
// might have to scanpeers() first
|
||||
// should scanpeers() first
|
||||
if (foundPeers.length==0) return
|
||||
getSshConfig().map( l => {
|
||||
getSshConfig().filter( i => foundPeers.map( e => subclass+e ).filter( x => i.connectionString.match(x) ).length )
|
||||
.map( l => {
|
||||
let cs = 'sshfs ' + l.name + ':'
|
||||
if (l.custom)
|
||||
cs+= l.custom
|
||||
else
|
||||
cs+='/home/'+l.user
|
||||
return cs + ' ' + path.resolve(__dirname, "sshfsmounts", l.name)
|
||||
let targetPath = path.resolve(__dirname, sshfsmounts, l.name)
|
||||
if (!fs.existsSync(targetPath)){ fs.mkdirSync(targetPath, { recursive: true }); }
|
||||
mountPoints.push(l.name)
|
||||
return cs + ' ' + targetPath
|
||||
} )
|
||||
//.map( l => execSync(l))
|
||||
.map( l => console.log(l))
|
||||
// will error out on non existing directories
|
||||
//.map( l => console.log(l))
|
||||
.map( l => { try { execSync(l) } catch (err) { console.log(err) } } )
|
||||
}
|
||||
|
||||
function umountAll(){
|
||||
mpath = path.resolve(__dirname, sshfsmounts)
|
||||
fs.readdirSync( mpath )
|
||||
// could rely on mountPoints instead
|
||||
.map( f => {
|
||||
try {
|
||||
execSync('umount ' + path.resolve(__dirname, sshfsmounts, f) )
|
||||
// should update mountPoints instead
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
})
|
||||
mountPoints = []
|
||||
}
|
||||
|
||||
function getSshConfig(){
|
||||
@@ -426,7 +466,9 @@ help()
|
||||
execConfiguredCommand(cmdName)
|
||||
getSshConfig()
|
||||
mountAll()
|
||||
umountAll()
|
||||
scanpeers()
|
||||
getUnifiedworkspaces()
|
||||
foundPeers
|
||||
port
|
||||
protocol
|
||||
@@ -447,10 +489,20 @@ utilsCmd
|
||||
instructions
|
||||
auth_instructions
|
||||
process.title
|
||||
sshfsmounts
|
||||
mountPoints
|
||||
workspaces
|
||||
`
|
||||
}
|
||||
|
||||
rl.on("close", function() {
|
||||
console.log("\ndone");
|
||||
umountAll()
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Demo Day target :
|
||||
// show files from ~/Prototypes as cubes from ssh mounted on a virtual workspace
|
||||
// sshfs might not even be needed, see allpeers/exec instead
|
||||
// wouldn't easily get content back though, just meta data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user