diff --git a/README.md b/README.md index b65837b..7a1cd86 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,16 @@ Portable swiss-army knife to automate [janusXR](https://janusxr.org) / JML thing # Usage ``` -Usage: ./janusxr --health [--max-time-per-asset 5] - ./janusxr --scrape +Usage: ./janusxr health [--max-time-per-asset 5] + ./janusxr scrape + ./janusxr optimize ``` ## Examples > scan a room URL for broken links in JML+HTML ```bash -$ ./janusxr --health http://localhost:8790/models/m5gr26w0wqqs +$ ./janusxr health http://localhost:8790/models/m5gr26w0wqqs ✅ http://localhost:8791/templates/xrfragment/%232/website.glb ✅ http://localhost:8790/models/assets/offscreen_renderer-186b8c52.js @@ -36,7 +37,7 @@ $ ./janusxr --health http://localhost:8790/models/m5gr26w0wqqs > scrape a room URL and rewrite JML to serve local assets (usecase: preservation/local-first/prototyping) ```bash -$ ./janusxr --scrape https://www.janusxr.org/newlobby/index.html mydir +$ ./janusxr scrape https://www.janusxr.org/newlobby/index.html mydir 🔗 http://dizzket.com/archive/dotmatrix/ 🔗 https://vesta.janusvr.com/nazrin/minecraft-sandbox ✅ http://www.janusvr.com/newlobby/scripts/home.txt @@ -48,6 +49,23 @@ home.txt ... ``` +> optimize a room by adding tags to your JML + +```bash +$ ./janusxr optimize https://janusvr.com/newlobby/index.html + + + + + + +... + +``` + +* `preconnect` speeds up loading remote resources (DNS lookup, TCP handshake, TLS negotiation) +* ` allows archive.org to fully capture the room (resources) + ## Awk? Why not some superfancy scripting for this task? diff --git a/janusxr b/janusxr index 1751a1b..d22945c 100755 --- a/janusxr +++ b/janusxr @@ -1,8 +1,9 @@ #!/usr/bin/env -S awk -f function usage() { - print "Usage: ./janusxr --health [--max-time-per-asset 5] \n" \ - " ./janusxr --scrape \n" + print "Usage: ./janusxr health [--max-time-per-asset 5] \n" \ + " ./janusxr scrape \n" \ + " ./janusxr optimize \n" exit 1 } @@ -12,9 +13,12 @@ function usage() { BEGIN { if (ARGC < 2) usage() command = ARGV[1] - if (command == "--health" || command == "--scrape") { + if (command == "health" || command == "scrape" || command == "optimize" ) { scrape(command) } else { + printf("1:"ARGV[0]) + printf("1:"ARGV[1]) + printf("2:"ARGV[2]) printf("Unknown command: %s\n", command) usage() } @@ -47,7 +51,7 @@ function scrape( arg, tmpfile, line, attr, check, u) { close(tmpfile) # Check each extracted links - if( arg == "--health" ){ + if( arg == "health" ){ maxtime = ARGV[3] if ( maxtime == "" ) maxtime = 5 nlinks = 0 @@ -65,7 +69,7 @@ function scrape( arg, tmpfile, line, attr, check, u) { if( nlinks != nlinksok ) exit(1) } - if( arg == "--scrape" ) { + if( arg == "scrape" ) { outdir = ARGV[3] if ( outdir == "" ) outdir = "." system("mkdir "outdir" || true ") @@ -86,6 +90,23 @@ function scrape( arg, tmpfile, line, attr, check, u) { nlinks+=1 } } + + if( arg == "optimize" ) { + printf("\n") + for (u in links) { + if( substr(u,1,1) == "/" ) u = rooturl""u + check = "curl -L --max-time 20 -I -s \"" u "\" > /dev/null" + if (system(check) == 0 && has_non_html_ext(u) ){ + printf("\n") + split(u,urlpart,"/") + domain=urlpart[1]"//"urlpart[3] + if( !domains[domain] ){ + printf("\n") + domains[domain]=1 + } + } + } + } } # Function: has_non_html_ext