@xiboplayer/cache 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiboplayer/cache",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Offline caching and download management with parallel chunk downloads",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "spark-md5": "^3.0.2",
15
- "@xiboplayer/utils": "0.1.3"
15
+ "@xiboplayer/utils": "0.2.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "vitest": "^2.0.0",
@@ -222,20 +222,13 @@ class ServiceWorkerBackend extends EventEmitter {
222
222
  }
223
223
 
224
224
  /**
225
- * Check if file is cached
225
+ * Check if file is cached (delegates to hasFile for consistent fetchReady handling)
226
226
  * @param {string} type - 'media', 'layout', 'widget'
227
227
  * @param {string} id - File ID
228
228
  * @returns {Promise<boolean>}
229
229
  */
230
230
  async isCached(type, id) {
231
- const cacheUrl = `${BASE}/cache/${type}/${id}`;
232
-
233
- try {
234
- const response = await fetch(cacheUrl, { method: 'HEAD' });
235
- return response.ok;
236
- } catch (error) {
237
- return false;
238
- }
231
+ return this.hasFile(type, id);
239
232
  }
240
233
 
241
234
  /**
@@ -384,16 +377,13 @@ export class CacheProxy extends EventEmitter {
384
377
  }
385
378
 
386
379
  /**
387
- * Check if file is cached
380
+ * Check if file is cached (delegates to hasFile for consistent fetchReady handling)
388
381
  * @param {string} type - 'media', 'layout', 'widget'
389
382
  * @param {string} id - File ID
390
383
  * @returns {Promise<boolean>}
391
384
  */
392
385
  async isCached(type, id) {
393
- if (!this.backend) {
394
- throw new Error('CacheProxy not initialized');
395
- }
396
- return await this.backend.isCached(type, id);
386
+ return this.hasFile(type, id);
397
387
  }
398
388
 
399
389
  /**
@@ -29,8 +29,6 @@ export class DownloadTask {
29
29
  this.downloadedBytes = 0;
30
30
  this.totalBytes = 0;
31
31
  this.promise = null;
32
- this.resolve = null;
33
- this.reject = null;
34
32
  this.waiters = []; // Promises waiting for completion
35
33
  this.state = 'pending'; // pending, downloading, complete, failed
36
34
  // Progressive streaming: callback fired for each chunk as it downloads
File without changes