bedrock-ts-sdk 0.0.5 → 0.0.6

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/index.mjs CHANGED
@@ -871,8 +871,16 @@ var FileService = class {
871
871
  const aleph = this.core.getAlephService();
872
872
  const publicKey = this.core.getPublicKey();
873
873
  const uploadedFiles = [];
874
+ const existingFiles = await this.listFiles();
875
+ const filesToUpload = files.filter((file) => {
876
+ const filterIn = !existingFiles.some(
877
+ (existingFile) => !existingFile.deleted_at && existingFile.path === (directoryPath ? `${directoryPath}${file.path}` : file.path)
878
+ );
879
+ console.log(`Keeping ${file} in ? ${filterIn ? "yes" : "no"}`);
880
+ return filterIn;
881
+ });
874
882
  try {
875
- for (const file of files) {
883
+ for (const file of filesToUpload) {
876
884
  const key = EncryptionService.generateKey();
877
885
  const iv = EncryptionService.generateIv();
878
886
  let fileBuffer;
@@ -913,6 +921,39 @@ var FileService = class {
913
921
  throw new FileError(`Failed to upload files: ${error.message}`);
914
922
  }
915
923
  }
924
+ async editFileContent(fileInfo, newContent) {
925
+ const aleph = this.core.getAlephService();
926
+ const privateKey = this.core.getSubAccountPrivateKey();
927
+ try {
928
+ const postResult = await aleph.updatePost(
929
+ POST_TYPES.FILE,
930
+ fileInfo.post_hash,
931
+ [aleph.getAddress()],
932
+ FileMetaEncryptedSchema,
933
+ async (encryptedMeta) => {
934
+ const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
935
+ const encryptedContent = await EncryptionService.encryptFile(
936
+ newContent,
937
+ Buffer.from(decryptedMeta.key, "hex"),
938
+ Buffer.from(decryptedMeta.iv, "hex")
939
+ );
940
+ const uploadResult = await aleph.uploadFile(encryptedContent);
941
+ decryptedMeta.store_hash = uploadResult.item_hash;
942
+ fileInfo.store_hash = decryptedMeta.store_hash;
943
+ return await this.encryptFileMeta(decryptedMeta);
944
+ }
945
+ );
946
+ fileInfo.post_hash = postResult.item_hash;
947
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
948
+ files: aggregate.files.map(
949
+ (entry) => fileInfo.path === EncryptionService.decryptEcies(entry.path, privateKey) ? { ...entry, post_hash: fileInfo.post_hash } : entry
950
+ )
951
+ }));
952
+ return fileInfo;
953
+ } catch (error) {
954
+ throw new FileError(`Failed to edit file's content: ${error.message}`);
955
+ }
956
+ }
916
957
  /**
917
958
  * Download and decrypt a file
918
959
  * @param fileInfo - File information