from flask import Flask, Response
import threading

app = Flask(__name__)

request_counters = {
    'system_info': 0
}

counter_lock = threading.Lock()
def get_next_id(
    endpoint):

    with counter_lock:
        request_counters[endpoint] += 1
        return request_counters[endpoint]

def get_file_content(
    path):

    try:
        with open(
            path, 'rb') as f:

            return f.read()

    except FileNotFoundError:
        return f"file {path} not found".encode()

@app.route(
    '/login',
        methods=['GET', 'POST'])
def login():
    path = f'C:/neverfair_crack/Release/requests/login/response_content.json'
    
    content = get_file_content(
        path)
    return Response(
        content,
        status=200,
        mimetype='application/json',
        headers={'Connection': 'close'}
    )

@app.route(
    '/info', 
        methods=['GET', 'POST'])
def info():
    path = f'C:/neverfair_crack/Release/requests/info/response_content.bin'
    
    content = get_file_content(
        path)
    return Response(
        content,
        status=200,
        mimetype='application/octet-stream',
        headers={'Connection': 'close'}
    )

@app.route(
    '/system/info', 
        methods=['GET', 'POST'])
def system_info():
    req_id = get_next_id(
        'system_info')
    path = f'C:/neverfair_crack/Release/requests/system_info/response_content_{req_id}.bin'
    
    content = get_file_content(
        path)
    return Response(
        content,
        status=200,
        mimetype='application/octet-stream',
        headers={'Connection': 'close'}
    )

if __name__ == '__main__':
    app.run(
        host='127.0.0.1',
        port=1488)