From cb0bdbdc65432610a14b9ed90a6c2caf2fd2e07c Mon Sep 17 00:00:00 2001 From: Anders Evenrud Date: Sat, 11 Apr 2020 00:12:00 +0200 Subject: [PATCH] Depend on client-side package installation root (#28) --- src/packages.js | 10 +++++++++- src/providers/packages.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/packages.js b/src/packages.js index a857045..9ff4d46 100644 --- a/src/packages.js +++ b/src/packages.js @@ -156,12 +156,16 @@ class Packages { * @param {object} user */ async installPackage(url, options, user) { + if (!options.root) { + throw new Error('Missing package installation root path'); + } + const {realpath} = this.core.make('osjs/vfs'); const name = path.basename(url.split('?')[0]) .replace(/\.[^/.]+$/, ''); - const userRoot = options.root || 'home:/.packages'; // FIXME: Client-side + const userRoot = options.root; const target = await realpath(`${userRoot}/${name}`, user); const root = await realpath(userRoot, user); const manifest = await realpath(`${userRoot}/metadata.json`, user); @@ -194,6 +198,10 @@ class Packages { const metadatas = await Promise.all(filenames.map(f => fs.readJson(f))); await fs.writeJson(manifest, metadatas); + + return { + reload: !options.system + }; } /** diff --git a/src/providers/packages.js b/src/providers/packages.js index 31afff3..6845bec 100644 --- a/src/providers/packages.js +++ b/src/providers/packages.js @@ -80,7 +80,7 @@ class PackageServiceProvider extends ServiceProvider { routeAuthenticated('POST', '/api/packages/install', (req, res) => { this.packages.installPackage(req.body.url, req.body.options, req.session.user) - .then(() => res.json({success: true})) + .then(body => res.json(body)) .catch((error) => { console.error(error); res.status(400).json({error: 'Package installation failed'});