@overmap-ai/core 1.0.46-project-attachments.6 → 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.
package/dist/overmap-core.js
CHANGED
|
@@ -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
|