server: secret menu to edit device id

This commit is contained in:
Koushik Dutta
2022-02-24 15:55:22 -08:00
parent 9545658db7
commit 56eb016cf3
2 changed files with 13 additions and 1 deletions

View File

@@ -493,7 +493,7 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
}
catch (e) {
}
await this.upsertDevice(plugin._id, device);
this.upsertDevice(plugin._id, device);
return this.runPlugin(plugin, pluginDebug);
}

View File

@@ -4,6 +4,7 @@ import { Plugin } from '../db-types';
import { getState } from "../state";
import axios from 'axios';
import semver from 'semver';
import { sleep } from "../sleep";
export class PluginComponent {
scrypted: ScryptedRuntime;
@@ -11,6 +12,17 @@ export class PluginComponent {
this.scrypted = scrypted;
}
async renameDeviceId(id: string, newId: string) {
const pluginDevice = this.scrypted.findPluginDeviceById(id);
await this.kill(pluginDevice.pluginId);
// wait for everything to settle.
await sleep(2000);
await this.scrypted.removeDevice(pluginDevice);
pluginDevice._id = newId;
await this.scrypted.datastore.upsert(pluginDevice);
await this.scrypted.notifyPluginDeviceDescriptorChanged(pluginDevice);
}
getNativeId(id: string) {
return this.scrypted.findPluginDeviceById(id)?.nativeId;
}