Skip to content

Commit d47e846

Browse files
committed
xet: fix fetch calls in browser
1 parent 1e3e514 commit d47e846

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

packages/hub/scripts/bench.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ async function main() {
227227
const uploadParams = {
228228
accessToken: args.token,
229229
hubUrl: "https://huggingface.co",
230-
customFetch: mockFetchObj.fetch,
230+
fetch: mockFetchObj.fetch,
231231
repo,
232232
rev: "main",
233233
};
@@ -311,7 +311,7 @@ async function main() {
311311
})),
312312
accessToken: args.token,
313313
title: "Upload xet files with JS lib",
314-
xet: true,
314+
useXet: true,
315315
});
316316
for await (const event of iterator) {
317317
if (event.event === "fileProgress" && event.state === "hashing") {

packages/hub/src/lib/commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
336336
}
337337
})(),
338338
{
339-
customFetch: params.fetch ?? fetch,
339+
fetch: params.fetch,
340340
accessToken,
341341
hubUrl: params.hubUrl ?? HUB_URL,
342342
repo: repoId,

packages/hub/src/utils/createXorbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export async function* createXorbs(
198198
const token = await xetWriteToken(params);
199199
bytesSinceRemoteDedup = 0;
200200

201-
const shardResp = await params.customFetch(token.casUrl + "/v1/chunk/default/" + chunk.hash, {
201+
const shardResp = await (params.fetch ?? fetch)(token.casUrl + "/v1/chunk/default/" + chunk.hash, {
202202
headers: {
203203
Authorization: `Bearer ${token.accessToken}`,
204204
},

packages/hub/src/utils/uploadShards.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const SHARD_MAGIC_TAG = new Uint8Array([
5454
interface UploadShardsParams {
5555
accessToken: string | undefined;
5656
hubUrl: string;
57-
customFetch: typeof fetch;
57+
fetch?: typeof fetch;
5858
repo: RepoId;
5959
rev: string;
6060
}
@@ -347,7 +347,7 @@ function writeHashToArray(hash: string, array: Uint8Array, offset: number) {
347347
async function uploadXorb(xorb: { hash: string; xorb: Uint8Array }, params: UploadShardsParams) {
348348
const token = await xetWriteToken(params);
349349

350-
const resp = await params.customFetch(`${token.casUrl}/v1/xorb/default/${xorb.hash}`, {
350+
const resp = await (params.fetch ?? fetch)(`${token.casUrl}/v1/xorb/default/${xorb.hash}`, {
351351
method: "POST",
352352
body: xorb.xorb,
353353
headers: {
@@ -363,7 +363,7 @@ async function uploadXorb(xorb: { hash: string; xorb: Uint8Array }, params: Uplo
363363
async function uploadShard(shard: Uint8Array, params: UploadShardsParams) {
364364
const token = await xetWriteToken(params);
365365

366-
const resp = await params.customFetch(`${token.casUrl}/v1/shard`, {
366+
const resp = await (params.fetch ?? fetch)(`${token.casUrl}/v1/shard`, {
367367
method: "POST",
368368
body: shard,
369369
headers: {

packages/hub/src/utils/xetWriteToken.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import type { RepoId } from "../types/public";
44
export interface XetWriteTokenParams {
55
accessToken: string | undefined;
66
hubUrl: string;
7-
customFetch: typeof fetch;
7+
fetch?: typeof fetch;
88
repo: RepoId;
99
rev: string;
1010
}
1111

1212
const JWT_SAFETY_PERIOD = 60_000;
1313
const JWT_CACHE_SIZE = 1_000;
1414

15-
function cacheKey(params: Omit<XetWriteTokenParams, "customFetch">): string {
15+
function cacheKey(params: Omit<XetWriteTokenParams, "fetch">): string {
1616
return JSON.stringify([params.hubUrl, params.repo, params.rev, params.accessToken]);
1717
}
1818

@@ -45,7 +45,7 @@ export async function xetWriteToken(params: XetWriteTokenParams): Promise<{ acce
4545
}
4646

4747
const promise = (async () => {
48-
const resp = await params.customFetch(
48+
const resp = await (params.fetch ?? fetch)(
4949
`${params.hubUrl}/api/${params.repo.type}s/${params.repo.name}/xet-write-token/${params.rev}`,
5050
{
5151
headers: params.accessToken

0 commit comments

Comments
 (0)