yeq6x commited on
Commit
94f711b
·
1 Parent(s): 8e7e62e
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from flask import Flask, request, render_template, send_file, jsonify, send_from_directory
2
  from flask_socketio import SocketIO, join_room, leave_room, close_room, rooms, disconnect
 
3
  from flask_cors import CORS
4
  from flask_limiter import Limiter
5
  from flask_limiter.util import get_remote_address
@@ -59,7 +60,7 @@ def update_queue_status(message):
59
 
60
  def process_task(task):
61
  try:
62
- client_id = request.sid
63
  task.is_processing = True
64
  # ファイルデータをPIL Imageに変換
65
  image = Image.open(io.BytesIO(task.file_data))
@@ -118,14 +119,14 @@ connected_clients = 0
118
  tasks_per_client = {}
119
  @socketio.on('connect')
120
  def handle_connect(auth):
121
- client_id = request.sid # クライアントIDを取得
122
  join_room(client_id) # クライアントを自身のルームに入れる
123
  global connected_clients
124
  connected_clients += 1
125
 
126
  @socketio.on('disconnect')
127
  def handle_disconnect():
128
- client_id = request.sid # クライアントIDを取得
129
  leave_room(client_id) # クライアントをルームから出す
130
  global connected_clients
131
  connected_clients -= 1
@@ -148,7 +149,7 @@ def submit_task():
148
 
149
  # クライアントIPアドレスを取得
150
  client_ip = get_remote_address()
151
- client_id = request.sid # クライアントIDを取得
152
 
153
  # 同一IPからの同時タスク数を制限
154
  if tasks_per_client.get(client_ip, 0) >= 2:
 
1
  from flask import Flask, request, render_template, send_file, jsonify, send_from_directory
2
  from flask_socketio import SocketIO, join_room, leave_room, close_room, rooms, disconnect
3
+ from flask_socketio import request as socketio_request
4
  from flask_cors import CORS
5
  from flask_limiter import Limiter
6
  from flask_limiter.util import get_remote_address
 
60
 
61
  def process_task(task):
62
  try:
63
+ client_id = socketio_request.sid
64
  task.is_processing = True
65
  # ファイルデータをPIL Imageに変換
66
  image = Image.open(io.BytesIO(task.file_data))
 
119
  tasks_per_client = {}
120
  @socketio.on('connect')
121
  def handle_connect(auth):
122
+ client_id = socketio_request.sid # クライアントIDを取得
123
  join_room(client_id) # クライアントを自身のルームに入れる
124
  global connected_clients
125
  connected_clients += 1
126
 
127
  @socketio.on('disconnect')
128
  def handle_disconnect():
129
+ client_id = socketio_request.sid # クライアントIDを取得
130
  leave_room(client_id) # クライアントをルームから出す
131
  global connected_clients
132
  connected_clients -= 1
 
149
 
150
  # クライアントIPアドレスを取得
151
  client_ip = get_remote_address()
152
+ client_id = socketio_request.sid # クライアントIDを取得
153
 
154
  # 同一IPからの同時タスク数を制限
155
  if tasks_per_client.get(client_ip, 0) >= 2: