@overmap-ai/core 1.0.58-asset-description.6 → 1.0.58-asset-description.7
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.
|
@@ -5368,6 +5368,16 @@ var __publicField = (obj, key, value) => {
|
|
|
5368
5368
|
store.dispatch(setCategories(result));
|
|
5369
5369
|
}
|
|
5370
5370
|
}
|
|
5371
|
+
function chunkArray(arr, chunkSize) {
|
|
5372
|
+
const chunks = [];
|
|
5373
|
+
let index2 = 0;
|
|
5374
|
+
const arrLength = arr.length;
|
|
5375
|
+
while (index2 < arrLength) {
|
|
5376
|
+
chunks.push(arr.slice(index2, index2 += chunkSize));
|
|
5377
|
+
}
|
|
5378
|
+
return chunks;
|
|
5379
|
+
}
|
|
5380
|
+
const BULK_ADD_ASSET_BATCH_SIZE = 1e3;
|
|
5371
5381
|
class AssetService extends BaseApiService {
|
|
5372
5382
|
// Basic CRUD functions
|
|
5373
5383
|
add(asset, workspaceId) {
|
|
@@ -5444,36 +5454,49 @@ var __publicField = (obj, key, value) => {
|
|
|
5444
5454
|
throw err;
|
|
5445
5455
|
});
|
|
5446
5456
|
}
|
|
5447
|
-
|
|
5457
|
+
addBulk(assetsToCreate, workspaceId, assetTypeId) {
|
|
5458
|
+
const { store } = this.client;
|
|
5448
5459
|
const fullAssets = assetsToCreate.map((asset) => {
|
|
5449
5460
|
return { ...offline(asset), submitted_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
5450
5461
|
});
|
|
5451
|
-
const
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
workspace_id: workspaceId.toString()
|
|
5459
|
-
},
|
|
5460
|
-
payload: {
|
|
5461
|
-
assets: fullAssets
|
|
5462
|
-
},
|
|
5463
|
-
blockers: [assetTypeId],
|
|
5464
|
-
blocks: fullAssets.map((c) => c.offline_id)
|
|
5465
|
-
});
|
|
5466
|
-
void promise.then((result) => {
|
|
5467
|
-
for (const assets of Object.values(result)) {
|
|
5468
|
-
store.dispatch(updateAsset(assets));
|
|
5469
|
-
}
|
|
5470
|
-
}).catch((e) => {
|
|
5471
|
-
for (const asset of fullAssets) {
|
|
5472
|
-
store.dispatch(removeAsset(asset.offline_id));
|
|
5473
|
-
}
|
|
5474
|
-
throw e;
|
|
5462
|
+
const assetBatches = chunkArray(fullAssets, BULK_ADD_ASSET_BATCH_SIZE).map((assetBatch) => {
|
|
5463
|
+
return {
|
|
5464
|
+
batchId: uuid.v4(),
|
|
5465
|
+
payload: {
|
|
5466
|
+
assets: assetBatch
|
|
5467
|
+
}
|
|
5468
|
+
};
|
|
5475
5469
|
});
|
|
5476
|
-
|
|
5470
|
+
store.dispatch(addAssetsInBatches(fullAssets));
|
|
5471
|
+
let prevBatchId = null;
|
|
5472
|
+
const batchPromises = Promise.all(
|
|
5473
|
+
assetBatches.map((assetBatch) => {
|
|
5474
|
+
const { batchId, payload } = assetBatch;
|
|
5475
|
+
const promise = this.client.enqueueRequest({
|
|
5476
|
+
description: "Batch create assets",
|
|
5477
|
+
method: HttpMethod.POST,
|
|
5478
|
+
url: `/assets/types/${assetTypeId}/add-assets/`,
|
|
5479
|
+
queryParams: {
|
|
5480
|
+
workspace_id: workspaceId.toString()
|
|
5481
|
+
},
|
|
5482
|
+
payload,
|
|
5483
|
+
blockers: prevBatchId ? [assetTypeId, prevBatchId] : [assetTypeId],
|
|
5484
|
+
blocks: assetBatch.payload.assets.map((c) => c.offline_id).concat([batchId])
|
|
5485
|
+
});
|
|
5486
|
+
promise.then((result) => {
|
|
5487
|
+
for (const assets of Object.values(result)) {
|
|
5488
|
+
store.dispatch(updateAsset(assets));
|
|
5489
|
+
}
|
|
5490
|
+
}).catch(() => {
|
|
5491
|
+
for (const asset of assetBatch.payload.assets) {
|
|
5492
|
+
store.dispatch(removeAsset(asset.offline_id));
|
|
5493
|
+
}
|
|
5494
|
+
});
|
|
5495
|
+
prevBatchId = assetBatch.batchId;
|
|
5496
|
+
return promise;
|
|
5497
|
+
})
|
|
5498
|
+
);
|
|
5499
|
+
return [fullAssets, batchPromises.then((result) => result)];
|
|
5477
5500
|
}
|
|
5478
5501
|
async refreshStore() {
|
|
5479
5502
|
const { store } = this.client;
|
|
@@ -7239,15 +7262,6 @@ var __publicField = (obj, key, value) => {
|
|
|
7239
7262
|
store.dispatch(setFormRevisionAttachments(Object.values(result.attachments)));
|
|
7240
7263
|
}
|
|
7241
7264
|
}
|
|
7242
|
-
function chunkArray(arr, chunkSize) {
|
|
7243
|
-
const chunks = [];
|
|
7244
|
-
let index2 = 0;
|
|
7245
|
-
const arrLength = arr.length;
|
|
7246
|
-
while (index2 < arrLength) {
|
|
7247
|
-
chunks.push(arr.slice(index2, index2 += chunkSize));
|
|
7248
|
-
}
|
|
7249
|
-
return chunks;
|
|
7250
|
-
}
|
|
7251
7265
|
const isArrayOfFiles = (value) => {
|
|
7252
7266
|
return Array.isArray(value) && value[0] instanceof File;
|
|
7253
7267
|
};
|