Spaces:
Running
Running
File size: 1,247 Bytes
f42b4a1 1185ec1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import { downloadFile } from "@/lib/huggingface/hub/src"
import { getCredentials } from "./getCredentials"
export async function downloadFileAsBlob({
repo,
path,
apiKey,
expectedMimeType = "text/plain",
renewCache = false,
neverThrow = false
}: {
repo: string
path: string
apiKey?: string
expectedMimeType?: string
/**
* Force renewing the cache
*
* False by default
*/
renewCache?: boolean
/**
* If set to true, this function will never throw an exception
* this is useful in workflow where we don't care about what happened
*
* False by default
*/
neverThrow?: boolean
}): Promise<Blob> {
try {
const { credentials } = await getCredentials(apiKey)
const response = await downloadFile({
repo,
path,
credentials,
requestInit: renewCache
? { cache: "no-cache" }
: undefined
})
if (!response) {
throw new Error("missing response")
}
const blob = await response.blob()
return blob
} catch (err) {
if (neverThrow) {
console.error(`downloadFileAsBlob():`, err)
const blobResult = new Blob([""], { type: expectedMimeType })
return blobResult
} else {
throw err
}
}
} |