@@ -1374,23 +1374,97 @@ async function UIDesktop(options) {
1374
1374
//--------------------------------------------------------------------------------------
1375
1375
const url_paths = window . location . pathname . split ( '/' ) . filter ( element => element ) ;
1376
1376
if ( url_paths [ 0 ] ?. startsWith ( '@' ) ) {
1377
- let username = url_paths [ 0 ] . substring ( 1 ) ;
1377
+ const username = url_paths [ 0 ] . substring ( 1 ) ;
1378
1378
let item_path = '/' + username + '/Public' ;
1379
+ if ( url_paths . length > 1 ) {
1380
+ item_path += '/' + url_paths . slice ( 1 ) . join ( '/' ) ;
1381
+ }
1379
1382
1380
- // check if username has valid characters
1381
- if ( ! username . match ( / ^ [ a - z 0 - 9 _ ] + $ / i) ) {
1382
- UIAlert ( {
1383
- message : 'Invalid username.'
1383
+ // GUARD: avoid invalid user directories
1384
+ {
1385
+ if ( ! username . match ( / ^ [ a - z 0 - 9 _ ] + $ / i) ) {
1386
+ UIAlert ( {
1387
+ message : 'Invalid username.'
1388
+ } ) ;
1389
+ return ;
1390
+ }
1391
+ }
1392
+
1393
+ const stat = await puter . fs . stat ( item_path ) ;
1394
+ console . log ( 'stat result' , stat ) ;
1395
+
1396
+ // TODO: DRY everything here with open_item. Unfortunately we can't
1397
+ // use open_item here because it's coupled with UI logic;
1398
+ // it requires a UIItem element and cannot operate on a
1399
+ // file path on its own.
1400
+ if ( ! stat . is_dir ) {
1401
+ if ( stat . associated_app ) {
1402
+ launch_app ( { name : stat . associated_app . name } ) ;
1403
+ return ;
1404
+ }
1405
+
1406
+ const ext_pref =
1407
+ window . user_preferences [ `default_apps${ path . extname ( item_path ) . toLowerCase ( ) } ` ] ;
1408
+
1409
+ if ( ext_pref ) {
1410
+ launch_app ( {
1411
+ name : ext_pref ,
1412
+ file_path : item_path ,
1413
+ } ) ;
1414
+ return ;
1415
+ }
1416
+
1417
+
1418
+ const open_item_meta = await $ . ajax ( {
1419
+ url : window . api_origin + "/open_item" ,
1420
+ type : 'POST' ,
1421
+ contentType : "application/json" ,
1422
+ data : JSON . stringify ( {
1423
+ path : item_path ,
1424
+ } ) ,
1425
+ headers : {
1426
+ "Authorization" : "Bearer " + window . auth_token
1427
+ } ,
1428
+ statusCode : {
1429
+ 401 : function ( ) {
1430
+ window . logout ( ) ;
1431
+ } ,
1432
+ } ,
1384
1433
} ) ;
1385
- } else {
1386
- UIWindow ( {
1387
- path : item_path ,
1388
- title : path . basename ( item_path ) ,
1389
- icon : await item_icon ( { is_dir : true , path : item_path } ) ,
1390
- is_dir : true ,
1391
- app : 'explorer' ,
1434
+ const suggested_apps = open_item_meta ?. suggested_apps ?? await window . suggest_apps_for_fsentry ( {
1435
+ path : item_path
1392
1436
} ) ;
1437
+
1438
+ // Note: I'm not adding unzipping logic here. We'll wait until
1439
+ // we've refactored open_item so that Puter can have a
1440
+ // properly-reusable open function.
1441
+ if ( suggested_apps . length !== 0 ) {
1442
+ launch_app ( {
1443
+ name : suggested_apps [ 0 ] . name ,
1444
+ token : open_item_meta . token ,
1445
+ file_path : item_path ,
1446
+ app_obj : suggested_apps [ 0 ] ,
1447
+ window_title : path . basename ( item_path ) ,
1448
+ maximized : options . maximized ,
1449
+ file_signature : open_item_meta . signature ,
1450
+ } ) ;
1451
+ return ;
1452
+ }
1453
+
1454
+ await UIAlert ( {
1455
+ message : 'Cannot find an app to open this file; ' +
1456
+ 'opening directory instead.'
1457
+ } ) ;
1458
+ item_path = item_path . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' )
1393
1459
}
1460
+
1461
+ UIWindow ( {
1462
+ path : item_path ,
1463
+ title : path . basename ( item_path ) ,
1464
+ icon : await item_icon ( { is_dir : true , path : item_path } ) ,
1465
+ is_dir : true ,
1466
+ app : 'explorer' ,
1467
+ } ) ;
1394
1468
}
1395
1469
}
1396
1470
0 commit comments