-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Secure upload mechanism (#153)
* fix: axios header issue * Feature: secure upload * Refactor: more simple code * Fix & refactor --------- Co-authored-by: Bonjour Internet <[email protected]>
- Loading branch information
Showing
2 changed files
with
134 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import shajs from "sha.js"; | ||
|
||
export async function blobToBuffer(blob: Blob): Promise<Buffer> { | ||
return new Promise<Buffer>((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
if (reader.result instanceof ArrayBuffer) { | ||
resolve(Buffer.from(reader.result)); | ||
} else { | ||
reject("Failed to convert Blob to Buffer."); | ||
} | ||
}; | ||
reader.readAsArrayBuffer(blob); | ||
}); | ||
} | ||
|
||
export function calculateSHA256Hash(data: ArrayBuffer | Buffer): string { | ||
const buffer = Buffer.from(data); | ||
return new shajs.sha256().update(buffer).digest("hex"); | ||
} |