MegaAntiCheat / masterbase

API/Data Platform for Ingesting, Storing, and Serving Data through Postgres, and Litestar
9 stars 1 forks source link

demo_sessions should include size in bytes of the demo #36

Closed jayceslesar closed 2 months ago

jayceslesar commented 2 months ago

This allows us to display the size in the list_demos endpoint as well as change the demodata endpoint to include the size of the demo to get a progress bar

@get("/demodata", guards=[valid_key_guard, session_closed_guard, analyst_guard], sync_to_thread=False)
def demodata(request: Request, api_key: str, session_id: str) -> Stream:
    """Return the demo."""
    engine = request.app.state.engine
    bytestream_generator = demodata_helper(engine, api_key, session_id)
    file_size = os.path.getsize(session_id + ".dem") # Calculate the size of the file
    headers = {
        "Content-Disposition": f'attachment; filename="{session_id}.dem"',
        "Content-Length": str(file_size) # Include Content-Length header
    }
    return Stream(bytestream_generator, media_type=MediaType.TEXT, headers=headers)

To totally solve this issue: