1
+ import http .client
1
2
import json
2
3
import os
3
4
import pathlib
@@ -52,21 +53,21 @@ def getAPSAuth() -> APSAuth | None:
52
53
return APS_AUTH
53
54
54
55
55
- def _res_json (res ) :
56
- return json .loads (res .read ().decode (res .info ().get_param ("charset" ) or "utf-8" ))
56
+ def _res_json (res : http . client . HTTPResponse ) -> dict [ str , Any ] :
57
+ return dict ( json .loads (res .read ().decode (str ( res .info ().get_param ("charset" )) or "utf-8" ) ))
57
58
58
59
59
60
def getCodeChallenge () -> str | None :
60
61
endpoint = "https://synthesis.autodesk.com/api/aps/challenge/"
61
- res = urllib .request .urlopen (endpoint )
62
+ res : http . client . HTTPResponse = urllib .request .urlopen (endpoint )
62
63
data = _res_json (res )
63
- return data ["challenge" ]
64
+ return str ( data ["challenge" ])
64
65
65
66
66
67
def getAuth () -> APSAuth | None :
67
68
global APS_AUTH
68
69
if APS_AUTH is not None :
69
- return APS_AUTH
70
+ return APS_AUTH # type: ignore[unreachable]
70
71
71
72
currTime = time .time ()
72
73
if os .path .exists (auth_path ):
@@ -86,7 +87,7 @@ def getAuth() -> APSAuth | None:
86
87
return APS_AUTH
87
88
88
89
89
- def convertAuthToken (code : str ):
90
+ def convertAuthToken (code : str ) -> None :
90
91
global APS_AUTH
91
92
authUrl = f'https://synthesis.autodesk.com/api/aps/code/?code={ code } &redirect_uri={ urllib .parse .quote_plus ("https://synthesis.autodesk.com/api/aps/exporter/" )} '
92
93
res = urllib .request .urlopen (authUrl )
@@ -106,14 +107,14 @@ def convertAuthToken(code: str):
106
107
_ = loadUserInfo ()
107
108
108
109
109
- def removeAuth ():
110
+ def removeAuth () -> None :
110
111
global APS_AUTH , APS_USER_INFO
111
112
APS_AUTH = None
112
113
APS_USER_INFO = None
113
114
pathlib .Path .unlink (pathlib .Path (auth_path ))
114
115
115
116
116
- def refreshAuthToken ():
117
+ def refreshAuthToken () -> None :
117
118
global APS_AUTH
118
119
if APS_AUTH is None or APS_AUTH .refresh_token is None :
119
120
raise Exception ("No refresh token found." )
@@ -178,6 +179,8 @@ def loadUserInfo() -> APSUserInfo | None:
178
179
removeAuth ()
179
180
logger .error (f"User Info Error:\n { e .code } - { e .reason } " )
180
181
gm .ui .messageBox ("Please sign in again." )
182
+ finally :
183
+ return None
181
184
182
185
183
186
def getUserInfo () -> APSUserInfo | None :
@@ -259,20 +262,30 @@ def upload_mirabuf(project_id: str, folder_id: str, file_name: str, file_content
259
262
global APS_AUTH
260
263
if APS_AUTH is None :
261
264
gm .ui .messageBox ("You must login to upload designs to APS" , "USER ERROR" )
265
+ return None
266
+
262
267
auth = APS_AUTH .access_token
263
268
# Get token from APS API later
264
269
265
270
new_folder_id = get_item_id (auth , project_id , folder_id , "MirabufDir" , "folders" )
266
271
if new_folder_id is None :
267
- folder_id = create_folder (auth , project_id , folder_id , "MirabufDir" )
272
+ created_folder_id = create_folder (auth , project_id , folder_id , "MirabufDir" )
268
273
else :
269
- folder_id = new_folder_id
270
- (lineage_id , file_id , file_version ) = get_file_id (auth , project_id , folder_id , file_name )
274
+ created_folder_id = new_folder_id
275
+
276
+ if created_folder_id is None :
277
+ return None
278
+
279
+ file_id_data = get_file_id (auth , project_id , created_folder_id , file_name )
280
+ if file_id_data is None :
281
+ return None
282
+
283
+ (lineage_id , file_id , file_version ) = file_id_data
271
284
272
285
"""
273
286
Create APS Storage Location
274
287
"""
275
- object_id = create_storage_location (auth , project_id , folder_id , file_name )
288
+ object_id = create_storage_location (auth , project_id , created_folder_id , file_name )
276
289
if object_id is None :
277
290
gm .ui .messageBox ("UPLOAD ERROR" , "Object id is none; check create storage location" )
278
291
return None
@@ -297,10 +310,10 @@ def upload_mirabuf(project_id: str, folder_id: str, file_name: str, file_content
297
310
return None
298
311
if file_id != "" :
299
312
update_file_version (
300
- auth , project_id , folder_id , lineage_id , file_id , file_name , file_contents , file_version , object_id
313
+ auth , project_id , created_folder_id , lineage_id , file_id , file_name , file_contents , file_version , object_id
301
314
)
302
315
else :
303
- _lineage_info = create_first_file_version (auth , str (object_id ), project_id , str (folder_id ), file_name )
316
+ _lineage_info = create_first_file_version (auth , str (object_id ), project_id , str (created_folder_id ), file_name )
304
317
return ""
305
318
306
319
@@ -376,7 +389,7 @@ def get_item_id(auth: str, project_id: str, parent_folder_id: str, folder_name:
376
389
return ""
377
390
for item in data :
378
391
if item ["type" ] == item_type and item ["attributes" ]["name" ] == folder_name :
379
- return item ["id" ]
392
+ return str ( item ["id" ])
380
393
return None
381
394
382
395
@@ -500,7 +513,7 @@ def get_file_id(auth: str, project_id: str, folder_id: str, file_name: str) -> t
500
513
elif not file_res .ok :
501
514
gm .ui .messageBox (f"UPLOAD ERROR: { file_res .text } " , "Failed to get file" )
502
515
return None
503
- file_json : list [ dict [str , Any ] ] = file_res .json ()
516
+ file_json : dict [str , Any ] = file_res .json ()
504
517
if len (file_json ["data" ]) == 0 :
505
518
return ("" , "" , "" )
506
519
id : str = str (file_json ["data" ][0 ]["id" ])
0 commit comments