From 70d2dfe3974dded80a59012cb044dbf6d8a5a991 Mon Sep 17 00:00:00 2001 From: Anders Evenrud Date: Fri, 10 Apr 2020 22:37:00 +0200 Subject: [PATCH] Support metadata loading from list in API (#28) --- src/packages.js | 22 ++++++++++++++-------- src/providers/packages.js | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) 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})); });