@@ -89,25 +89,20 @@ def _get_msg_sender_by_account(self, account_name):
8989 msg_sender = None
9090 return msg_sender
9191
92- def auth (self , with_socket_io = False ):
93- """Auth to SeaTable
94- """
92+ def _auth (self , workspace_id , dtable_name , dtable_uuid , access_token , dtable_server_url , dtable_db_url , use_api_gateway , with_socket_io = False ):
9593 self .jwt_exp = datetime .now () + timedelta (days = 3 )
96- url = self .server_url + '/api/v2.1/dtable/app-access-token/'
97- headers = parse_headers (self .token )
98- response = requests .get (url , headers = headers , timeout = self .timeout )
99- data = parse_response (response )
10094
101- self .dtable_server_url = parse_server_url (data .get ('dtable_server' ))
102- self .dtable_db_url = parse_server_url (data .get ('dtable_db' , '' ))
103- self .jwt_token = data .get ('access_token' )
95+ self .dtable_server_url = parse_server_url (dtable_server_url )
96+ self .dtable_db_url = parse_server_url (dtable_db_url )
97+
98+ self .jwt_token = access_token
10499 self .headers = parse_headers (self .jwt_token )
105- self .workspace_id = data .get ('workspace_id' )
106- self .dtable_uuid = data .get ('dtable_uuid' )
107- self .dtable_name = data .get ('dtable_name' )
108100
109- # api gateway entry
110- self .use_api_gateway = data .get ('use_api_gateway' )
101+ self .workspace_id = workspace_id
102+ self .dtable_name = dtable_name
103+ self .dtable_uuid = dtable_uuid
104+
105+ self .use_api_gateway = use_api_gateway
111106 if self .use_api_gateway :
112107 self .api_gateway = APIGateway (
113108 token = self .token ,
@@ -116,13 +111,34 @@ def auth(self, with_socket_io=False):
116111 headers = self .headers ,
117112 dtable_uuid = self .dtable_uuid
118113 )
114+ self .dtable_server_url = parse_server_url (self .server_url + '/api-gateway' )
115+
116+ self .is_authed = True
119117
120118 if with_socket_io is True :
121119 base = self ._clone ()
122120 self .socketIO = SocketIO (base )
123121 self .socketIO ._connect ()
124122
125- self .is_authed = True
123+ def auth (self , with_socket_io = False ):
124+ """Auth to SeaTable
125+ """
126+ self .jwt_exp = datetime .now () + timedelta (days = 3 )
127+ url = self .server_url + '/api/v2.1/dtable/app-access-token/'
128+ headers = parse_headers (self .token )
129+ response = requests .get (url , headers = headers , timeout = self .timeout )
130+ data = parse_response (response )
131+
132+ self ._auth (
133+ data .get ('workspace_id' ),
134+ data .get ('dtable_name' ),
135+ data .get ('dtable_uuid' ),
136+ data .get ('access_token' ),
137+ data .get ('dtable_server' , '' ),
138+ data .get ('dtable_db' , '' ),
139+ data .get ('use_api_gateway' ),
140+ with_socket_io = with_socket_io
141+ )
126142
127143 def _metadata_server_url (self ):
128144 return self .dtable_server_url + '/api/v1/dtables/' + self .dtable_uuid + '/metadata/'
@@ -1351,6 +1367,13 @@ def _get_temp_api_token_url(self, workspace_id, name):
13511367 'name' : name
13521368 }
13531369
1370+ def _get_base_access_token_url (self , workspace_id , name ):
1371+ return '%(server_url)s/api/v2.1/workspace/%(workspace_id)s/dtable/%(name)s/access-token/' % {
1372+ 'server_url' : self .server_url ,
1373+ 'workspace_id' : workspace_id ,
1374+ 'name' : name
1375+ }
1376+
13541377 @property
13551378 def token_headers (self ):
13561379 return {
@@ -1407,9 +1430,21 @@ def copy_base(self, src_workspace_id, base_name, dst_workspace_id):
14071430 return parse_response (response ).get ('dtable' )
14081431
14091432 def get_base (self , workspace_id , base_name , with_socket_io = False ):
1410- response = requests .get (self ._get_temp_api_token_url (workspace_id , base_name ),
1411- headers = self .token_headers , timeout = self .timeout )
1412- api_token = parse_response (response ).get ('api_token' )
1413- base = SeaTableAPI (api_token , self .server_url )
1414- base .auth (with_socket_io = with_socket_io )
1433+ response = requests .get (self ._get_base_access_token_url (workspace_id , base_name ),
1434+ headers = self .token_headers ,
1435+ timeout = self .timeout )
1436+ resp_json = response .json ()
1437+ access_token = resp_json ['access_token' ]
1438+ dtable_uuid = resp_json ['dtable_uuid' ]
1439+ base = SeaTableAPI ('' , self .server_url )
1440+ base ._auth (
1441+ workspace_id ,
1442+ base_name ,
1443+ dtable_uuid ,
1444+ access_token ,
1445+ '' ,
1446+ '' ,
1447+ True ,
1448+ with_socket_io = with_socket_io
1449+ )
14151450 return base
0 commit comments