File size: 608 Bytes
9b72f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import type { Model } from "@utils/models.ts";

const ORIGIN = "https://huggingface.co";

export const isModelCached = async (model: Model): Promise<boolean> => {
  try {
    const cache = await caches.open("transformers-cache");
    const keys = await cache.keys();
    const cachedUrls = keys.map((req) => req.url);
    const filesUrls = Object.keys(model.files).map(
      (file) => `${ORIGIN}/${model.modelId}/resolve/main/${file}`
    );
    return filesUrls.every((url) => cachedUrls.includes(url));
  } catch (error) {
    console.error("Error checking model cache:", error);
    return false;
  }
};