Skip to content

Commit

Permalink
Depend on client-side package installation root (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 11, 2020
1 parent 7d1d170 commit b01d9df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
};
}

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

0 comments on commit b01d9df

Please sign in to comment.