Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29dbf3a

Browse filesBrowse files
committed
dev: URLs to files in public directories
Already existing was the functionality to go to puter.local/@username to access the Public folder belonging to "username". This commit adds the ability for relative paths such as puter.local/@username/document.md to access /username/Public/document.md in the suggested app for handling ".md" files.
1 parent 3856ddc commit 29dbf3a
Copy full SHA for 29dbf3a

File tree

1 file changed

+86
-12
lines changed
Filter options

1 file changed

+86
-12
lines changed

‎src/gui/src/UI/UIDesktop.js

Copy file name to clipboardExpand all lines: src/gui/src/UI/UIDesktop.js
+86-12
Original file line numberDiff line numberDiff line change
@@ -1374,23 +1374,97 @@ async function UIDesktop(options) {
13741374
//--------------------------------------------------------------------------------------
13751375
const url_paths = window.location.pathname.split('/').filter(element => element);
13761376
if (url_paths[0]?.startsWith('@')) {
1377-
let username = url_paths[0].substring(1);
1377+
const username = url_paths[0].substring(1);
13781378
let item_path = '/' + username + '/Public';
1379+
if ( url_paths.length > 1 ) {
1380+
item_path += '/' + url_paths.slice(1).join('/');
1381+
}
13791382

1380-
// check if username has valid characters
1381-
if (!username.match(/^[a-z0-9_]+$/i)) {
1382-
UIAlert({
1383-
message: 'Invalid username.'
1383+
// GUARD: avoid invalid user directories
1384+
{
1385+
if (!username.match(/^[a-z0-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+
},
13841433
});
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
13921436
});
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('/')
13931459
}
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+
});
13941468
}
13951469
}
13961470

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.