@overmap-ai/core 1.0.46-project-attachments.6 → 1.0.46-project-attachments.8

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.
@@ -4809,6 +4809,67 @@ class AttachmentService extends BaseApiService {
4809
4809
  const promise = performRequest2();
4810
4810
  return [offlineAttachment, promise];
4811
4811
  }
4812
+ async replaceProjectAttachmentFile(attachmentId, newFile) {
4813
+ const { store } = this.client;
4814
+ const attachment = store.getState().projectReducer.attachments[attachmentId];
4815
+ if (!attachment)
4816
+ throw new Error(`Attachment ${attachmentId} not found`);
4817
+ let oldFile = void 0;
4818
+ const newSha1 = await hashFile(newFile);
4819
+ const performRequest2 = async () => {
4820
+ oldFile = await this.client.files.fetchCache(attachment.file_sha1);
4821
+ if (!oldFile) {
4822
+ console.error(`Failed to fetch old file from cache for sha1 ${attachment.file_sha1}.`);
4823
+ }
4824
+ if (!newFile.objectURL) {
4825
+ throw new Error(`newFile["objectURL"] is unexpectedly ${newFile.objectURL}`);
4826
+ }
4827
+ store.dispatch(
4828
+ updateProjectAttachment({
4829
+ ...attachment,
4830
+ file_sha1: newSha1,
4831
+ file: URL.createObjectURL(newFile)
4832
+ })
4833
+ );
4834
+ await this.client.files.addCache(newFile, newSha1);
4835
+ const [fileProps] = await this.client.files.uploadFileToS3(newSha1).catch((e) => {
4836
+ store.dispatch(updateProjectAttachment(attachment));
4837
+ throw e;
4838
+ });
4839
+ const promise2 = this.enqueueRequest({
4840
+ description: "Edit attachment",
4841
+ method: HttpMethod.PATCH,
4842
+ url: `/attachments/projects/${attachment.offline_id}/`,
4843
+ isResponseBlob: false,
4844
+ payload: fileProps,
4845
+ blockers: [attachmentId, newSha1],
4846
+ blocks: [attachmentId, newSha1]
4847
+ });
4848
+ try {
4849
+ const result = await promise2;
4850
+ void this.client.files.removeCache(attachment.file_sha1);
4851
+ return result;
4852
+ } catch (e) {
4853
+ if (oldFile) {
4854
+ store.dispatch(
4855
+ updateProjectAttachment({
4856
+ ...attachment,
4857
+ file_sha1: attachment.file_sha1,
4858
+ file: URL.createObjectURL(oldFile)
4859
+ })
4860
+ );
4861
+ }
4862
+ throw e;
4863
+ }
4864
+ };
4865
+ const offlineAttachment = {
4866
+ ...attachment,
4867
+ file_sha1: newSha1,
4868
+ file: URL.createObjectURL(newFile)
4869
+ };
4870
+ const promise = performRequest2();
4871
+ return [offlineAttachment, promise];
4872
+ }
4812
4873
  /**
4813
4874
  * Deletes an attachment and associated data in the cloud, in the Redux store and the cache.
4814
4875
  * @param issueAttachmentId
@@ -7319,9 +7380,9 @@ class DocumentService extends BaseApiService {
7319
7380
  }
7320
7381
  store.dispatch(updateDocuments([document2]));
7321
7382
  const promise = this.enqueueRequest({
7322
- description: "Delete Document",
7383
+ description: "Update Document",
7323
7384
  method: HttpMethod.PATCH,
7324
- url: `/documents/${document2.offline_id}`,
7385
+ url: `/documents/${document2.offline_id}/`,
7325
7386
  payload: document2,
7326
7387
  blockers: [document2.offline_id],
7327
7388
  blocks: [document2.offline_id]
@@ -7360,7 +7421,7 @@ class DocumentService extends BaseApiService {
7360
7421
  }
7361
7422
  store.dispatch(moveDocument({ documentId, targetDocumentId, position }));
7362
7423
  const promise = this.enqueueRequest({
7363
- description: "Delete Document",
7424
+ description: "Move Document",
7364
7425
  method: HttpMethod.PATCH,
7365
7426
  url: `/documents/${documentId}/move/`,
7366
7427
  queryParams: {
@@ -7391,7 +7452,7 @@ class DocumentService extends BaseApiService {
7391
7452
  const promise = this.enqueueRequest({
7392
7453
  description: "Delete Document",
7393
7454
  method: HttpMethod.DELETE,
7394
- url: `/documents/${documentId}`,
7455
+ url: `/documents/${documentId}/`,
7395
7456
  blockers: [documentId],
7396
7457
  blocks: []
7397
7458
  });
@@ -7411,7 +7472,7 @@ class DocumentService extends BaseApiService {
7411
7472
  const result = await this.enqueueRequest({
7412
7473
  description: "Get project documents",
7413
7474
  method: HttpMethod.GET,
7414
- url: `/documents/projects/${activeProjectId}`,
7475
+ url: `/documents/projects/${activeProjectId}/`,
7415
7476
  blockers: [],
7416
7477
  blocks: []
7417
7478
  });