Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -19,7 +19,11 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(mess
|
|
19 |
SESSION_DATA = {}
|
20 |
SESSION_LOCKS = {}
|
21 |
|
22 |
-
def
|
|
|
|
|
|
|
|
|
23 |
sid = flask.request.cookies.get('session-id')
|
24 |
if not sid:
|
25 |
sid = str(uuid.uuid4())
|
@@ -147,6 +151,7 @@ def get_split_results_placeholder():
|
|
147 |
|
148 |
app.layout = dbc.Container(
|
149 |
[
|
|
|
150 |
dcc.Store(id='session-store', storage_type='session'),
|
151 |
html.Div(id='dummy-div', style={'display': 'none'}),
|
152 |
dbc.Row(
|
@@ -198,6 +203,18 @@ app.layout = dbc.Container(
|
|
198 |
className="p-4"
|
199 |
)
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
@app.callback(
|
202 |
Output('file-info', 'children'),
|
203 |
Output('split-btn', 'disabled'),
|
@@ -209,12 +226,13 @@ app.layout = dbc.Container(
|
|
209 |
Input({'type': 'delete-upload-btn', 'index': ALL}, 'n_clicks'),
|
210 |
Input('split-btn', 'n_clicks'),
|
211 |
State('session-store', 'data'),
|
|
|
212 |
prevent_initial_call=True
|
213 |
)
|
214 |
-
def handle_upload(contents, filename, clear_n, delete_upload_n_list, split_n, session_data):
|
215 |
trigger = ctx.triggered_id
|
216 |
-
|
217 |
-
|
218 |
if not session_id:
|
219 |
session_id = str(uuid.uuid4())
|
220 |
flask.g.session_id = session_id
|
@@ -381,18 +399,22 @@ def download_zip_file(session_id, filename):
|
|
381 |
|
382 |
@app.callback(
|
383 |
Output('dummy-div', 'children'),
|
384 |
-
Input('session-store', 'data'),
|
385 |
-
prevent_initial_call=
|
386 |
)
|
387 |
-
def set_cookie_on_load(
|
388 |
-
|
|
|
389 |
resp = flask.make_response("")
|
390 |
resp.set_cookie('session-id', session_id, max_age=60*60*24*3)
|
|
|
391 |
return ""
|
392 |
|
393 |
@app.server.before_request
|
394 |
def persist_session_cookie():
|
395 |
-
session_id =
|
|
|
|
|
396 |
flask.g.session_id = session_id
|
397 |
|
398 |
if __name__ == '__main__':
|
|
|
19 |
SESSION_DATA = {}
|
20 |
SESSION_LOCKS = {}
|
21 |
|
22 |
+
def get_session_id_from_cookie():
|
23 |
+
sid = flask.request.cookies.get('session-id')
|
24 |
+
return sid
|
25 |
+
|
26 |
+
def get_or_create_session_id():
|
27 |
sid = flask.request.cookies.get('session-id')
|
28 |
if not sid:
|
29 |
sid = str(uuid.uuid4())
|
|
|
151 |
|
152 |
app.layout = dbc.Container(
|
153 |
[
|
154 |
+
dcc.Store(id='session-id-store', storage_type='session'),
|
155 |
dcc.Store(id='session-store', storage_type='session'),
|
156 |
html.Div(id='dummy-div', style={'display': 'none'}),
|
157 |
dbc.Row(
|
|
|
203 |
className="p-4"
|
204 |
)
|
205 |
|
206 |
+
@app.callback(
|
207 |
+
Output('session-id-store', 'data'),
|
208 |
+
Input('dummy-div', 'children'),
|
209 |
+
prevent_initial_call=False
|
210 |
+
)
|
211 |
+
def ensure_session_id(_):
|
212 |
+
sid = get_session_id_from_cookie()
|
213 |
+
if not sid:
|
214 |
+
sid = str(uuid.uuid4())
|
215 |
+
flask.g.session_id = sid
|
216 |
+
return sid
|
217 |
+
|
218 |
@app.callback(
|
219 |
Output('file-info', 'children'),
|
220 |
Output('split-btn', 'disabled'),
|
|
|
226 |
Input({'type': 'delete-upload-btn', 'index': ALL}, 'n_clicks'),
|
227 |
Input('split-btn', 'n_clicks'),
|
228 |
State('session-store', 'data'),
|
229 |
+
State('session-id-store', 'data'),
|
230 |
prevent_initial_call=True
|
231 |
)
|
232 |
+
def handle_upload(contents, filename, clear_n, delete_upload_n_list, split_n, session_data, session_id):
|
233 |
trigger = ctx.triggered_id
|
234 |
+
|
235 |
+
# Always use session id from store
|
236 |
if not session_id:
|
237 |
session_id = str(uuid.uuid4())
|
238 |
flask.g.session_id = session_id
|
|
|
399 |
|
400 |
@app.callback(
|
401 |
Output('dummy-div', 'children'),
|
402 |
+
Input('session-id-store', 'data'),
|
403 |
+
prevent_initial_call=False
|
404 |
)
|
405 |
+
def set_cookie_on_load(session_id):
|
406 |
+
if not session_id:
|
407 |
+
session_id = str(uuid.uuid4())
|
408 |
resp = flask.make_response("")
|
409 |
resp.set_cookie('session-id', session_id, max_age=60*60*24*3)
|
410 |
+
flask.g.session_id = session_id
|
411 |
return ""
|
412 |
|
413 |
@app.server.before_request
|
414 |
def persist_session_cookie():
|
415 |
+
session_id = get_session_id_from_cookie()
|
416 |
+
if not session_id:
|
417 |
+
session_id = str(uuid.uuid4())
|
418 |
flask.g.session_id = session_id
|
419 |
|
420 |
if __name__ == '__main__':
|