修改时间戳添加方式
This commit is contained in:
@ -16,18 +16,106 @@ public class TimestampUtils {
|
||||
private static ArrayMap<String, Integer> intervalMap; // 间隔
|
||||
private static ArrayMap<String, Integer> cdMap; // cd
|
||||
|
||||
public static void initMap() {
|
||||
initIntervalMap();
|
||||
initCDMap();
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getIntervalMap() {
|
||||
if (intervalMap == null) {
|
||||
intervalMap = new ArrayMap<>();
|
||||
}
|
||||
return intervalMap;
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getCdMap() {
|
||||
if (cdMap == null) {
|
||||
cdMap = new ArrayMap<>();
|
||||
}
|
||||
return cdMap;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据CD获取时间戳
|
||||
*/
|
||||
public static long getTimestamp(String url, int cd) {
|
||||
if (intervalMap == null) {
|
||||
initIntervalMap();
|
||||
}
|
||||
long base = BASE;
|
||||
for (String key : intervalMap.keySet()){
|
||||
for (String key : getIntervalMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
Utils.log("url add base = " + url);
|
||||
base += intervalMap.get(key);
|
||||
base += getIntervalMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -36,86 +124,6 @@ public class TimestampUtils {
|
||||
return (long) (Math.ceil((now - base) / cd) * cd + base);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
synchronized (TimestampUtils.class) {
|
||||
if (cdMap == null) {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
synchronized (TimestampUtils.class) {
|
||||
if (intervalMap == null) {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 为url添加timestamp
|
||||
*/
|
||||
@ -123,13 +131,10 @@ public class TimestampUtils {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return url;
|
||||
}
|
||||
if (cdMap == null) {
|
||||
initCDMap();
|
||||
}
|
||||
int cd = 0;
|
||||
for (String key : cdMap.keySet()){
|
||||
for (String key : getCdMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
cd = cdMap.get(key);
|
||||
cd = getCdMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user