@@ -18,10 +18,10 @@ import { promisesQueueStreaming } from "../utils/promisesQueueStreaming";
1818import { sha256 } from "../utils/sha256" ;
1919import { toRepoId } from "../utils/toRepoId" ;
2020import { WebBlob } from "../utils/WebBlob" ;
21- import { createBlob } from "../utils/createBlob" ;
2221import { eventToGenerator } from "../utils/eventToGenerator" ;
2322import { base64FromBytes } from "../utils/base64FromBytes" ;
2423import { isFrontend } from "../utils/isFrontend" ;
24+ import { createBlobs } from "../utils/createBlobs" ;
2525
2626const CONCURRENT_SHAS = 5 ;
2727const CONCURRENT_LFS_UPLOADS = 5 ;
@@ -73,9 +73,15 @@ export type CommitParams = {
7373 /**
7474 * Whether to use web workers to compute SHA256 hashes.
7575 *
76- * We load hash-wasm from a CDN inside the web worker. Not sure how to do otherwise and still have a "clean" bundle.
76+ * @default false
7777 */
7878 useWebWorkers ?: boolean | { minSize ?: number ; poolSize ?: number } ;
79+ /**
80+ * Maximum depth of folders to upload. Files deeper than this will be ignored
81+ *
82+ * @default 5
83+ */
84+ maxFolderDepth ?: number ;
7985 /**
8086 * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
8187 */
@@ -144,27 +150,33 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
144150 }
145151
146152 try {
147- const allOperations = await Promise . all (
148- params . operations . map ( async ( operation ) => {
149- if ( operation . operation !== "addOrUpdate" ) {
150- return operation ;
151- }
152-
153- if ( ! ( operation . content instanceof URL ) ) {
154- /** TS trick to enforce `content` to be a `Blob` */
155- return { ...operation , content : operation . content } ;
156- }
157-
158- const lazyBlob = await createBlob ( operation . content , { fetch : params . fetch } ) ;
153+ const allOperations = (
154+ await Promise . all (
155+ params . operations . map ( async ( operation ) => {
156+ if ( operation . operation !== "addOrUpdate" ) {
157+ return operation ;
158+ }
159159
160- abortSignal ?. throwIfAborted ( ) ;
160+ if ( ! ( operation . content instanceof URL ) ) {
161+ /** TS trick to enforce `content` to be a `Blob` */
162+ return { ...operation , content : operation . content } ;
163+ }
161164
162- return {
163- ...operation ,
164- content : lazyBlob ,
165- } ;
166- } )
167- ) ;
165+ const lazyBlobs = await createBlobs ( operation . content , operation . path , {
166+ fetch : params . fetch ,
167+ maxFolderDepth : params . maxFolderDepth ,
168+ } ) ;
169+
170+ abortSignal ?. throwIfAborted ( ) ;
171+
172+ return lazyBlobs . map ( ( blob ) => ( {
173+ ...operation ,
174+ content : blob . blob ,
175+ path : blob . path ,
176+ } ) ) ;
177+ } )
178+ )
179+ ) . flat ( 1 ) ;
168180
169181 const gitAttributes = allOperations . filter ( isFileOperation ) . find ( ( op ) => op . path === ".gitattributes" ) ?. content ;
170182
0 commit comments