Ver código fonte

Use cookies for resource handler (#857)

Dinh Long Nguyen 1 ano atrás
pai
commit
ffb6b2b461

+ 4 - 0
frontend/taipy-gui/base/src/index.ts

@@ -4,3 +4,7 @@ import { VariableModuleData } from "./variableManager";
 export default TaipyApp;
 export { TaipyApp, createApp };
 export type { OnChangeHandler, OnInitHandler, VariableModuleData };
+
+window.addEventListener("beforeunload", () => {
+    document.cookie = "tprh=;path=/;Max-Age=-99999999;";
+});

+ 9 - 1
frontend/taipy-gui/src/components/Taipy/Navigate.tsx

@@ -32,13 +32,21 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
         if (to) {
             const tos = to === "/" ? to : "/" + to;
             const searchParams = new URLSearchParams(params || "");
+            // Handle Resource Handler Id
+            let tprh: string | null = null;
+            if (searchParams.has("tprh")) {
+                tprh = searchParams.get("tprh");
+                searchParams.delete("tprh");
+            }
             if (Object.keys(state.locations || {}).some((route) => tos === route)) {
                 const searchParamsLocation = new URLSearchParams(location.search);
                 if (force && location.pathname === tos && searchParamsLocation.toString() === searchParams.toString()) {
                     navigate(0);
                 } else {
                     navigate({ pathname: to, search: `?${searchParams.toString()}` });
-                    if (searchParams.has("tprh")) {
+                    if (tprh !== null) {
+                        // Add a session cookie for the resource handler id
+                        document.cookie = `tprh=${tprh};path=/;`;
                         navigate(0);
                     }
                 }

+ 1 - 5
taipy/gui/server.py

@@ -22,7 +22,6 @@ import typing as t
 import webbrowser
 from importlib import util
 from random import randint
-from urllib.parse import parse_qsl, urlparse
 
 from flask import Blueprint, Flask, json, jsonify, render_template, request, send_from_directory
 from flask_cors import CORS
@@ -148,10 +147,7 @@ class _Server:
         @taipy_bp.route("/", defaults={"path": ""})
         @taipy_bp.route("/<path:path>")
         def my_index(path):
-            resource_handler_id = dict(parse_qsl(urlparse(request.referrer or "").query)).get(
-                _Server._RESOURCE_HANDLER_ARG
-            )
-            resource_handler_id = resource_handler_id or request.args.get(_Server._RESOURCE_HANDLER_ARG, None)
+            resource_handler_id = request.cookies.get(_Server._RESOURCE_HANDLER_ARG, None)
             if resource_handler_id is not None:
                 resource_handler = _ExternalResourceHandlerManager().get(resource_handler_id)
                 if resource_handler is None: