From 667d8cabc90d7a8613a49de151519b61aa85d491 Mon Sep 17 00:00:00 2001 From: Weronika K Date: Thu, 25 May 2023 21:02:01 +0200 Subject: [PATCH] fix: vault context for file uploads --- src/core/node.ts | 2 +- src/core/stack.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/node.ts b/src/core/node.ts index f0ca8294..7961b249 100644 --- a/src/core/node.ts +++ b/src/core/node.ts @@ -192,7 +192,7 @@ class NodeService extends Service { } protected async setVaultContextFromNodeId(nodeId: string, type: NodeType, vaultId?: string) { - const object = await this.api.getNode(nodeId, type, this.vaultId); + const object = await this.api.getNode(nodeId, type, vaultId); this.setVaultId(object.vaultId); this.setIsPublic(object.__public__); await this.setMembershipKeys(object); diff --git a/src/core/stack.ts b/src/core/stack.ts index 29ea973a..1239835a 100644 --- a/src/core/stack.ts +++ b/src/core/stack.ts @@ -23,10 +23,13 @@ class StackService extends NodeService { ...options } await this.setVaultContext(vaultId); + this.setVaultContextForFile(); this.setActionRef(actionRefs.STACK_CREATE); this.setFunction(functions.NODE_CREATE); this.setTags(createOptions.tags); + createOptions.cacheOnly = this.vault.cacheOnly; + const state = { name: await this.processWriteString(name ? name : file.name), versions: [await this.uploadNewFileVersion(file, createOptions)], @@ -44,6 +47,7 @@ class StackService extends NodeService { */ public async import(vaultId: string, fileTxId: string, options: NodeCreateOptions = this.defaultCreateOptions): Promise { await this.setVaultContext(vaultId); + this.setVaultContextForFile(); this.setActionRef(actionRefs.STACK_CREATE); this.setFunction(functions.NODE_CREATE); @@ -72,8 +76,11 @@ class StackService extends NodeService { */ public async uploadRevision(stackId: string, file: FileLike, options: FileUploadOptions = {}): Promise { await this.setVaultContextFromNodeId(stackId, this.objectType); + this.setVaultContextForFile(); this.setActionRef(actionRefs.STACK_UPLOAD_REVISION); + options.cacheOnly = this.object.__cacheOnly__; + const state = { versions: [await this.uploadNewFileVersion(file, options)] }; @@ -91,6 +98,7 @@ class StackService extends NodeService { const stack = new Stack(await this.api.getNode(stackId, objectType.STACK, this.vaultId), null); const version = stack.getVersion(index); await this.setVaultContext(stack.vaultId); + this.setVaultContextForFile(); const { fileData, metadata } = await this.api.downloadFile(version.getUri(StorageType.S3), { public: this.isPublic }); const data = await this.processReadRaw(fileData, metadata); const name = await this.processReadString(version.name); @@ -110,9 +118,6 @@ class StackService extends NodeService { } private async uploadNewFileVersion(file: FileLike, options: FileUploadOptions): Promise { - if (this.object.__cacheOnly__) { - options.cacheOnly = true - } const { resourceTx, resourceUrl, @@ -133,8 +138,7 @@ class StackService extends NodeService { return version; } - protected async setVaultContext(vaultId: string): Promise { - await super.setVaultContext(vaultId); + protected setVaultContextForFile(): void { this.fileService.setKeys(this.keys); this.fileService.setRawDataEncryptionPublicKey(this.dataEncrypter.publicKey); this.fileService.setVaultId(this.vaultId);