<commit_before># -*- coding: utf-8 -*-

from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse

from qllr.app import App
from qllr.settings import RUN_POST_PROCESS
from qllr.submission import submit_match  # TODO: перенеси в этот блупринт

bp = App()
bp.json_only_mode = True


@bp.route("/submit", methods=["POST"])
async def http_stats_submit(request: Request):
    # https://github.com/PredatH0r/XonStat/blob/cfeae1b0c35c48a9f14afa98717c39aa100cde59/feeder/feeder.node.js#L989
    if request.headers.get("X-D0-Blind-Id-Detached-Signature") != "dummy":
        raise HTTPException(403, "signature header invalid or not found")

    if request.client.host not in [
        "::ffff:127.0.0.1",
        "::1",
        "127.0.0.1",
        "testclient",
    ]:
        raise HTTPException(403, "non-loopback requests are not allowed")

    match_report = await request.body()
    result = await submit_match(match_report.decode("utf-8"))
    if result["ok"] == False:
        raise HTTPException(422, result["message"])
    else:
        if RUN_POST_PROCESS is False:
            raise HTTPException(202, result["message"])
        else:
            return JSONResponse(result)<commit_msg>Remove result checking in http_stats_submit, as submit_match raises exception on fail<commit_after># -*- coding: utf-8 -*-

from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse

from qllr.app import App
from qllr.settings import RUN_POST_PROCESS
from qllr.submission import submit_match  # TODO: перенеси в этот блупринт

bp = App()
bp.json_only_mode = True


@bp.route("/submit", methods=["POST"])
async def http_stats_submit(request: Request):
    # https://github.com/PredatH0r/XonStat/blob/cfeae1b0c35c48a9f14afa98717c39aa100cde59/feeder/feeder.node.js#L989
    if request.headers.get("X-D0-Blind-Id-Detached-Signature") != "dummy":
        raise HTTPException(403, "signature header invalid or not found")

    if request.client.host not in [
        "::ffff:127.0.0.1",
        "::1",
        "127.0.0.1",
        "testclient",
    ]:
        raise HTTPException(403, "non-loopback requests are not allowed")

    match_report = await request.body()
    result = await submit_match(match_report.decode("utf-8"))
    if RUN_POST_PROCESS is False:
        raise HTTPException(202, result["message"])

    return JSONResponse(result)
{'fraction_non_alphanumeric': 0.11505853855470327, 'fraction_numerical': 0.04158255954784013, 'mean_word_length': 3.6843100189035916, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4213891', 'n_tokens_mistral': 853, 'n_tokens_neox': 794, 'n_words': 185}