routes availability, WebXR route example and KWin example
This commit is contained in:
3117
examples/spasca-offline/engine/index.html
Normal file
3117
examples/spasca-offline/engine/index.html
Normal file
File diff suppressed because it is too large
Load Diff
26
index.js
26
index.js
@@ -8,7 +8,7 @@ const express = require("express"); // could be good to replace with c
|
||||
// (worked at least on RPi, Deck, Quest and x64 machines)
|
||||
|
||||
// Get port or default to 8082
|
||||
const port = process.env.PORT || 8082;
|
||||
const port = process.env.PORT || 8082; // assumes homogenity across peers
|
||||
const protocol = process.env.PROTOCOL || 'https'
|
||||
const subclass = process.env.SUBCLASS || '192.168.0.' // defaulting to IP used at home rather than RPi0. Could also change it there as it's not justified beside helping distinction.
|
||||
// Object.values(require("os").networkInterfaces()).flat().filter(({ family, internal }) => family === "IPv4" && !internal).map(({ address }) => address)[0].split('.').slice(0,3).join('.')+'.'
|
||||
@@ -68,8 +68,13 @@ const utilsCmd = { // security risk but for now not accepting user input so safe
|
||||
format: res => res.toString().split('\n')
|
||||
},
|
||||
// per device specific (until adjustable per user)
|
||||
'minimizeall' : { cmd: '/home/fabien/Prototypes/kwin-scripting/launch'}, //KWin script
|
||||
'highresscreen' : { cmd: 'xrandr --output DP-4 --mode 3840x2160'},
|
||||
'lowresscreen' : { cmd: 'xrandr --output DP-4 --mode 1920x1080'},
|
||||
// 'anyresscreen' : { cmd: 'xrandr --output DP-4 --mode '}, // would require user input which is risky e.g here 'OxO; wget rootkit; bash rootkit;'
|
||||
'availableRes' : { cmd: 'xrandr -q | grep 0x | grep -v primary | cut -f 4 -d " "',
|
||||
format: res => res.toString().split('\n').filter( l => l!='' )
|
||||
},
|
||||
|
||||
//'npmfind' : { desc: 'package manager finder', cmd: 'find . -wholename "*node_modules/acorn"' },
|
||||
// security risk if relying on user provided name, e.g replacing acorn by user input
|
||||
@@ -120,11 +125,17 @@ app.get('/', (req, res) => {
|
||||
})
|
||||
|
||||
app.get('/routes', (req, res) => {
|
||||
let routes = app._router.stack.map( r => r.route?.path ).filter( r => typeof(r) == 'string' )
|
||||
let formattedRoutes = routes.map( r => `<li><a href='${r}'>${r}</a></li>` ).join('\n')
|
||||
res.send( formattedRoutes )
|
||||
})
|
||||
|
||||
app.get('/routes/json', (req, res) => {
|
||||
// minimalist for JXR but could also be OpenAPI, cf https://git.benetou.fr/utopiah/offline-octopus/issues/16
|
||||
// used in /webxr as
|
||||
// fetch('/routes/json').then(r=>r.json()).then(r=>r.filter(p=>p.match(/resolution/)).map(p=>addNewNote('jxr fetch("https://192.168.0.129:8082'+p+'")')))
|
||||
res.send( routes )
|
||||
})
|
||||
|
||||
app.get('/authtestviaheader', (req, res) => {
|
||||
if (req.header('authorization') != 'Bearer '+md5fromPub){ res.sendStatus(401); return; }
|
||||
res.sendStatus(200)
|
||||
@@ -237,9 +248,11 @@ app.get('/recentfiles', (req, res) => {
|
||||
res.json( {msg: 'not yet implemented'})
|
||||
})
|
||||
|
||||
let dynURL = 'https://192.168.4.1/offline.html'
|
||||
let dynURL = '/'
|
||||
app.get('/hmdlink/set', (req, res) => { // could be a PUT instead
|
||||
// e.g http://192.168.4.3:8082/hmdlink/set?url=http://192.168.4.3:8082/114df5f8-3921-42f0-81e7-48731b563571.thumbnails/f07120ba-0ca1-429d-869f-c704a52b7aa3.png
|
||||
// should return a warning if req.query.url is undefined
|
||||
if (!oeq.query.url) {res.json( {error: 'use /hmdlink/set?url=YOURURL'}); return}
|
||||
dynURL = req.query.url
|
||||
res.redirect( dynURL )
|
||||
})
|
||||
@@ -384,8 +397,10 @@ function getSshConfig(){
|
||||
easier to revoke if need be
|
||||
*/
|
||||
|
||||
app.get('/minimizeall', (req, res) => { res.json( execConfiguredCommand('minimizeall') ) })
|
||||
app.get('/resolution/high', (req, res) => { res.json( execConfiguredCommand('highresscreen') ) })
|
||||
app.get('/resolution/low', (req, res) => { res.json( execConfiguredCommand('lowresscreen') ) })
|
||||
app.get('/resolution/list', (req, res) => { res.json( execConfiguredCommand('availableRes') ) })
|
||||
|
||||
app.get('/localprototypes', (req, res) => {
|
||||
// examples to disentangle own work for cloned existing repositories :
|
||||
@@ -429,6 +444,9 @@ app.get('/editor/save', (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
let routes = app._router.stack.map( r => r.route?.path ).filter( r => typeof(r) == 'string' )
|
||||
// it's a form of caching but so far routes are not dynamically generated so sufficient solution
|
||||
|
||||
const privateKey = fs.readFileSync("naf-key.pem", "utf8");
|
||||
const certificate = fs.readFileSync("naf.pem", "utf8");
|
||||
const credentials = { key: privateKey, cert: certificate };
|
||||
@@ -438,7 +456,7 @@ const webServer = https.createServer(credentials, app);
|
||||
// const webServer = http.createServer(app);
|
||||
// Listen on port
|
||||
webServer.listen(port, () => {
|
||||
console.log("listening on "+protocol+"://localhost:" + port)
|
||||
console.log("listening on "+protocol+"://0.0.0.0:" + port)
|
||||
getCommand()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user