mirror of
https://github.com/koush/scrypted.git
synced 2026-09-21 11:10:40 +01:00
support installing old plugins
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user