nico-martin's picture
nico-martin HF Staff
init
9b72f0d
raw
history blame
608 Bytes
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;
}
};