Skip to content

Commit 581964b

Browse files
committed
Make GUI open the relavant directory when URL is provided
1 parent c1647a5 commit 581964b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/backend/src/routers/_default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ router.all('*', async function(req, res, next) {
274274
app_title = config.title;
275275

276276
// /action/
277-
if(path.startsWith('/action/')){
277+
if(path.startsWith('/action/') || path.startsWith('/@')){
278278
path = '/';
279279
}
280280
// /app/

src/initgui.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,35 @@ window.initgui = async function(options){
186186
// will hold the result of the whoami API call
187187
let whoami;
188188

189+
const url_paths = window.location.pathname.split('/').filter(element => element);
190+
//--------------------------------------------------------------------------------------
191+
// Trying to view a user's public folder?
192+
// i.e. https://puter.com/@<username>
193+
//--------------------------------------------------------------------------------------
194+
if(url_paths[0]?.startsWith('@')){
195+
let username = url_paths[0].substring(1);
196+
let item_path = '/' + username + '/Public';
197+
198+
// check if username has valid characters
199+
if(!username.match(/^[a-z0-9_]+$/i)){
200+
UIAlert({
201+
message: 'Invalid username.'
202+
});
203+
}else{
204+
UIWindow({
205+
path: item_path,
206+
title: path.basename(item_path),
207+
icon: await window.item_icon({is_dir: true, path: item_path}),
208+
is_dir: true,
209+
app: 'explorer',
210+
});
211+
}
212+
}
213+
189214
//--------------------------------------------------------------------------------------
190215
// Determine if an app was launched from URL
191216
// i.e. https://puter.com/app/<app_name>
192217
//--------------------------------------------------------------------------------------
193-
const url_paths = window.location.pathname.split('/').filter(element => element);
194218
if(url_paths[0]?.toLocaleLowerCase() === 'app' && url_paths[1]){
195219
window.app_launched_from_url = url_paths[1];
196220

0 commit comments

Comments
 (0)