some updates
This commit is contained in:
BIN
__pycache__/main.cpython-311.pyc
Normal file
BIN
__pycache__/main.cpython-311.pyc
Normal file
Binary file not shown.
BIN
handlers/__pycache__/http.cpython-311.pyc
Normal file
BIN
handlers/__pycache__/http.cpython-311.pyc
Normal file
Binary file not shown.
BIN
handlers/__pycache__/socketio.cpython-311.pyc
Normal file
BIN
handlers/__pycache__/socketio.cpython-311.pyc
Normal file
Binary file not shown.
28
handlers/http.py
Normal file
28
handlers/http.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
from flask import request, jsonify
|
||||||
|
from misc.random_string import generate_secure_string
|
||||||
|
|
||||||
|
|
||||||
|
def init_http_handlers(app):
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return "Добро пожаловать на Flask сервер!"
|
||||||
|
|
||||||
|
@app.route('/api/new-request', methods=['POST'])
|
||||||
|
def handle_data():
|
||||||
|
# Получаем JSON из запроса
|
||||||
|
data = request.get_json()
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return jsonify({"error": "No JSON payload received"}), 400
|
||||||
|
|
||||||
|
# Выводим полученные данные в консоль
|
||||||
|
print("Полученные данные:", data)
|
||||||
|
|
||||||
|
# Формируем ответ
|
||||||
|
response = {
|
||||||
|
"message": "Data received successfully",
|
||||||
|
"yourData": data,
|
||||||
|
"conversation_id":generate_secure_string(40)
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonify(response), 200
|
||||||
25
handlers/socketio.py
Normal file
25
handlers/socketio.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
from misc.conversations import Conversations
|
||||||
|
from flask import Flask, request
|
||||||
|
from flask_socketio import join_room, leave_room
|
||||||
|
|
||||||
|
def init_socketio_handlers(socketio):
|
||||||
|
@socketio.on('connect')
|
||||||
|
def handle_connect():
|
||||||
|
print('Клиент подключился')
|
||||||
|
ip_address = request.remote_addr # Получение IP-адреса клиента
|
||||||
|
sid = request.sid
|
||||||
|
print(f'Клиент подключился с IP: {ip_address} SID: {sid}')
|
||||||
|
|
||||||
|
@socketio.on('disconnect')
|
||||||
|
def handle_disconnect():
|
||||||
|
print('Клиент отключился')
|
||||||
|
|
||||||
|
@socketio.on('new_problem')
|
||||||
|
def handle_message(data):
|
||||||
|
print('Получено сообщение:', data, ip_address)
|
||||||
|
conversation = Conversations().create(data.get("message"),data.get("work_place"),data.get("name"),data.get("problem"))
|
||||||
|
|
||||||
|
|
||||||
|
socketio.emit('response', {'data': conversation})
|
||||||
|
print(data)
|
||||||
34
main.py
34
main.py
@@ -1,32 +1,14 @@
|
|||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
from misc.random_string import generate_secure_string
|
from flask_socketio import SocketIO, emit
|
||||||
|
from handlers.http import init_http_handlers
|
||||||
|
from handlers.socketio import init_socketio_handlers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
socketio = SocketIO(app,cors_allowed_origins="*")
|
||||||
@app.route('/')
|
init_socketio_handlers(socketio)
|
||||||
def index():
|
init_http_handlers(app)
|
||||||
return "Добро пожаловать на Flask сервер!"
|
|
||||||
|
|
||||||
@app.route('/api/new-request', methods=['POST'])
|
|
||||||
def handle_data():
|
|
||||||
# Получаем JSON из запроса
|
|
||||||
data = request.get_json()
|
|
||||||
|
|
||||||
if not data:
|
|
||||||
return jsonify({"error": "No JSON payload received"}), 400
|
|
||||||
|
|
||||||
# Выводим полученные данные в консоль
|
|
||||||
print("Полученные данные:", data)
|
|
||||||
|
|
||||||
# Формируем ответ
|
|
||||||
response = {
|
|
||||||
"message": "Data received successfully",
|
|
||||||
"yourData": data,
|
|
||||||
"conversation_id":generate_secure_string(40)
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonify(response), 200
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
socketio.run(app, debug=True)
|
||||||
BIN
misc/__pycache__/conversations.cpython-311.pyc
Normal file
BIN
misc/__pycache__/conversations.cpython-311.pyc
Normal file
Binary file not shown.
BIN
misc/__pycache__/random_string.cpython-311.pyc
Normal file
BIN
misc/__pycache__/random_string.cpython-311.pyc
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
from random_string import generate_secure_string
|
from misc.random_string import generate_secure_string
|
||||||
|
|
||||||
CONVERSATIONS = {}
|
CONVERSATIONS = {}
|
||||||
"""
|
"""
|
||||||
@@ -29,5 +29,5 @@ class Conversations:
|
|||||||
"workspace":workspace,
|
"workspace":workspace,
|
||||||
"user_name":user_name,
|
"user_name":user_name,
|
||||||
"problem_type":problem_type}
|
"problem_type":problem_type}
|
||||||
return CONVERSATIONS[self.id]
|
return {"conversation":CONVERSATIONS[self.id], "id":self.id}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user