diff --git a/src/packages.js b/src/packages.js index b66d2ca..b97a8d8 100644 --- a/src/packages.js +++ b/src/packages.js @@ -150,22 +150,28 @@ class Packages { /** * Reads package manifests + * @param {string[]} paths + * @param {object} user * @return {Package[]} List of packages */ - async readPackageManifests(user) { + async readPackageManifests(paths, user) { const {realpath} = this.core.make('osjs/vfs'); const {manifestFile} = this.options; - const homePath = await realpath('home:/.packages/metadata.json', user); - const systemManifest = await readOrDefault(manifestFile); - const userManifest = await readOrDefault(homePath); + + const userManifests = await Promise.all(paths.map(async p => { + const real = await realpath(`${p}/metadata.json`, user); + const list = await readOrDefault(real); + + return list.map(pkg => Object.assign({}, pkg, { + _vfs: p, + server: null + })); + })); return [ ...systemManifest, - ...userManifest.map(pkg => Object.assign({}, pkg, { - _user: true, - server: null - })) + ...[].concat(...userManifests) ]; } diff --git a/src/providers/packages.js b/src/providers/packages.js index b08397b..899ef88 100644 --- a/src/providers/packages.js +++ b/src/providers/packages.js @@ -72,7 +72,7 @@ class PackageServiceProvider extends ServiceProvider { this.core.singleton('osjs/packages', () => this.packages); routeAuthenticated('GET', '/api/packages/manifest', (req, res) => { - this.packages.readPackageManifests(req.session.user) + this.packages.readPackageManifests(req.query.root || [], req.session.user) .then(json => res.json(json)) .catch(error => res.status(400).json({error})); });