@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.
@@ -4799,6 +4799,67 @@ var __publicField = (obj, key, value) => {
4799
4799
  const promise = performRequest2();
4800
4800
  return [offlineAttachment, promise];
4801
4801
  }
4802
+ async replaceProjectAttachmentFile(attachmentId, newFile) {
4803
+ const { store } = this.client;
4804
+ const attachment = store.getState().projectReducer.attachments[attachmentId];
4805
+ if (!attachment)
4806
+ throw new Error(`Attachment ${attachmentId} not found`);
4807
+ let oldFile = void 0;
4808
+ const newSha1 = await hashFile(newFile);
4809
+ const performRequest2 = async () => {
4810
+ oldFile = await this.client.files.fetchCache(attachment.file_sha1);
4811
+ if (!oldFile) {
4812
+ console.error(`Failed to fetch old file from cache for sha1 ${attachment.file_sha1}.`);
4813
+ }
4814
+ if (!newFile.objectURL) {
4815
+ throw new Error(`newFile["objectURL"] is unexpectedly ${newFile.objectURL}`);
4816
+ }
4817
+ store.dispatch(
4818
+ updateProjectAttachment({
4819
+ ...attachment,
4820
+ file_sha1: newSha1,
4821
+ file: URL.createObjectURL(newFile)
4822
+ })
4823
+ );
4824
+ await this.client.files.addCache(newFile, newSha1);
4825
+ const [fileProps] = await this.client.files.uploadFileToS3(newSha1).catch((e) => {
4826
+ store.dispatch(updateProjectAttachment(attachment));
4827
+ throw e;
4828
+ });
4829
+ const promise2 = this.enqueueRequest({
4830
+ description: "Edit attachment",
4831
+ method: HttpMethod.PATCH,
4832
+ url: `/attachments/projects/${attachment.offline_id}/`,
4833
+ isResponseBlob: false,
4834
+ payload: fileProps,
4835
+ blockers: [attachmentId, newSha1],
4836
+ blocks: [attachmentId, newSha1]
4837
+ });
4838
+ try {
4839
+ const result = await promise2;
4840
+ void this.client.files.removeCache(attachment.file_sha1);
4841
+ return result;
4842
+ } catch (e) {
4843
+ if (oldFile) {
4844
+ store.dispatch(
4845
+ updateProjectAttachment({
4846
+ ...attachment,
4847
+ file_sha1: attachment.file_sha1,
4848
+ file: URL.createObjectURL(oldFile)
4849
+ })
4850
+ );
4851
+ }
4852
+ throw e;
4853
+ }
4854
+ };
4855
+ const offlineAttachment = {
4856
+ ...attachment,
4857
+ file_sha1: newSha1,
4858
+ file: URL.createObjectURL(newFile)
4859
+ };
4860
+ const promise = performRequest2();
4861
+ return [offlineAttachment, promise];
4862
+ }
4802
4863
  /**
4803
4864
  * Deletes an attachment and associated data in the cloud, in the Redux store and the cache.
4804
4865
  * @param issueAttachmentId
@@ -7309,9 +7370,9 @@ var __publicField = (obj, key, value) => {
7309
7370
  }
7310
7371
  store.dispatch(updateDocuments([document2]));
7311
7372
  const promise = this.enqueueRequest({
7312
- description: "Delete Document",
7373
+ description: "Update Document",
7313
7374
  method: HttpMethod.PATCH,
7314
- url: `/documents/${document2.offline_id}`,
7375
+ url: `/documents/${document2.offline_id}/`,
7315
7376
  payload: document2,
7316
7377
  blockers: [document2.offline_id],
7317
7378
  blocks: [document2.offline_id]
@@ -7350,7 +7411,7 @@ var __publicField = (obj, key, value) => {
7350
7411
  }
7351
7412
  store.dispatch(moveDocument({ documentId, targetDocumentId, position }));
7352
7413
  const promise = this.enqueueRequest({
7353
- description: "Delete Document",
7414
+ description: "Move Document",
7354
7415
  method: HttpMethod.PATCH,
7355
7416
  url: `/documents/${documentId}/move/`,
7356
7417
  queryParams: {
@@ -7381,7 +7442,7 @@ var __publicField = (obj, key, value) => {
7381
7442
  const promise = this.enqueueRequest({
7382
7443
  description: "Delete Document",
7383
7444
  method: HttpMethod.DELETE,
7384
- url: `/documents/${documentId}`,
7445
+ url: `/documents/${documentId}/`,
7385
7446
  blockers: [documentId],
7386
7447
  blocks: []
7387
7448
  });
@@ -7401,7 +7462,7 @@ var __publicField = (obj, key, value) => {
7401
7462
  const result = await this.enqueueRequest({
7402
7463
  description: "Get project documents",
7403
7464
  method: HttpMethod.GET,
7404
- url: `/documents/projects/${activeProjectId}`,
7465
+ url: `/documents/projects/${activeProjectId}/`,
7405
7466
  blockers: [],
7406
7467
  blocks: []
7407
7468
  });