Comparing version 0.0.6 to 0.0.7
@@ -10,2 +10,3 @@ import MistBase from './MistBase'; | ||
private checkCompletion; | ||
updateConfig: (config: any) => any; | ||
} |
@@ -5,3 +5,6 @@ export declare enum WorkerMessages { | ||
START = "start", | ||
ERROR = "error" | ||
UPLOAD = "upload", | ||
CANCEL = "cancel", | ||
ERROR = "error", | ||
CONFIG = "config" | ||
} | ||
@@ -8,0 +11,0 @@ export interface IConfig { |
declare class Worker { | ||
evaporate: any; | ||
signHeaders: any; | ||
constructor(); | ||
@@ -4,0 +5,0 @@ private listenToEvents; |
{ | ||
"name": "dice-mist", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A wrapper for the evaporate library allowing use in a web worker.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,3 +20,3 @@ import MistBase from './MistBase'; | ||
this.worker.postMessage({ | ||
type: 'upload', | ||
type: WorkerMessages.UPLOAD, | ||
config, | ||
@@ -64,3 +64,3 @@ files, | ||
this.checkCompletion(); | ||
this.worker.postMessage({id, type: 'cancel' }); | ||
this.worker.postMessage({id, type: WorkerMessages.CANCEL }); | ||
}) | ||
@@ -73,2 +73,4 @@ | ||
} | ||
public updateConfig = config => this.worker.postMessage({ type: WorkerMessages.CONFIG, config }); | ||
} |
@@ -5,3 +5,6 @@ export enum WorkerMessages { | ||
START = 'start', | ||
ERROR = 'error' | ||
UPLOAD = 'upload', | ||
CANCEL = 'cancel', | ||
ERROR = 'error', | ||
CONFIG = 'config' | ||
} | ||
@@ -8,0 +11,0 @@ |
import * as Evaporate from 'evaporate'; | ||
import * as SparkMD5 from 'spark-md5'; | ||
import { sha256 } from 'js-sha256'; | ||
import { WorkerMessages } from './types'; | ||
class Worker { | ||
evaporate: any; | ||
signHeaders: any; | ||
constructor() { | ||
@@ -18,3 +21,3 @@ this.evaporate = null; | ||
switch (type) { | ||
case 'cancel': | ||
case WorkerMessages.CANCEL: | ||
if (this.evaporate) this.evaporate.cancel(id); | ||
@@ -24,3 +27,5 @@ // @ts-ignore | ||
break; | ||
case 'upload': | ||
case WorkerMessages.UPLOAD: | ||
// Save initial values | ||
this.signHeaders = { ...config.signHeaders }; | ||
const augmentedConfig = this.augmentConfig(config); | ||
@@ -30,2 +35,6 @@ this.evaporate = await Evaporate.create(augmentedConfig); | ||
break; | ||
case WorkerMessages.CONFIG: | ||
// Save updated values | ||
this.signHeaders = { ...config.signHeaders }; | ||
break; | ||
} | ||
@@ -43,12 +52,12 @@ }; | ||
bucket, | ||
progress: progress => postMessage({ type: 'progress', progress, id }) | ||
progress: progress => postMessage({ type: WorkerMessages.PROGRESS, progress, id }) | ||
}; | ||
postMessage({type: 'start', id, cancelId}); | ||
postMessage({type: WorkerMessages.START, id, cancelId}); | ||
try { | ||
const awsObjectKey = await this.evaporate.add(formattedConfig); | ||
postMessage({type: 'success', id, data, awsObjectKey}); | ||
postMessage({type: WorkerMessages.SUCCESS, id, data, awsObjectKey}); | ||
} catch (reason) { | ||
postMessage({type: 'error', reason, id }); | ||
postMessage({type: WorkerMessages.ERROR, reason, id }); | ||
} | ||
@@ -66,3 +75,11 @@ }); | ||
return hash.hex(); | ||
} | ||
}, | ||
// Transform values into getters | ||
signHeaders: Object.keys(config.signHeaders) | ||
.reduce((headers, key) => { | ||
return { | ||
...headers, | ||
[key]: () => this.signHeaders[key] | ||
}; | ||
}, {}) | ||
}) | ||
@@ -69,0 +86,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1559948
32
935
1