Skip to content

Commit

Permalink
auto zone build date
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Nov 3, 2023
1 parent 71e44cf commit 21f38d4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions library/src/main/java/com/qiniu/android/common/ZoneInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.qiniu.android.common;

import com.qiniu.android.utils.Utils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -76,14 +78,15 @@ private ZoneInfo(int ttl,
boolean ipv6,
String regionId,
List<String> domains,
List<String> old_domains) {
List<String> old_domains,
Date buildDate) {
this.ttl = ttl;
this.http3Enabled = http3Enabled;
this.ipv6 = ipv6;
this.regionId = regionId;
this.domains = domains;
this.old_domains = old_domains;
this.buildDate = new Date();
this.buildDate = buildDate != null ? buildDate : new Date();
List<String> allHosts = new ArrayList<>();
if (domains != null) {
allHosts.addAll(domains);
Expand All @@ -105,6 +108,12 @@ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException {
}

int ttl = obj.optInt("ttl");
long timestamp = obj.optInt("timestamp");
if (timestamp < 100) {
timestamp = Utils.currentTimestamp();
obj.put("timestamp", timestamp);
}

boolean http3Enabled = false;
boolean ipv6Enabled = false;
try {
Expand Down Expand Up @@ -153,7 +162,8 @@ public static ZoneInfo buildFromJson(JSONObject obj) throws JSONException {
return null;
}

ZoneInfo zoneInfo = new ZoneInfo(ttl, http3Enabled, ipv6Enabled, regionId, domains, old_domains);
Date buildDate = new Date(timestamp);
ZoneInfo zoneInfo = new ZoneInfo(ttl, http3Enabled, ipv6Enabled, regionId, domains, old_domains, buildDate);
zoneInfo.detailInfo = obj;

return zoneInfo;
Expand All @@ -179,7 +189,7 @@ public boolean isValid() {

@Override
protected Object clone() throws CloneNotSupportedException {
ZoneInfo info = new ZoneInfo(ttl, http3Enabled, ipv6, regionId, domains, old_domains);
ZoneInfo info = new ZoneInfo(ttl, http3Enabled, ipv6, regionId, domains, old_domains, buildDate);
info.detailInfo = detailInfo;
return info;
}
Expand Down

0 comments on commit 21f38d4

Please sign in to comment.