File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1212
1313class Ip2AsnUpdater
1414{
15+ public static function fetch (Ip $ version ): string
16+ {
17+ static $ baseUrls = [
18+ 'https://iptoasn.com/data ' ,
19+ 'https://assets.ppy.sh ' ,
20+ ];
21+
22+ foreach ($ baseUrls as $ baseUrl ) {
23+ try {
24+ $ gz = file_get_contents ("{$ baseUrl }/ip2asn- {$ version ->value }.tsv.gz " );
25+
26+ if ($ gz !== false ) {
27+ break ;
28+ }
29+ } catch (\Throwable ) {
30+ // retry
31+ }
32+ }
33+
34+ if (!isset ($ gz ) || !is_string ($ gz )) {
35+ throw new \Exception ('failed downloading source database ' );
36+ }
37+
38+ return gzdecode ($ gz );
39+ }
40+
1541 public static function getDbPath (Ip $ version ): string
1642 {
1743 return database_path ("ip2asn/ {$ version ->value }.tsv " );
@@ -60,7 +86,7 @@ private function update(Ip $version, callable $logger): void
6086
6187 if ($ newDb ) {
6288 $ logger ('Db file is outdated. Downloading ' );
63- $ tsv = gzdecode ( file_get_contents ( " https://iptoasn.com/data/ip2asn- { $ version-> value } .tsv.gz " ) );
89+ $ tsv = static :: fetch ( $ version );
6490 } else {
6591 $ tsv = file_get_contents ($ dbPath );
6692 }
You can’t perform that action at this time.
0 commit comments