Skip to content

Commit

Permalink
fix: handle public file download
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrvis committed Oct 5, 2023
1 parent a1600b1 commit c6fd42d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/core/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,24 @@ class StackService extends NodeService<Stack> {
const stack = new Stack(stackProto, stackProto.__keys__);
const version = stack.getVersion(index);
const id = version.getUri(StorageType.S3);
if (!service.isPublic) {
await version.decrypt();
}
await service.setVaultContext(stack.vaultId);

const key = await service.dataEncrypter.decryptKey(version.encryptedKey);
navigator.serviceWorker.controller.postMessage({

const workerMessage = {
type: 'init',
key: key,
chunkSize: version.chunkSize || (version.size + IV_LENGTH_IN_BYTES),
chunkSize: version.chunkSize,
size: version.size,
name: version.name,
iv: version.iv,
id: id,
url: `${service.api.config.gatewayurl}/internal/${id}`
});
} as Record<string, any>;

if (!service.isPublic) {
await version.decrypt();
const key = await service.dataEncrypter.decryptKey(version.encryptedKey);
workerMessage.key = key;
workerMessage.iv = version.iv;
}
workerMessage.name = version.name,
navigator.serviceWorker.controller.postMessage(workerMessage);

downloadPromise = new Promise((resolve, reject) => {
if (options.skipSave) {
Expand Down

0 comments on commit c6fd42d

Please sign in to comment.