1- import { parse } from "https://deno.land/std@0.132 .0/flags/mod.ts" ;
1+ import { parse } from "https://deno.land/std@0.181 .0/flags/mod.ts" ;
22
33type ServerDataJSON = {
44 hostname : string ;
@@ -37,46 +37,64 @@ const runTypes = ["all", "ram", "disk"];
3737const args = parse ( Deno . args ) ;
3838if ( args . help == true ) {
3939 console . log ( `Usage: script [OPTION]
40- --country <code> the country you want to query (eg. us, gb, de)
41- --list-countries lists the available countries
42- --type <type> the type of server to query (${ serverTypes . join ( ", " ) } )
43- --count <n> the number of pings to the server (default 3)` ) ;
40+ --country <code> the country you want to query (eg. us, gb, de)
41+ --list-countries lists the available countries
42+ --type <type> the type of server to query (${
43+ serverTypes . join ( ", " )
44+ } )
45+ --count <n> the number of pings to the server (default 3)` ) ;
4446 if ( Deno . build . os != "windows" ) {
4547 console . log (
46- ` --interval <i> the interval between pings in seconds (default/min 0.2)` ,
48+ ` --interval <i> the interval between pings in seconds (default/min 0.2)` ,
4749 ) ;
4850 }
4951 console . log (
50- ` --top <n> the number of top servers to show, (0=all)
51- --port-speed <n> only show servers with at least n Gigabit port speed
52- --run-mode <type> only show servers running from (${ runTypes . join ( ", " ) } )
53- --help usage information` ,
52+ ` --top <n> the number of top servers to show, (0=all)
53+ --port-speed <n> only show servers with at least n Gigabit port speed
54+ --provider <name> only show servers from the given provider
55+ --owned <true|false> only show servers owned by Mullvad
56+ --run-mode <type> only show servers running from (${
57+ runTypes . join ( ", " )
58+ } )
59+ --help usage information` ,
5460 ) ;
5561 Deno . exit ( 0 ) ;
5662}
5763
5864const country = args . country ;
5965const serverType = args . type ?? "all" ;
6066if ( ! serverTypes . includes ( serverType ) ) {
61- console . error ( `Invalid type, allowed types are: ${ serverTypes . join ( ", " ) } ` ) ;
62- Deno . exit ( 1 ) ;
67+ throw new Error ( `Invalid type, allowed types are: ${ serverTypes . join ( ", " ) } ` ) ;
6368}
6469
6570const interval = parseFloat ( args . interval ?? 0.2 ) || 0.2 ;
6671if ( interval < 0.2 ) {
67- console . error ( "Minimum interval value is 0.2" ) ;
68- Deno . exit ( 1 ) ;
72+ throw new Error ( "Minimum interval value is 0.2" ) ;
6973}
7074const count = parseInt ( args . count ?? 5 ) || 5 ;
7175const topN = parseInt ( args . top ?? 5 ) || 5 ;
7276const portSpeed = parseInt ( args [ "port-speed" ] ?? 0 ) || 0 ;
7377
7478const runMode = args [ "run-mode" ] ?? "all" ;
7579if ( ! runTypes . includes ( runMode ) ) {
76- console . error ( `Invalid run-mode, allowed types are: ${ runTypes . join ( ", " ) } ` ) ;
77- Deno . exit ( 1 ) ;
80+ throw new Error (
81+ `Invalid run-mode, allowed types are: ${ runTypes . join ( ", " ) } ` ,
82+ ) ;
83+ }
84+
85+ let owned : boolean | null = null ;
86+ if ( args . owned != null ) {
87+ if ( args . owned == "true" ) {
88+ owned = true ;
89+ } else if ( args . owned == "false" ) {
90+ owned = false ;
91+ } else {
92+ throw new Error ( "Invalid value for owned, must be true or false" ) ;
93+ }
7894}
7995
96+ const provider = args . provider ;
97+
8098console . log ( "Fetching currently available relays..." ) ;
8199const response = await fetch (
82100 `https://api.mullvad.net/www/relays/${ serverType } /` ,
@@ -98,7 +116,9 @@ if (args["list-countries"]) {
98116 if (
99117 ( country == null || country == server . country_code ) &&
100118 ( server . network_port_speed >= portSpeed ) &&
101- checkRunMode ( server . stboot , runMode )
119+ checkRunMode ( server . stboot , runMode ) &&
120+ ( provider == null || provider == server . provider ) &&
121+ ( owned == null || owned == server . owned )
102122 ) {
103123 let cmd = [ ] ;
104124 if ( Deno . build . os == "windows" ) {
0 commit comments