mirror of
https://github.com/DarrylNixon/binhop
synced 2024-04-22 12:37:06 -07:00
type hints and cleanup
This commit is contained in:
parent
1f5afc3000
commit
feeebd8fe5
2 changed files with 8 additions and 11 deletions
13
binhop.py
13
binhop.py
|
@ -8,9 +8,10 @@ import binwalk
|
|||
import os
|
||||
from aiohttp_compress import compress_middleware
|
||||
from aiohttp import web
|
||||
from typing import List, Tuple, Dict, Union
|
||||
|
||||
|
||||
async def scan_file(filename, base_dir):
|
||||
async def scan_file(filename: str, base_dir: str) -> List:
|
||||
try:
|
||||
scan = binwalk.scan(
|
||||
filename,
|
||||
|
@ -26,7 +27,7 @@ async def scan_file(filename, base_dir):
|
|||
print("Critical failure: ", e)
|
||||
|
||||
|
||||
async def build_listing(path):
|
||||
async def build_listing(path: str) -> Tuple[int, int, Dict]:
|
||||
result = {}
|
||||
num_files, num_dirs = 0, 0
|
||||
for item in os.listdir(path):
|
||||
|
@ -41,7 +42,7 @@ async def build_listing(path):
|
|||
return num_files, num_dirs, result
|
||||
|
||||
|
||||
async def upload_file(request):
|
||||
async def upload_file(request: web.Request) -> web.json_response:
|
||||
reader = await request.multipart()
|
||||
field = await reader.next()
|
||||
assert field.name == "file"
|
||||
|
@ -119,18 +120,18 @@ async def upload_file(request):
|
|||
return web.json_response(response_data)
|
||||
|
||||
|
||||
async def serve_index(request):
|
||||
async def serve_index(request: web.Request) -> web.FileResponse:
|
||||
return web.FileResponse("index.html")
|
||||
|
||||
|
||||
async def serve_static(request):
|
||||
async def serve_static(request: web.Request) -> Union[web.FileResponse, web.HTTPNotFound]:
|
||||
path = request.path[1:]
|
||||
if not path.startswith("static/"):
|
||||
return web.HTTPNotFound()
|
||||
return web.FileResponse(path)
|
||||
|
||||
|
||||
async def main():
|
||||
async def main() -> None:
|
||||
app = web.Application()
|
||||
app.middlewares.append(compress_middleware)
|
||||
|
||||
|
|
|
@ -209,14 +209,10 @@ async function process_upload(file) {
|
|||
});
|
||||
|
||||
if (response.ok) {
|
||||
// if (1 === 1) {
|
||||
const data = await response.json();
|
||||
// const json = '{"meta":{"name":"miwifi_r4av2_firmware_6bdd4_2.30.500.bin","sizeb":13632488,"sha1":"6cefd9d5de3b80799d0341b19043d108624dcaca","md5":"639616a5b70983903ccdd019a7a6bdd4","sig_quant":411,"duration":"00:05.457"},"offsets":[{"start":960,"end":13630770,"d":"LZMA compressed data"},{"start":1704660,"end":13621866,"d":"Squashfs filesystem"},{"start":4534008,"end":5267984,"d":"xz compressed data"},{"start":5258380,"end":5267984,"d":"ASCII cpio archive"}]}';
|
||||
// const data = JSON.parse(json);
|
||||
|
||||
const container = document.querySelector('.container');
|
||||
|
||||
// visualization
|
||||
container.innerHTML = `
|
||||
<div id="blob-row">
|
||||
<canvas id="blob" width="1200px" height="60px" style="background-color: #18232c;"></canvas>
|
||||
|
|
Loading…
Reference in a new issue