import { uploadFile } from "@huggingface/hub"; import type { RepoDesignation, Credentials } from "@huggingface/hub"; import { env } from '$env/dynamic/private' const TOTAL_FOLDERS = 10 // const MAX_IMAGES_PER_FOLDER = 10_000 export const UploaderDataset = async (blob: Blob, name: string) => { const repo: RepoDesignation = { type: "dataset", name: "enzostvs/loras-studio" }; const credentials: Credentials = { accessToken: env.SECRET_HF_TOKEN as string }; const folder_key = Math.floor(Math.random() * TOTAL_FOLDERS) const formatted_name = name.replace(/[^a-zA-Z0-9]/g, "-") const path = `images-${folder_key}/${formatted_name}.png` try { await uploadFile({ repo, credentials, file: { path, content: blob, }, }) return { path, ok: true } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { console.error(e) return { ok: false } } }