Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an API which accepts a body of Content-Type: application/octet-… #43

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/routes/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from models.responses import *
from foss42.text.slugify import slugify
import foss42.text.humanize as hz
from fastapi.responses import JSONResponse
from fastapi import HTTPException
import hashlib

io_router = APIRouter(tags=["I/O"])

Expand Down Expand Up @@ -80,3 +83,16 @@ async def analyze_img_file(
"deduced-mime-type": deduced_type})
except:
raise internal_error_500()

@io_router.post('/octet-stream')
async def process_octet_stream(request: Request):
try:
content = await request.body()


#Calculate MD5 hash of the content
md5_hash = hashlib.md5(content).hexdigest()
return JSONResponse({"md5_hash": md5_hash})
except Exception as e:
print(e)
raise HTTPException(status_code=500, detail="Internal server error")