Skip to content

Commit

Permalink
Support metadata loading from list in API (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 11, 2020
1 parent bddf576 commit 547eb7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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}));
});
Expand Down

0 comments on commit 547eb7e

Please sign in to comment.