Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal to make the forStream function more clear #401

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions typescript/src/Vaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,37 @@ export class Vaas {
const guid = uuidv4();
if (this.debug) console.debug("uuid", guid);
let contentLength = 0;
this.verdictPromises.set(guid, {
this.verdictPromises.set(guid, { // waits for the verdictRequestForStream response
resolve: async (verdictResponse: VerdictResponse) => {
if (
verdictResponse.verdict !== Verdict.UNKNOWN &&
contentLength === 0
) {
if (verdictResponse.verdict !== Verdict.UNKNOWN) {
throw new VaasServerError(
"Server returned verdict without receiving content",
);
}
if (verdictResponse.verdict === Verdict.UNKNOWN) {
contentLength = stream.readableLength;
await this.upload(verdictResponse, stream, contentLength);
return;
if (verdictResponse.upload_token === undefined || verdictResponse.upload_token == "") {
throw new VaasServerError(
"No upload token set in response",
);
}
if (verdictResponse.url === undefined || verdictResponse.url == "") {
throw new VaasServerError(
"No upload url set in response",
);
}
this.verdictPromises.delete(guid);

resolve(
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic),
);
this.verdictPromises.set(guid, { // waits for the upload response
resolve: async (verdictResponse: VerdictResponse) => {
this.verdictPromises.delete(guid);
resolve(
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic),
);
},
reject: (reason) => reject(reason),
});

contentLength = stream.readableLength;
await this.upload(verdictResponse, stream, contentLength);
return;
},
reject: (reason) => reject(reason),
});
Expand Down
Loading