From c9905eb127918a1135d77418c0ea7ede900039df Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Mon, 17 Jul 2023 18:05:53 -0600 Subject: [PATCH] feat: added file hashing --- backend/routers/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/routers/index.ts b/backend/routers/index.ts index 68fa47f..e245e60 100644 --- a/backend/routers/index.ts +++ b/backend/routers/index.ts @@ -1,6 +1,7 @@ import fs from 'fs-extra'; import bb from 'express-busboy'; import { Router } from 'express'; +import crypto from 'crypto'; import { log } from '../log'; import { UserConfig } from '../UserConfig'; import { random } from '../generators'; @@ -51,6 +52,9 @@ router.post('/', async (req, res) => { // Get the file size const fileSize = (await fs.stat(bbFile.file)).size; + // Get the hash + const sha256 = crypto.createHash('sha256').update(await fs.readFile(bbFile.file)).digest('base64'); + // * Move the file if (!s3) await fs.move(bbFile.file, destination); else await uploadFileS3(await fs.readFile(bbFile.file), bbFile.mimetype, fileKey);