@@ -13,7 +13,7 @@ export default class GEOResourceManifest {
1313 Console . log ( "☑️ Download" ) ;
1414 const newRequest = { ...request } ;
1515 newRequest . url = new URL ( newRequest . url ) ;
16- newRequest . url . searchParams . set ( "country_code" , countryCode ) ;
16+ newRequest . url . searchParams . set ( "country_code" , countryCode === "XX" ? "US" : countryCode ) ;
1717 newRequest . url = newRequest . url . toString ( ) ;
1818 newRequest [ "binary-mode" ] = true ;
1919 const response = await fetch ( newRequest ) ;
@@ -26,12 +26,16 @@ export default class GEOResourceManifest {
2626 * 读取资源清单缓存。
2727 * Read resource manifest cache.
2828 * @param {object } caches 缓存对象 / Cache object.
29- * @param {string } countryCode 国家代码 / Country code .
29+ * @param {string } queryString 查询字符串(包含前导问号) / Query string with leading question mark .
3030 * @returns {{eTag?: string, base64?: string}|undefined } 缓存条目 / Cache entry.
3131 */
32- static getCache ( caches = { } , countryCode = "CN " ) {
32+ static getCache ( caches = { } , queryString = "" ) {
3333 Console . log ( "☑️ Get Cache" ) ;
34- const cache = caches ?. GeoManifest ?. [ countryCode ] ;
34+ if ( ! queryString ) {
35+ Console . warn ( "❎ Get Cache" , "Missing query string" ) ;
36+ return undefined ;
37+ }
38+ const cache = caches ?. GeoManifest ?. [ queryString ] ;
3539 switch ( typeof cache ?. base64 ) {
3640 case "string" :
3741 if ( cache . base64 ) {
@@ -48,21 +52,25 @@ export default class GEOResourceManifest {
4852 * 写入资源清单缓存。
4953 * Write resource manifest cache.
5054 * @param {object } caches 缓存对象 / Cache object.
51- * @param {string } countryCode 国家代码 / Country code .
55+ * @param {string } queryString 查询字符串(包含前导问号) / Query string with leading question mark .
5256 * @param {string } eTag 实体标签 / Entity tag.
5357 * @param {Uint8Array|ArrayBuffer } rawBody 原始二进制 / Raw binary body.
5458 * @param {object } env Worker 环境对象 / Worker environment bindings.
5559 * @returns {Promise<boolean> } 是否写入成功 / Whether cache is written.
5660 */
57- static async setCache ( caches = { } , countryCode = "CN " , eTag = "" , rawBody = new Uint8Array ( ) , env ) {
61+ static async setCache ( caches = { } , queryString = "" , eTag = "" , rawBody = new Uint8Array ( ) , env ) {
5862 Console . log ( "☑️ Set Cache" ) ;
63+ if ( ! queryString ) {
64+ Console . warn ( "❎ Set Cache" , "Missing query string" ) ;
65+ return false ;
66+ }
5967 if ( ! eTag ) {
60- Console . warn ( "❎ Set Cache" , `Missing eTag: ${ countryCode } ` ) ;
68+ Console . warn ( "❎ Set Cache" , `Missing eTag: ${ queryString } ` ) ;
6169 return false ;
6270 }
6371 rawBody = rawBody instanceof Uint8Array ? rawBody : new Uint8Array ( rawBody ?? [ ] ) ;
6472 if ( ! rawBody . length ) {
65- Console . warn ( "❎ Set Cache" , `Empty body: ${ countryCode } ` ) ;
73+ Console . warn ( "❎ Set Cache" , `Empty body: ${ queryString } ` ) ;
6674 return false ;
6775 }
6876 let base64 = "" ;
@@ -87,15 +95,15 @@ export default class GEOResourceManifest {
8795 }
8896 } catch ( error ) {
8997 Console . error ( error ) ;
90- Console . warn ( "❎ Set Cache" , `Encode failed: ${ countryCode } ` ) ;
98+ Console . warn ( "❎ Set Cache" , `Encode failed: ${ queryString } ` ) ;
9199 return false ;
92100 }
93101 if ( ! base64 ) {
94- Console . warn ( "❎ Set Cache" , `Empty base64: ${ countryCode } ` ) ;
102+ Console . warn ( "❎ Set Cache" , `Empty base64: ${ queryString } ` ) ;
95103 return false ;
96104 }
97105 if ( typeof caches . GeoManifest !== "object" || caches . GeoManifest === null ) caches . GeoManifest = { } ;
98- caches . GeoManifest [ countryCode ] = { eTag, base64 } ;
106+ caches . GeoManifest [ queryString ] = { eTag, base64 } ;
99107 const result = env ?. PersistentStore
100108 ? await new Storage ( { env : { namespace : env . PersistentStore } } ) . setItem ( "@iRingo.Maps.Caches.GeoManifest" , caches . GeoManifest )
101109 : PersistentStorage . setItem ( "@iRingo.Maps.Caches" , caches ) ;
@@ -107,14 +115,14 @@ export default class GEOResourceManifest {
107115 * 解码资源清单缓存。
108116 * Decode resource manifest cache.
109117 * @param {object } caches 缓存对象 / Cache object.
110- * @param {string } countryCode 国家代码 / Country code .
118+ * @param {string } queryString 查询字符串(包含前导问号) / Query string with leading question mark .
111119 * @returns {object|undefined } 解码结果 / Decoded manifest.
112120 */
113- static decodeCache ( caches = { } , countryCode = "CN " ) {
121+ static decodeCache ( caches = { } , queryString = "" ) {
114122 Console . log ( "☑️ Decode Cache" ) ;
115- const cache = this . getCache ( caches , countryCode ) ;
123+ const cache = GEOResourceManifest . getCache ( caches , queryString ) ;
116124 if ( ! cache ?. base64 ) {
117- Console . warn ( "❎ Decode Cache" , `Missing cache: ${ countryCode } ` ) ;
125+ Console . warn ( "❎ Decode Cache" , `Missing cache: ${ queryString } ` ) ;
118126 return undefined ;
119127 }
120128 try {
@@ -133,15 +141,15 @@ export default class GEOResourceManifest {
133141 throw new Error ( "Unsupported base64 decoder" ) ;
134142 }
135143 if ( ! rawBody ?. length ) {
136- Console . warn ( "❎ Decode Cache" , `Empty body: ${ countryCode } ` ) ;
144+ Console . warn ( "❎ Decode Cache" , `Empty body: ${ queryString } ` ) ;
137145 return undefined ;
138146 }
139147 const body = GEOResourceManifestDownload . decode ( rawBody ) ;
140148 Console . log ( "✅ Decode Cache" ) ;
141149 return body ;
142150 } catch ( error ) {
143151 Console . error ( error ) ;
144- Console . warn ( "❎ Decode Cache" , `Decode failed: ${ countryCode } ` ) ;
152+ Console . warn ( "❎ Decode Cache" , `Decode failed: ${ queryString } ` ) ;
145153 return undefined ;
146154 }
147155 }
0 commit comments