diff --git a/apps/desktop/electron/src/service/sync.ts b/apps/desktop/electron/src/service/sync.ts index da227979b..7e0c3038b 100644 --- a/apps/desktop/electron/src/service/sync.ts +++ b/apps/desktop/electron/src/service/sync.ts @@ -53,7 +53,7 @@ function syncFiles() { } const batch: Observable<{ id: string; success: boolean }>[] = source.items - .slice(0, 10) + .slice(0, 5) .map((item) => of(item).pipe( switchMap((item) => diff --git a/libs/sdk-core/src/lib/db/upload.ts b/libs/sdk-core/src/lib/db/upload.ts index 64f346ecc..bc26b1a28 100644 --- a/libs/sdk-core/src/lib/db/upload.ts +++ b/libs/sdk-core/src/lib/db/upload.ts @@ -1,6 +1,7 @@ import { catchError, concatMap, + delay, filter, from, map, @@ -10,6 +11,7 @@ import { of, range, repeat, + retry, startWith, switchMap, take, @@ -98,9 +100,10 @@ export const uploadFile = ( 'content-type': metadata?.contentType || 'application/octet-stream', ...getFileMetadata(metadata), }; - let retries = 1; + let retries = 3; const slug = metadata?.rslug ? `?rslug=${metadata.rslug}` : ''; return nuclia.rest.post(`${path}/upload${slug}`, buffer, headers, true).pipe( + switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))), repeat(), filter((res) => retries-- === 0 || res.status !== 503), take(1), @@ -161,8 +164,9 @@ export const TUSuploadFile = ( if (uploadMetadata.length > 0) { headers['upload-metadata'] = uploadMetadata.join(','); } - let retries = 1; + let retries = 3; return nuclia.rest.post(`${path}/tusupload`, creationPayload, headers, true).pipe( + switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))), repeat(), filter((res) => retries-- === 0 || res.status !== 503), catchError((error) => of(error)), @@ -195,6 +199,8 @@ export const TUSuploadFile = ( true, ) .pipe( + switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))), + retry(3), map((res) => { if (res.status !== 200) { failed = true; diff --git a/package.json b/package.json index 50c5561bb..313c50f64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuclia", - "version": "2.7.7", + "version": "2.7.8", "license": "MIT", "author": "Nuclia.cloud", "description": "Nuclia frontend apps and libs",