Initial commit

This commit is contained in:
2021-12-30 15:34:27 +00:00
commit 54c75ff97b
18 changed files with 1843 additions and 0 deletions

45
web/tasks.py Normal file
View File

@@ -0,0 +1,45 @@
import hashlib
import os
import time
from rq import get_current_job
BLOCKSIZE = 65535
def check_hash(algorithm, filename, hashval):
job = get_current_job()
if job:
job.meta["status"] = "Processing: 0%"
job.save_meta()
if filename == "" or hashval == "":
return "ERROR: Invalid Arguents"
if algorithm == "sha256":
hashfunc = hashlib.sha256()
else:
return "ERROR: Unknown Algorithm"
filesize = os.path.getsize(filename)
filepos = 0
with open(filename, "rb") as f:
file_buffer = f.read(BLOCKSIZE)
filepos += len(file_buffer)
job.meta["status"] = "Processing: {}%".format(filepos / filesize * 100)
job.save_meta()
while len(file_buffer) > 0:
hashfunc.update(file_buffer)
file_buffer = f.read(BLOCKSIZE)
job.meta["status"] = "Processing: {}%".format(filesize / filesize * 100)
job.save_meta()
# time.sleep(5)
if hashfunc.hexdigest() == hashval:
job.meta["status"] = "OK: Hash Value Matches"
else:
job.meta["status"] = "FAILED: Invalid Hash"
job.save_meta()