Selaa lähdekoodia

Make GUI open the relavant directory when URL is provided

Nariman Jelveh 11 kuukautta sitten
vanhempi
säilyke
581964b655
2 muutettua tiedostoa jossa 26 lisäystä ja 2 poistoa
  1. 1 1
      packages/backend/src/routers/_default.js
  2. 25 1
      src/initgui.js

+ 1 - 1
packages/backend/src/routers/_default.js

@@ -274,7 +274,7 @@ router.all('*', async function(req, res, next) {
             app_title = config.title;
 
             // /action/
-            if(path.startsWith('/action/')){
+            if(path.startsWith('/action/') || path.startsWith('/@')){
                 path = '/';
             }
             // /app/

+ 25 - 1
src/initgui.js

@@ -186,11 +186,35 @@ window.initgui = async function(options){
     // will hold the result of the whoami API call
     let whoami;
 
+    const url_paths = window.location.pathname.split('/').filter(element => element);
+    //--------------------------------------------------------------------------------------
+    // Trying to view a user's public folder?
+    // i.e. https://puter.com/@<username>
+    //--------------------------------------------------------------------------------------
+    if(url_paths[0]?.startsWith('@')){
+        let username = url_paths[0].substring(1);
+        let item_path = '/' + username + '/Public';
+
+        // check if username has valid characters
+        if(!username.match(/^[a-z0-9_]+$/i)){
+            UIAlert({
+                message: 'Invalid username.'
+            });
+        }else{
+            UIWindow({
+                path: item_path,
+                title: path.basename(item_path),
+                icon: await window.item_icon({is_dir: true, path: item_path}),
+                is_dir: true,
+                app: 'explorer',
+            });
+        }
+    }
+
     //--------------------------------------------------------------------------------------
     // Determine if an app was launched from URL
     // i.e. https://puter.com/app/<app_name>
     //--------------------------------------------------------------------------------------
-    const url_paths = window.location.pathname.split('/').filter(element => element);
     if(url_paths[0]?.toLocaleLowerCase() === 'app' && url_paths[1]){
         window.app_launched_from_url = url_paths[1];