stash
This commit is contained in:
parent
3b494dfa37
commit
0f51f6e33f
14 changed files with 534 additions and 356 deletions
|
|
@ -171,11 +171,17 @@ export default {
|
|||
this.dataImage = undefined;
|
||||
this.open();
|
||||
},
|
||||
save() {
|
||||
async save() {
|
||||
const mimeType = this.dataImage.split(';')[0].split(':')[1];
|
||||
const data = this.dataImage.split(',')[1];
|
||||
const raw_data = atob(data);
|
||||
const hash = nacl.crypto_hash(raw_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 bytes = Uint8Array.from(raw_data, c => c.charCodeAt(0));
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
|
||||
const hash = Array.from(new Uint8Array(hashBuffer))
|
||||
.map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
const image = {
|
||||
name: hash.slice(0, 12) + ".jpg",
|
||||
size: raw_data.length,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue