瀏覽代碼

feat: handle empty city name

M1Screw 2 年之前
父節點
當前提交
373750d88a
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 3 3
      src/Command/Update.php
  2. 5 1
      src/Utils/Tools.php

+ 3 - 3
src/Command/Update.php

@@ -81,11 +81,11 @@ END;
 
         if ($_ENV['maxmind_license_key'] !== '') {
             echo "正在更新 GeoLite2 数据库...\n";
-            $client = new Client(array(
+            $client = new Client([
                 'license_key' => $_ENV['maxmind_license_key'],
                 'dir' => BASE_PATH . '/storage/',
-                'editions' => array('GeoLite2-City', "GeoLite2-Country"),
-            ));
+                'editions' => ['GeoLite2-City', "GeoLite2-Country"],
+            ]);
             $client->run();
         }
     }

+ 5 - 1
src/Utils/Tools.php

@@ -33,7 +33,11 @@ final class Tools
             return '未知';
         }
 
-        return $country . ' ' . $city;
+        if ($city !== null) {
+            return $city . ', ' . $country;
+        }
+
+        return $country;
     }
 
     /**