@@ -59,7 +59,7 @@ public CrowdinOTA(QuickShop plugin) {
5959
6060 @ Nullable
6161 public Manifest getManifest () {
62- return JsonUtil .getGson ().fromJson (getManifestJson (), Manifest .class );
62+ return JsonUtil .regular ().fromJson (getManifestJson (), Manifest .class );
6363 }
6464
6565 /**
@@ -144,9 +144,9 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
144144 if (!manifest .getFiles ().contains (fileCrowdinPath )) {
145145 throw new IllegalArgumentException ("The file " + fileCrowdinPath + " not exists on Crowdin" );
146146 }
147- if (manifest .getCustomLanguages () != null && !manifest .getCustomLanguages ().contains (crowdinLocale )) {
148- throw new IllegalArgumentException ("The locale " + crowdinLocale + " not exists on Crowdin" );
149- }
147+ // if (manifest.getCustom_languages () != null && !manifest.getCustom_languages ().contains(crowdinLocale)) {
148+ // throw new IllegalArgumentException("The locale " + crowdinLocale + " not exists on Crowdin");
149+ // }
150150 // Post path (replaced with locale code)
151151 String postProcessingPath = fileCrowdinPath .replace ("%locale%" , crowdinLocale );
152152 OTACacheControl otaCacheControl = new OTACacheControl ();
@@ -158,16 +158,18 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
158158 // Check cache outdated
159159 if (!otaCacheControl .isCachedObjectOutdated (postProcessingPath , manifestTimestamp )) {
160160 // Return the caches
161+ Util .debugLog ("Use local cache for " + postProcessingPath );
161162 return new String (otaCacheControl .readObjectCache (postProcessingPath ), StandardCharsets .UTF_8 );
163+ } else {
164+ Util .debugLog ("Local cache outdated for " + postProcessingPath );
162165 }
163166 } catch (Exception exception ) {
164167 MsgUtil .debugStackTrace (exception .getStackTrace ());
165168 }
169+ } else {
170+ Util .debugLog ("Manifest timestamp check failed " + postProcessingPath + " excepted:" + otaCacheControl .readManifestTimestamp () + " actual: " + getManifest ().getTimestamp ());
166171 }
167172 // Out of the cache
168- if (manifestTimestamp == null ) { // null-safe
169- manifestTimestamp = System .currentTimeMillis ();
170- }
171173 String url = CROWDIN_OTA_HOST + "content" + fileCrowdinPath .replace ("%locale%" , crowdinLocale );
172174 plugin .getLogger ().info ("Updating translation " + crowdinLocale + " from: " + url );
173175 String data = HttpUtil .createGet (url );
@@ -177,6 +179,7 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
177179 }
178180 // Successfully grab the data from the remote server
179181 otaCacheControl .writeObjectCache (postProcessingPath , data .getBytes (StandardCharsets .UTF_8 ), manifestTimestamp );
182+ otaCacheControl .writeManifestTimestamp (getManifest ().getTimestamp ());
180183 return data ;
181184
182185// String pathHash = DigestUtils.sha1Hex(postProcessingPath);
@@ -260,7 +263,7 @@ public long readManifestTimestamp() {
260263 }
261264
262265 public void writeManifestTimestamp (long timestamp ) {
263- this .metadata .set ("manigest .timestamp" , timestamp );
266+ this .metadata .set ("manifest .timestamp" , timestamp );
264267 save ();
265268 }
266269
@@ -271,7 +274,7 @@ public long readCachedObjectTimestamp(String path) {
271274
272275 public boolean isCachedObjectOutdated (String path , long manifestTimestamp ) {
273276 String cacheKey = hash (path );
274- return this . metadata . getLong ( "objects." + cacheKey + ".timestamp" ) != manifestTimestamp ;
277+ return readCachedObjectTimestamp ( path ) != manifestTimestamp ;
275278 }
276279
277280 public byte [] readObjectCache (String path ) throws IOException {
0 commit comments