support installing old plugins

This commit is contained in:
Koushik Dutta
2021-09-15 12:04:55 -07:00
parent 8ecb11d592
commit e6d9c185d5
2 changed files with 9 additions and 7 deletions

View File

@@ -381,12 +381,14 @@ export class ScryptedRuntime {
return proxyPair;
}
async installNpm(pkg: string): Promise<PluginHost> {
async installNpm(pkg: string, version?: string): Promise<PluginHost> {
const registry = (await axios(`https://registry.npmjs.org/${pkg}`)).data;
const latest = registry['dist-tags'].latest;
console.log('latest package', pkg, latest);
if (!version) {
version = registry['dist-tags'].latest;
}
console.log('installing package', pkg, version);
const tarball = (await axios(`${registry.versions[latest].dist.tarball}`, {
const tarball = (await axios(`${registry.versions[version].dist.tarball}`, {
responseType: 'arraybuffer'
})).data;
console.log('downloaded tarball', tarball?.length);

View File

@@ -158,12 +158,12 @@ else {
}
});
app.post(['/web/component/script/install/:pkg', '/web/component/script/install/@:owner/:pkg'], async (req, res) => {
const { owner, pkg } = req.params;
app.post(['/web/component/script/install/:pkg', '/web/component/script/install/@:owner/:pkg', '/web/component/script/install/@:owner/:pkg/:tag'], async (req, res) => {
const { owner, pkg, tag } = req.params;
let endpoint = pkg;
if (owner)
endpoint = `@${owner}/${endpoint}`;
const plugin = await scrypted.installNpm(endpoint);
const plugin = await scrypted.installNpm(endpoint, tag);
res.send({
id: scrypted.findPluginDevice(plugin.pluginId)._id,
});