Explorar o código

feat: add appdata permission (if applicable) on app share

KernelDeimos hai 11 meses
pai
achega
9751fd92a5
Modificáronse 1 ficheiros con 21 adicións e 0 borrados
  1. 21 0
      packages/backend/src/routers/share.js

+ 21 - 0
packages/backend/src/routers/share.js

@@ -427,6 +427,12 @@ const v0_2 = async (req, res) => {
                         : { id: { name: thing.name } }
                         : { id: { name: thing.name } }
                 });
                 });
         }
         }
+        
+        app.metadata = db.case({
+            mysql: () => app.metadata,
+            otherwise: () => JSON.parse(app.metadata ?? '{}')
+        })();
+        
         item.app = app;
         item.app = app;
     }
     }
     
     
@@ -451,6 +457,21 @@ const v0_2 = async (req, res) => {
         )
         )
     }
     }
 
 
+    // Process: conditionally add permission for AppData
+    for ( const item of shares_work.list() ) {
+        if ( item.type !== 'app' ) continue;
+        if ( ! item.app.metadata?.shared_appdata ) continue;
+        
+        const app_owner = await get_user({ id: item.app.owner_user_id });
+        
+        const appdatadir =
+            `/${app_owner.username}/AppData/${item.app.uid}`;
+        const appdatadir_perm =
+            PermissionUtil.join('fs', appdatadir, 'write');
+
+        item.share_intent.permissions.push(appdatadir_perm);
+    }
+
     shares_work.clear_invalid();
     shares_work.clear_invalid();
 
 
     // Mark files as successful; further errors will be
     // Mark files as successful; further errors will be