@camstack/core 0.1.10 → 0.1.11
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/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -294,6 +294,14 @@ var EventBus = class {
|
|
|
294
294
|
import * as fs from "fs";
|
|
295
295
|
import * as path from "path";
|
|
296
296
|
import { createHash } from "crypto";
|
|
297
|
+
function buildHeaders(url) {
|
|
298
|
+
const headers = { "User-Agent": "CamStack/1.0" };
|
|
299
|
+
const hfToken = process.env["HF_TOKEN"] ?? process.env["HUGGING_FACE_HUB_TOKEN"];
|
|
300
|
+
if (hfToken && url.includes("huggingface.co")) {
|
|
301
|
+
headers["Authorization"] = `Bearer ${hfToken}`;
|
|
302
|
+
}
|
|
303
|
+
return headers;
|
|
304
|
+
}
|
|
297
305
|
async function downloadFile(url, destPath, onProgress) {
|
|
298
306
|
if (fs.existsSync(destPath)) return destPath;
|
|
299
307
|
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
@@ -301,7 +309,7 @@ async function downloadFile(url, destPath, onProgress) {
|
|
|
301
309
|
try {
|
|
302
310
|
const response = await fetch(url, {
|
|
303
311
|
redirect: "follow",
|
|
304
|
-
headers:
|
|
312
|
+
headers: buildHeaders(url)
|
|
305
313
|
});
|
|
306
314
|
if (!response.ok) {
|
|
307
315
|
throw new Error(`HTTP ${response.status} downloading ${url}`);
|
|
@@ -341,7 +349,7 @@ async function downloadFile(url, destPath, onProgress) {
|
|
|
341
349
|
async function fetchJson(url) {
|
|
342
350
|
const response = await fetch(url, {
|
|
343
351
|
redirect: "follow",
|
|
344
|
-
headers:
|
|
352
|
+
headers: buildHeaders(url)
|
|
345
353
|
});
|
|
346
354
|
if (!response.ok) {
|
|
347
355
|
throw new Error(`HTTP ${response.status} fetching ${url}`);
|