stash
This commit is contained in:
parent
3b494dfa37
commit
0f51f6e33f
14 changed files with 534 additions and 356 deletions
|
|
@ -53,14 +53,20 @@ export default {
|
|||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
reader.readAsArrayBuffer(file)
|
||||
reader.onloadend = () => {
|
||||
reader.onloadend = async () => {
|
||||
const buffer = reader.result;
|
||||
if (!(buffer instanceof ArrayBuffer)) {
|
||||
console.log(buffer)
|
||||
reject("Not an ArrayBuffer");
|
||||
return;
|
||||
}
|
||||
const data = new Uint8Array(buffer);
|
||||
const hash = nacl.crypto_hash(data).reduce((a, b) => a + b.toString(16).padStart(2, "0"), "");
|
||||
// SHA-256 via Web Crypto - must match the backend's own content hash
|
||||
// (files/models.py, hashlib.sha256) so a hash computed here can later
|
||||
// be used to identify the same File row server-side without a mismatch.
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
||||
const hash = Array.from(new Uint8Array(hashBuffer))
|
||||
.map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
var base64 = btoa(
|
||||
data.reduce((a, b) => a + String.fromCharCode(b), '')
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue