@overmap-ai/core 1.0.46-project-attachments.5 → 1.0.46-project-attachments.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.
@@ -4528,7 +4528,7 @@ var __publicField = (obj, key, value) => {
4528
4528
  const promise = this.enqueueRequest({
4529
4529
  description: "Create attachment",
4530
4530
  method: HttpMethod.POST,
4531
- url: `/components/types/${project}/attach/`,
4531
+ url: `/projects/${project}/attach/`,
4532
4532
  blocks: [offline_id, project.toString()],
4533
4533
  blockers: [file_sha1],
4534
4534
  payload: {
@@ -4605,7 +4605,7 @@ var __publicField = (obj, key, value) => {
4605
4605
  return photoAttachmentPromise(file);
4606
4606
  });
4607
4607
  }
4608
- attachFilesToProjectType(filesToSubmit, projectId) {
4608
+ attachFilesToProject(filesToSubmit, projectId) {
4609
4609
  return filesToSubmit.map((file) => {
4610
4610
  if (!(file instanceof File)) {
4611
4611
  throw new Error("Expected a File instance.");
@@ -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