@scrypted/server 0.7.93 → 0.7.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @scrypted/server might be problematic. Click here for more details.
- package/dist/asynciterable-utils.d.ts +2 -0
- package/dist/asynciterable-utils.js +24 -0
- package/dist/asynciterable-utils.js.map +1 -0
- package/dist/cert.d.ts +6 -0
- package/dist/cert.js +75 -0
- package/dist/cert.js.map +1 -0
- package/dist/collection.d.ts +1 -0
- package/dist/collection.js +16 -0
- package/dist/collection.js.map +1 -0
- package/dist/db-types.d.ts +38 -0
- package/dist/db-types.js +45 -0
- package/dist/db-types.js.map +1 -0
- package/dist/event-registry.d.ts +19 -0
- package/dist/event-registry.js +92 -0
- package/dist/event-registry.js.map +1 -0
- package/dist/http-interfaces.d.ts +3 -0
- package/dist/http-interfaces.js +73 -0
- package/dist/http-interfaces.js.map +1 -0
- package/dist/infer-defaults.d.ts +11 -0
- package/dist/infer-defaults.js +119 -0
- package/dist/infer-defaults.js.map +1 -0
- package/dist/io.d.ts +22 -0
- package/dist/io.js +3 -0
- package/dist/io.js.map +1 -0
- package/dist/level.d.ts +110 -0
- package/dist/level.js +135 -0
- package/dist/level.js.map +1 -0
- package/dist/listen-zero.d.ts +13 -0
- package/dist/listen-zero.js +48 -0
- package/dist/listen-zero.js.map +1 -0
- package/dist/logger.d.ts +29 -0
- package/dist/logger.js +78 -0
- package/dist/logger.js.map +1 -0
- package/dist/media-helpers.d.ts +5 -0
- package/dist/media-helpers.js +89 -0
- package/dist/media-helpers.js.map +1 -0
- package/dist/mixin/mixin-cycle.d.ts +3 -0
- package/dist/mixin/mixin-cycle.js +32 -0
- package/dist/mixin/mixin-cycle.js.map +1 -0
- package/dist/plugin/acl.d.ts +16 -0
- package/dist/plugin/acl.js +83 -0
- package/dist/plugin/acl.js.map +1 -0
- package/dist/plugin/descriptor.d.ts +22 -0
- package/dist/plugin/descriptor.js +35 -0
- package/dist/plugin/descriptor.js.map +1 -0
- package/dist/plugin/media.d.ts +71 -0
- package/dist/plugin/media.js +420 -0
- package/dist/plugin/media.js.map +1 -0
- package/dist/plugin/mediaobject.d.ts +10 -0
- package/dist/plugin/mediaobject.js +26 -0
- package/dist/plugin/mediaobject.js.map +1 -0
- package/dist/plugin/plugin-api.d.ts +106 -0
- package/dist/plugin/plugin-api.js +120 -0
- package/dist/plugin/plugin-api.js.map +1 -0
- package/dist/plugin/plugin-console.d.ts +28 -0
- package/dist/plugin/plugin-console.js +291 -0
- package/dist/plugin/plugin-console.js.map +1 -0
- package/dist/plugin/plugin-debug.d.ts +4 -0
- package/dist/plugin/plugin-debug.js +3 -0
- package/dist/plugin/plugin-debug.js.map +1 -0
- package/dist/plugin/plugin-device.d.ts +54 -0
- package/dist/plugin/plugin-device.js +413 -0
- package/dist/plugin/plugin-device.js.map +1 -0
- package/dist/plugin/plugin-error.d.ts +2 -0
- package/dist/plugin/plugin-error.js +7 -0
- package/dist/plugin/plugin-error.js.map +1 -0
- package/dist/plugin/plugin-host-api.d.ts +43 -0
- package/dist/plugin/plugin-host-api.js +179 -0
- package/dist/plugin/plugin-host-api.js.map +1 -0
- package/dist/plugin/plugin-host.d.ts +45 -0
- package/dist/plugin/plugin-host.js +398 -0
- package/dist/plugin/plugin-host.js.map +1 -0
- package/dist/plugin/plugin-http.d.ts +18 -0
- package/dist/plugin/plugin-http.js +120 -0
- package/dist/plugin/plugin-http.js.map +1 -0
- package/dist/plugin/plugin-lazy-remote.d.ts +31 -0
- package/dist/plugin/plugin-lazy-remote.js +75 -0
- package/dist/plugin/plugin-lazy-remote.js.map +1 -0
- package/dist/plugin/plugin-npm-dependencies.d.ts +8 -0
- package/dist/plugin/plugin-npm-dependencies.js +103 -0
- package/dist/plugin/plugin-npm-dependencies.js.map +1 -0
- package/dist/plugin/plugin-remote-stats.d.ts +8 -0
- package/dist/plugin/plugin-remote-stats.js +30 -0
- package/dist/plugin/plugin-remote-stats.js.map +1 -0
- package/dist/plugin/plugin-remote-websocket.d.ts +29 -0
- package/dist/plugin/plugin-remote-websocket.js +152 -0
- package/dist/plugin/plugin-remote-websocket.js.map +1 -0
- package/dist/plugin/plugin-remote-worker.d.ts +5 -0
- package/dist/plugin/plugin-remote-worker.js +348 -0
- package/dist/plugin/plugin-remote-worker.js.map +1 -0
- package/dist/plugin/plugin-remote.d.ts +75 -0
- package/dist/plugin/plugin-remote.js +598 -0
- package/dist/plugin/plugin-remote.js.map +1 -0
- package/dist/plugin/plugin-repl.d.ts +2 -0
- package/dist/plugin/plugin-repl.js +74 -0
- package/dist/plugin/plugin-repl.js.map +1 -0
- package/dist/plugin/plugin-state-check.d.ts +1 -0
- package/dist/plugin/plugin-state-check.js +27 -0
- package/dist/plugin/plugin-state-check.js.map +1 -0
- package/dist/plugin/plugin-volume.d.ts +3 -0
- package/dist/plugin/plugin-volume.js +31 -0
- package/dist/plugin/plugin-volume.js.map +1 -0
- package/dist/plugin/runtime/child-process-worker.d.ts +20 -0
- package/dist/plugin/runtime/child-process-worker.js +42 -0
- package/dist/plugin/runtime/child-process-worker.js.map +1 -0
- package/dist/plugin/runtime/node-fork-worker.d.ts +9 -0
- package/dist/plugin/runtime/node-fork-worker.js +67 -0
- package/dist/plugin/runtime/node-fork-worker.js.map +1 -0
- package/dist/plugin/runtime/node-thread-worker.d.ts +20 -0
- package/dist/plugin/runtime/node-thread-worker.js +73 -0
- package/dist/plugin/runtime/node-thread-worker.js.map +1 -0
- package/dist/plugin/runtime/python-worker.d.ts +10 -0
- package/dist/plugin/runtime/python-worker.js +91 -0
- package/dist/plugin/runtime/python-worker.js.map +1 -0
- package/dist/plugin/runtime/runtime-worker.d.ts +26 -0
- package/dist/plugin/runtime/runtime-worker.js +3 -0
- package/dist/plugin/runtime/runtime-worker.js.map +1 -0
- package/dist/plugin/socket-serializer.d.ts +5 -0
- package/dist/plugin/socket-serializer.js +17 -0
- package/dist/plugin/socket-serializer.js.map +1 -0
- package/dist/plugin/system.d.ts +39 -0
- package/dist/plugin/system.js +216 -0
- package/dist/plugin/system.js.map +1 -0
- package/dist/rpc-buffer-serializer.d.ts +11 -0
- package/dist/rpc-buffer-serializer.js +30 -0
- package/dist/rpc-buffer-serializer.js.map +1 -0
- package/dist/rpc-serializer.d.ts +24 -0
- package/dist/rpc-serializer.js +144 -0
- package/dist/rpc-serializer.js.map +1 -0
- package/dist/rpc.d.ts +147 -0
- package/dist/rpc.js +689 -0
- package/dist/rpc.js.map +1 -0
- package/dist/runtime.d.ts +103 -0
- package/dist/runtime.js +815 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scrypted-main-exports.d.ts +6 -0
- package/dist/scrypted-main-exports.js +57 -0
- package/dist/scrypted-main-exports.js.map +1 -0
- package/dist/scrypted-main.d.ts +1 -0
- package/dist/scrypted-main.js +8 -0
- package/dist/scrypted-main.js.map +1 -0
- package/dist/scrypted-plugin-main.d.ts +2 -0
- package/dist/scrypted-plugin-main.js +43 -0
- package/dist/scrypted-plugin-main.js.map +1 -0
- package/dist/scrypted-server-main.d.ts +6 -0
- package/dist/scrypted-server-main.js +559 -0
- package/dist/scrypted-server-main.js.map +1 -0
- package/dist/server-settings.d.ts +5 -0
- package/dist/server-settings.js +91 -0
- package/dist/server-settings.js.map +1 -0
- package/dist/services/addresses.d.ts +7 -0
- package/dist/services/addresses.js +43 -0
- package/dist/services/addresses.js.map +1 -0
- package/dist/services/alerts.d.ts +9 -0
- package/dist/services/alerts.js +27 -0
- package/dist/services/alerts.js.map +1 -0
- package/dist/services/cors.d.ts +18 -0
- package/dist/services/cors.js +18 -0
- package/dist/services/cors.js.map +1 -0
- package/dist/services/info.d.ts +5 -0
- package/dist/services/info.js +18 -0
- package/dist/services/info.js.map +1 -0
- package/dist/services/plugin.d.ts +46 -0
- package/dist/services/plugin.js +172 -0
- package/dist/services/plugin.js.map +1 -0
- package/dist/services/service-control.d.ts +8 -0
- package/dist/services/service-control.js +39 -0
- package/dist/services/service-control.js.map +1 -0
- package/dist/services/users.d.ts +19 -0
- package/dist/services/users.js +75 -0
- package/dist/services/users.js.map +1 -0
- package/dist/sleep.d.ts +1 -0
- package/dist/sleep.js +8 -0
- package/dist/sleep.js.map +1 -0
- package/dist/state.d.ts +39 -0
- package/dist/state.js +247 -0
- package/dist/state.js.map +1 -0
- package/dist/threading.d.ts +3 -0
- package/dist/threading.js +93 -0
- package/dist/threading.js.map +1 -0
- package/dist/usertoken.d.ts +11 -0
- package/dist/usertoken.js +52 -0
- package/dist/usertoken.js.map +1 -0
- package/package.json +2 -2
- package/src/plugin/plugin-host-api.ts +3 -1
@@ -0,0 +1,91 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.getHostAddresses = exports.getIpAddress = exports.SCRYPTED_DEBUG_PORT = exports.SCRYPTED_SECURE_PORT = exports.SCRYPTED_INSECURE_PORT = void 0;
|
30
|
+
const os_1 = __importDefault(require("os"));
|
31
|
+
const nodeIp = __importStar(require("ip"));
|
32
|
+
exports.SCRYPTED_INSECURE_PORT = parseInt(process.env.SCRYPTED_INSECURE_PORT) || 11080;
|
33
|
+
exports.SCRYPTED_SECURE_PORT = parseInt(process.env.SCRYPTED_SECURE_PORT) || 10443;
|
34
|
+
exports.SCRYPTED_DEBUG_PORT = parseInt(process.env.SCRYPTED_DEBUG_PORT) || 10081;
|
35
|
+
function getIpAddress() {
|
36
|
+
return nodeIp.address();
|
37
|
+
}
|
38
|
+
exports.getIpAddress = getIpAddress;
|
39
|
+
function normalizeFamilyNodeV18(family) {
|
40
|
+
if (family === 'IPv4')
|
41
|
+
return 4;
|
42
|
+
if (family === 'IPv6')
|
43
|
+
return 6;
|
44
|
+
return family;
|
45
|
+
}
|
46
|
+
function nodeIpAddress(family) {
|
47
|
+
// https://chromium.googlesource.com/external/webrtc/+/master/rtc_base/network.cc#236
|
48
|
+
const costlyNetworks = ["ipsec", "tun", "utun", "tap"];
|
49
|
+
const ignoreNetworks = [
|
50
|
+
// seen these on macos
|
51
|
+
'llw',
|
52
|
+
'awdl',
|
53
|
+
...costlyNetworks,
|
54
|
+
];
|
55
|
+
const interfaces = os_1.default.networkInterfaces();
|
56
|
+
const all = Object.keys(interfaces)
|
57
|
+
.map((nic) => {
|
58
|
+
for (const costly of ignoreNetworks) {
|
59
|
+
if (nic.startsWith(costly)) {
|
60
|
+
return {
|
61
|
+
nic,
|
62
|
+
addresses: [],
|
63
|
+
};
|
64
|
+
}
|
65
|
+
}
|
66
|
+
const addresses = interfaces[nic].filter((details) => normalizeFamilyNodeV18(details.family) === family
|
67
|
+
&& !nodeIp.isLoopback(details.address));
|
68
|
+
return {
|
69
|
+
nic,
|
70
|
+
addresses: addresses.map((address) => address.address),
|
71
|
+
};
|
72
|
+
})
|
73
|
+
.filter((address) => !!address);
|
74
|
+
// os.networkInterfaces doesn't actually return addresses in a good order.
|
75
|
+
// have seen instances where en0 (ethernet) is after en1 (wlan), etc.
|
76
|
+
// eth0 > eth1
|
77
|
+
all.sort((a, b) => a.nic.localeCompare(b.nic));
|
78
|
+
return Object.values(all)
|
79
|
+
.map((entry) => entry.addresses)
|
80
|
+
.flat();
|
81
|
+
}
|
82
|
+
function getHostAddresses(useIpv4, useIpv6) {
|
83
|
+
const address = [];
|
84
|
+
if (useIpv4)
|
85
|
+
address.push(...nodeIpAddress(4));
|
86
|
+
if (useIpv6)
|
87
|
+
address.push(...nodeIpAddress(6));
|
88
|
+
return address;
|
89
|
+
}
|
90
|
+
exports.getHostAddresses = getHostAddresses;
|
91
|
+
//# sourceMappingURL=server-settings.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"server-settings.js","sourceRoot":"","sources":["../src/server-settings.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,2CAA6B;AAEhB,QAAA,sBAAsB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,KAAK,CAAC;AAC/E,QAAA,oBAAoB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC;AAC3E,QAAA,mBAAmB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,KAAK,CAAC;AAEtF,SAAgB,YAAY;IACxB,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;AAC5B,CAAC;AAFD,oCAEC;AAED,SAAS,sBAAsB,CAAC,MAAqB;IACjD,IAAI,MAAM,KAAK,MAAM;QACjB,OAAO,CAAC,CAAC;IACb,IAAI,MAAM,KAAK,MAAM;QACjB,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AC/C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;SACpB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;SAC/B,IAAI,EAAE,CAAC;AAChB,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAAgB,EAAE,OAAgB;IAC/D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,OAAO;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,OAAO;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,OAAO,CAAC;AACnB,CAAC;AALD,4CAKC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ScryptedRuntime } from "../runtime";
|
2
|
+
export declare class AddressSettings {
|
3
|
+
scrypted: ScryptedRuntime;
|
4
|
+
constructor(scrypted: ScryptedRuntime);
|
5
|
+
setLocalAddresses(addresses: string[]): Promise<void>;
|
6
|
+
getLocalAddresses(raw?: boolean): Promise<string[]>;
|
7
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.AddressSettings = void 0;
|
7
|
+
const db_types_1 = require("../db-types");
|
8
|
+
const os_1 = __importDefault(require("os"));
|
9
|
+
class AddressSettings {
|
10
|
+
scrypted;
|
11
|
+
constructor(scrypted) {
|
12
|
+
this.scrypted = scrypted;
|
13
|
+
}
|
14
|
+
async setLocalAddresses(addresses) {
|
15
|
+
const localAddresses = new db_types_1.Settings();
|
16
|
+
localAddresses._id = 'localAddresses';
|
17
|
+
localAddresses.value = addresses;
|
18
|
+
await this.scrypted.datastore.upsert(localAddresses);
|
19
|
+
}
|
20
|
+
async getLocalAddresses(raw) {
|
21
|
+
const settings = await this.scrypted.datastore.tryGet(db_types_1.Settings, 'localAddresses');
|
22
|
+
if (!settings?.value?.[0])
|
23
|
+
return;
|
24
|
+
const ret = [];
|
25
|
+
const networkInterfaces = os_1.default.networkInterfaces();
|
26
|
+
for (const addressOrInterface of settings.value) {
|
27
|
+
const nif = networkInterfaces[addressOrInterface];
|
28
|
+
if (!raw && nif) {
|
29
|
+
for (const addr of nif) {
|
30
|
+
if (!addr.address || addr.address.startsWith('169.254.') || addr.address.toLowerCase().startsWith('fe80:'))
|
31
|
+
continue;
|
32
|
+
ret.push(addr.address);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
ret.push(addressOrInterface);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return ret;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
exports.AddressSettings = AddressSettings;
|
43
|
+
//# sourceMappingURL=addresses.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../src/services/addresses.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAuC;AAEvC,4CAAoB;AAEpB,MAAa,eAAe;IACL;IAAnB,YAAmB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAC5C,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,SAAmB;QACvC,MAAM,cAAc,GAAG,IAAI,mBAAQ,EAAE,CAAC;QACtC,cAAc,CAAC,GAAG,GAAG,gBAAgB,CAAC;QACtC,cAAc,CAAC,KAAK,GAAG,SAAS,CAAC;QACjC,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,GAAa;QACjC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,mBAAQ,EAAE,gBAAgB,CAAC,CAAC;QAElF,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACrB,OAAO;QAEX,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,MAAM,iBAAiB,GAAG,YAAE,CAAC,iBAAiB,EAAE,CAAC;QACjD,KAAK,MAAM,kBAAkB,IAAI,QAAQ,CAAC,KAAK,EAAE;YAC7C,MAAM,GAAG,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;YAClD,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE;gBACb,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE;oBACpB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;wBACtG,SAAS;oBACb,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBAC1B;aACJ;iBACI;gBACD,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAChC;SACJ;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAlCD,0CAkCC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ScryptedAlert } from "../db-types";
|
2
|
+
import { ScryptedRuntime } from "../runtime";
|
3
|
+
export declare class Alerts {
|
4
|
+
scrypted: ScryptedRuntime;
|
5
|
+
constructor(scrypted: ScryptedRuntime);
|
6
|
+
getAlerts(): Promise<ScryptedAlert[]>;
|
7
|
+
removeAlert(alert: ScryptedAlert): Promise<void>;
|
8
|
+
clearAlerts(): Promise<void>;
|
9
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Alerts = void 0;
|
4
|
+
const db_types_1 = require("../db-types");
|
5
|
+
class Alerts {
|
6
|
+
scrypted;
|
7
|
+
constructor(scrypted) {
|
8
|
+
this.scrypted = scrypted;
|
9
|
+
}
|
10
|
+
async getAlerts() {
|
11
|
+
const ret = [];
|
12
|
+
for await (const alert of this.scrypted.datastore.getAll(db_types_1.ScryptedAlert)) {
|
13
|
+
ret.push(alert);
|
14
|
+
}
|
15
|
+
return ret;
|
16
|
+
}
|
17
|
+
async removeAlert(alert) {
|
18
|
+
await this.scrypted.datastore.removeId(db_types_1.ScryptedAlert, alert._id);
|
19
|
+
this.scrypted.stateManager.notifyInterfaceEvent(null, 'Logger', undefined);
|
20
|
+
}
|
21
|
+
async clearAlerts() {
|
22
|
+
await this.scrypted.datastore.removeAll(db_types_1.ScryptedAlert);
|
23
|
+
this.scrypted.stateManager.notifyInterfaceEvent(null, 'Logger', undefined);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.Alerts = Alerts;
|
27
|
+
//# sourceMappingURL=alerts.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"alerts.js","sourceRoot":"","sources":["../../src/services/alerts.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAG5C,MAAa,MAAM;IACI;IAAnB,YAAmB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAC5C,CAAC;IAED,KAAK,CAAC,SAAS;QACX,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAa,CAAC,EAAE;YACrE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACnB;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IACD,KAAK,CAAC,WAAW,CAAC,KAAoB;QAClC,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,wBAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAe,EAAE,SAAS,CAAC,CAAC;IACtF,CAAC;IACD,KAAK,CAAC,WAAW;QACb,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,wBAAa,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAe,EAAE,SAAS,CAAC,CAAC;IACtF,CAAC;CACJ;AAnBD,wBAmBC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ScryptedRuntime } from "../runtime";
|
2
|
+
export declare class CORSControl {
|
3
|
+
runtime: ScryptedRuntime;
|
4
|
+
origins: {
|
5
|
+
[id: string]: string[];
|
6
|
+
};
|
7
|
+
constructor(runtime: ScryptedRuntime);
|
8
|
+
getCORS(id: string): Promise<string[]>;
|
9
|
+
setCORS(id: string, origins: string[]): Promise<void>;
|
10
|
+
}
|
11
|
+
export interface CORSServerLegacy {
|
12
|
+
tag: string;
|
13
|
+
server: string;
|
14
|
+
}
|
15
|
+
export interface CORSControlLegacy {
|
16
|
+
getCORS(): Promise<CORSServerLegacy[]>;
|
17
|
+
setCORS(servers: CORSServerLegacy[]): Promise<void>;
|
18
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.CORSControl = void 0;
|
4
|
+
class CORSControl {
|
5
|
+
runtime;
|
6
|
+
origins = {};
|
7
|
+
constructor(runtime) {
|
8
|
+
this.runtime = runtime;
|
9
|
+
}
|
10
|
+
async getCORS(id) {
|
11
|
+
return this.origins[id] || [];
|
12
|
+
}
|
13
|
+
async setCORS(id, origins) {
|
14
|
+
this.origins[id] = origins;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.CORSControl = CORSControl;
|
18
|
+
//# sourceMappingURL=cors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/services/cors.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IAKD;IAJnB,OAAO,GAEH,EAAE,CAAC;IAEP,YAAmB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,OAAiB;QACvC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC;IAC/B,CAAC;CACJ;AAfD,kCAeC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Info = void 0;
|
4
|
+
class Info {
|
5
|
+
async getVersion() {
|
6
|
+
return require('../../package.json').version;
|
7
|
+
}
|
8
|
+
async getScryptedEnv() {
|
9
|
+
const ret = {};
|
10
|
+
for (const key of Object.keys(process.env)) {
|
11
|
+
if (key.startsWith('SCRYPTED_'))
|
12
|
+
ret[key] = process.env[key];
|
13
|
+
}
|
14
|
+
return ret;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.Info = Info;
|
18
|
+
//# sourceMappingURL=info.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../src/services/info.ts"],"names":[],"mappings":";;;AAAA,MAAa,IAAI;IACb,KAAK,CAAC,UAAU;QACZ,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,cAAc;QAChB,MAAM,GAAG,GAAsB,EAAE,CAAC;QAClC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACxC,IAAI,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC;gBAC3B,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACnC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAbD,oBAaC"}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { ScryptedNativeId } from "@scrypted/types";
|
3
|
+
import { ScryptedRuntime } from "../runtime";
|
4
|
+
export declare class PluginComponent {
|
5
|
+
scrypted: ScryptedRuntime;
|
6
|
+
constructor(scrypted: ScryptedRuntime);
|
7
|
+
renameDeviceId(id: string, newId: string): Promise<void>;
|
8
|
+
getStorage(id: string): {
|
9
|
+
[key: string]: string;
|
10
|
+
};
|
11
|
+
setStorage(id: string, storage: {
|
12
|
+
[key: string]: string;
|
13
|
+
}): Promise<void>;
|
14
|
+
setMixins(id: string, mixins: string[]): Promise<void>;
|
15
|
+
getIdForPluginId(pluginId: string): Promise<string>;
|
16
|
+
getIdForNativeId(pluginId: string, nativeId: ScryptedNativeId): Promise<string>;
|
17
|
+
reload(pluginId: string): Promise<void>;
|
18
|
+
kill(pluginId: string): Promise<void>;
|
19
|
+
getPackageJson(pluginId: string): Promise<any>;
|
20
|
+
getDeviceInfo(id: string): Promise<{
|
21
|
+
mixins: any;
|
22
|
+
pluginId: string;
|
23
|
+
storage: {
|
24
|
+
[key: string]: string;
|
25
|
+
};
|
26
|
+
nativeId: string;
|
27
|
+
}>;
|
28
|
+
getPluginInfo(pluginId: string): Promise<{
|
29
|
+
pid: number;
|
30
|
+
stats: {
|
31
|
+
cpuUsage: NodeJS.CpuUsage;
|
32
|
+
memoryUsage: NodeJS.MemoryUsage;
|
33
|
+
};
|
34
|
+
rpcObjects: number;
|
35
|
+
packageJson: any;
|
36
|
+
pendingResults: number;
|
37
|
+
id: string;
|
38
|
+
}>;
|
39
|
+
installNpm(pkg: string, version?: string): Promise<void>;
|
40
|
+
npmInfo(endpoint: string): Promise<any>;
|
41
|
+
updatePlugins(): Promise<void>;
|
42
|
+
clearConsole(id: string): Promise<void>;
|
43
|
+
getRemoteServicePort(pluginId: string, name: string, ...args: any[]): Promise<number>;
|
44
|
+
setHostParam(pluginId: string, name: string, param?: any): Promise<void>;
|
45
|
+
getHostParam(pluginId: string, name: string): Promise<any>;
|
46
|
+
}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.PluginComponent = void 0;
|
7
|
+
const types_1 = require("@scrypted/types");
|
8
|
+
const db_types_1 = require("../db-types");
|
9
|
+
const state_1 = require("../state");
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
11
|
+
const semver_1 = __importDefault(require("semver"));
|
12
|
+
const sleep_1 = require("../sleep");
|
13
|
+
const mixin_cycle_1 = require("../mixin/mixin-cycle");
|
14
|
+
class PluginComponent {
|
15
|
+
scrypted;
|
16
|
+
constructor(scrypted) {
|
17
|
+
this.scrypted = scrypted;
|
18
|
+
}
|
19
|
+
async renameDeviceId(id, newId) {
|
20
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
21
|
+
await this.kill(pluginDevice.pluginId);
|
22
|
+
// wait for everything to settle.
|
23
|
+
await (0, sleep_1.sleep)(2000);
|
24
|
+
// removing will also clear the state.
|
25
|
+
const { state } = pluginDevice;
|
26
|
+
await this.scrypted.removeDevice(pluginDevice);
|
27
|
+
pluginDevice._id = newId;
|
28
|
+
pluginDevice.state = state;
|
29
|
+
await this.scrypted.datastore.upsert(pluginDevice);
|
30
|
+
this.scrypted.pluginDevices[pluginDevice._id] = pluginDevice;
|
31
|
+
await this.scrypted.notifyPluginDeviceDescriptorChanged(pluginDevice);
|
32
|
+
await this.reload(pluginDevice.pluginId);
|
33
|
+
}
|
34
|
+
getStorage(id) {
|
35
|
+
return this.scrypted.findPluginDeviceById(id)?.storage || {};
|
36
|
+
}
|
37
|
+
async setStorage(id, storage) {
|
38
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
39
|
+
pluginDevice.storage = storage;
|
40
|
+
await this.scrypted.datastore.upsert(pluginDevice);
|
41
|
+
const host = this.scrypted.getPluginHostForDeviceId(id);
|
42
|
+
await host?.remote?.setNativeId?.(pluginDevice.nativeId, pluginDevice._id, storage);
|
43
|
+
this.scrypted.stateManager.notifyInterfaceEvent(pluginDevice, 'Storage', undefined);
|
44
|
+
}
|
45
|
+
async setMixins(id, mixins) {
|
46
|
+
mixins = mixins || [];
|
47
|
+
if ((0, mixin_cycle_1.hasMixinCycle)(this.scrypted, id, mixins)) {
|
48
|
+
const message = `setMixins: ${id} has a mixin cycle. Cancelling change.`;
|
49
|
+
console.warn(message);
|
50
|
+
throw new Error(message);
|
51
|
+
}
|
52
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
53
|
+
this.scrypted.stateManager.setPluginDeviceState(pluginDevice, types_1.ScryptedInterfaceProperty.mixins, [...new Set(mixins)]);
|
54
|
+
this.scrypted.stateManager.updateDescriptor(pluginDevice);
|
55
|
+
await this.scrypted.datastore.upsert(pluginDevice);
|
56
|
+
// device may not exist, so force creation.
|
57
|
+
this.scrypted.rebuildPluginDeviceMixinTable(id);
|
58
|
+
this.scrypted.getDevice(id);
|
59
|
+
await this.scrypted.devices[id]?.handler?.ensureProxy();
|
60
|
+
}
|
61
|
+
async getIdForPluginId(pluginId) {
|
62
|
+
return this.scrypted.findPluginDevice(pluginId)?._id;
|
63
|
+
}
|
64
|
+
async getIdForNativeId(pluginId, nativeId) {
|
65
|
+
return this.scrypted.findPluginDevice(pluginId, nativeId)?._id;
|
66
|
+
}
|
67
|
+
async reload(pluginId) {
|
68
|
+
const plugin = await this.scrypted.datastore.tryGet(db_types_1.Plugin, pluginId);
|
69
|
+
this.scrypted.runPlugin(plugin);
|
70
|
+
}
|
71
|
+
async kill(pluginId) {
|
72
|
+
return this.scrypted.plugins[pluginId]?.kill();
|
73
|
+
}
|
74
|
+
// TODO: Remove this, ScryptedPlugin exists now.
|
75
|
+
// 12/29/2022
|
76
|
+
async getPackageJson(pluginId) {
|
77
|
+
return this.scrypted.getPackageJson(pluginId);
|
78
|
+
}
|
79
|
+
async getDeviceInfo(id) {
|
80
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
81
|
+
if (!pluginDevice)
|
82
|
+
throw new Error(`device ${id} does not exist`);
|
83
|
+
return {
|
84
|
+
mixins: (0, state_1.getState)(pluginDevice, types_1.ScryptedInterfaceProperty.mixins) || [],
|
85
|
+
pluginId: pluginDevice.pluginId,
|
86
|
+
storage: pluginDevice.storage,
|
87
|
+
nativeId: pluginDevice.nativeId,
|
88
|
+
};
|
89
|
+
}
|
90
|
+
async getPluginInfo(pluginId) {
|
91
|
+
const packageJson = await this.getPackageJson(pluginId);
|
92
|
+
const host = this.scrypted.plugins[pluginId];
|
93
|
+
let rpcObjects = 0;
|
94
|
+
let pendingResults = 0;
|
95
|
+
if (host.peer) {
|
96
|
+
rpcObjects = host.peer.localProxied.size + Object.keys(host.peer.remoteWeakProxies).length;
|
97
|
+
pendingResults = Object.keys(host.peer.pendingResults).length;
|
98
|
+
}
|
99
|
+
return {
|
100
|
+
pid: host?.worker?.pid,
|
101
|
+
stats: host?.stats,
|
102
|
+
rpcObjects,
|
103
|
+
packageJson,
|
104
|
+
pendingResults,
|
105
|
+
id: this.scrypted.findPluginDevice(pluginId)._id,
|
106
|
+
};
|
107
|
+
}
|
108
|
+
async installNpm(pkg, version) {
|
109
|
+
await this.scrypted.installNpm(pkg, version);
|
110
|
+
}
|
111
|
+
async npmInfo(endpoint) {
|
112
|
+
const response = await (0, axios_1.default)(`https://registry.npmjs.org/${endpoint}`);
|
113
|
+
return response.data;
|
114
|
+
}
|
115
|
+
async updatePlugins() {
|
116
|
+
console.log('updating plugins');
|
117
|
+
for (const [plugin, host] of Object.entries(this.scrypted.plugins)) {
|
118
|
+
try {
|
119
|
+
const registry = await this.npmInfo(plugin);
|
120
|
+
const version = registry['dist-tags'].latest;
|
121
|
+
if (registry?.versions?.[version]?.deprecated) {
|
122
|
+
console.log('plugin deprecated, uninstalling:', plugin);
|
123
|
+
await this.scrypted.removeDevice(this.scrypted.findPluginDevice(plugin));
|
124
|
+
continue;
|
125
|
+
}
|
126
|
+
if (!semver_1.default.gt(version, host.packageJson.version)) {
|
127
|
+
console.log('plugin up to date:', plugin);
|
128
|
+
continue;
|
129
|
+
}
|
130
|
+
console.log('updating plugin', plugin);
|
131
|
+
await this.installNpm(plugin);
|
132
|
+
}
|
133
|
+
catch (e) {
|
134
|
+
console.warn('plugin update check or installation failed', e);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
console.log('done updating plugins');
|
138
|
+
}
|
139
|
+
async clearConsole(id) {
|
140
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id);
|
141
|
+
const consoleServer = await this.scrypted.plugins[pluginDevice.pluginId].consoleServer;
|
142
|
+
consoleServer.clear(pluginDevice.nativeId);
|
143
|
+
}
|
144
|
+
async getRemoteServicePort(pluginId, name, ...args) {
|
145
|
+
if (name === 'console') {
|
146
|
+
const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
|
147
|
+
return consoleServer.readPort;
|
148
|
+
}
|
149
|
+
if (name === 'console-writer') {
|
150
|
+
const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
|
151
|
+
return consoleServer.writePort;
|
152
|
+
}
|
153
|
+
return this.scrypted.plugins[pluginId].remote.getServicePort(name, ...args);
|
154
|
+
}
|
155
|
+
async setHostParam(pluginId, name, param) {
|
156
|
+
const host = this.scrypted.plugins[pluginId];
|
157
|
+
if (!host)
|
158
|
+
return;
|
159
|
+
const key = `oob-param-${name}`;
|
160
|
+
if (param === undefined)
|
161
|
+
delete host.peer.params[key];
|
162
|
+
else
|
163
|
+
host.peer.params[key] = param;
|
164
|
+
}
|
165
|
+
async getHostParam(pluginId, name) {
|
166
|
+
const host = this.scrypted.plugins[pluginId];
|
167
|
+
const key = `oob-param-${name}`;
|
168
|
+
return host?.peer?.params?.[key];
|
169
|
+
}
|
170
|
+
}
|
171
|
+
exports.PluginComponent = PluginComponent;
|
172
|
+
//# sourceMappingURL=plugin.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/services/plugin.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA8E;AAE9E,0CAAqC;AACrC,oCAAoC;AACpC,kDAA0B;AAC1B,oDAA4B;AAC5B,oCAAiC;AACjC,sDAAqD;AAErD,MAAa,eAAe;IACxB,QAAQ,CAAkB;IAC1B,YAAY,QAAyB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EAAU,EAAE,KAAa;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;QAC5D,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACvC,iCAAiC;QACjC,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAClB,sCAAsC;QACtC,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC;QAC/B,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC/C,YAAY,CAAC,GAAG,GAAG,KAAK,CAAC;QACzB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC7D,MAAM,IAAI,CAAC,QAAQ,CAAC,mCAAmC,CAAC,YAAY,CAAC,CAAC;QACtE,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ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AI;YACL,OAAO;QAEX,MAAM,GAAG,GAAG,aAAa,IAAI,EAAE,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS;YACnB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;YAE7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,IAAY;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,aAAa,IAAI,EAAE,CAAC;QAChC,OAAO,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;CACJ;AAzKD,0CAyKC"}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.ServiceControl = void 0;
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
9
|
+
class ServiceControl {
|
10
|
+
scrypted;
|
11
|
+
constructor(scrypted) {
|
12
|
+
this.scrypted = scrypted;
|
13
|
+
}
|
14
|
+
async exit() {
|
15
|
+
fs_1.default.writeFileSync('.exit', '');
|
16
|
+
this.restart();
|
17
|
+
}
|
18
|
+
async restart() {
|
19
|
+
process.exit();
|
20
|
+
}
|
21
|
+
async update() {
|
22
|
+
const webhookUpdate = process.env.SCRYPTED_WEBHOOK_UPDATE;
|
23
|
+
if (webhookUpdate) {
|
24
|
+
const webhookUpdateAuthorization = process.env.SCRYPTED_WEBHOOK_UPDATE_AUTHORIZATION;
|
25
|
+
const response = await axios_1.default.get(webhookUpdate, {
|
26
|
+
headers: {
|
27
|
+
Authorization: webhookUpdateAuthorization,
|
28
|
+
}
|
29
|
+
});
|
30
|
+
return response.data;
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
fs_1.default.writeFileSync('.update', '');
|
34
|
+
this.restart();
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.ServiceControl = ServiceControl;
|
39
|
+
//# sourceMappingURL=service-control.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"service-control.js","sourceRoot":"","sources":["../../src/services/service-control.ts"],"names":[],"mappings":";;;;;;AACA,4CAAoB;AACpB,kDAA0B;AAE1B,MAAa,cAAc;IACJ;IAAnB,YAAmB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;IAC5C,CAAC;IAED,KAAK,CAAC,IAAI;QACN,YAAE,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,OAAO;QACT,OAAO,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;QAC1D,IAAI,aAAa,EAAE;YACf,MAAM,0BAA0B,GAAG,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC;YACrF,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,aAAa,EAAE;gBAC5C,OAAO,EAAE;oBACL,aAAa,EAAE,0BAA0B;iBAC5C;aACJ,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC;SACxB;aACI;YACD,YAAE,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE,CAAC;SAClB;IACL,CAAC;CACJ;AA7BD,wCA6BC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { ScryptedUser } from "../db-types";
|
2
|
+
import { ScryptedRuntime } from "../runtime";
|
3
|
+
export declare class UsersService {
|
4
|
+
scrypted: ScryptedRuntime;
|
5
|
+
users: Map<string, ScryptedUser>;
|
6
|
+
usersPromise: Promise<ScryptedUser[]>;
|
7
|
+
constructor(scrypted: ScryptedRuntime);
|
8
|
+
private ensureUsersPromise;
|
9
|
+
private updateUsersPromise;
|
10
|
+
getAllUsers(): Promise<{
|
11
|
+
username: string;
|
12
|
+
admin: boolean;
|
13
|
+
}[]>;
|
14
|
+
removeUser(username: string): Promise<void>;
|
15
|
+
removeAllUsers(): Promise<void>;
|
16
|
+
addUserInternal(username: string, password: string, aclId: string): Promise<ScryptedUser>;
|
17
|
+
addUser(username: string, password: string, aclId: string): Promise<void>;
|
18
|
+
}
|
19
|
+
export declare function setScryptedUserPassword(user: ScryptedUser, password: string, timestamp: number): void;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.setScryptedUserPassword = exports.UsersService = void 0;
|
7
|
+
const db_types_1 = require("../db-types");
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
9
|
+
class UsersService {
|
10
|
+
scrypted;
|
11
|
+
users = new Map();
|
12
|
+
usersPromise;
|
13
|
+
constructor(scrypted) {
|
14
|
+
this.scrypted = scrypted;
|
15
|
+
}
|
16
|
+
async ensureUsersPromise() {
|
17
|
+
if (!this.usersPromise) {
|
18
|
+
this.usersPromise = (async () => {
|
19
|
+
const users = new Map();
|
20
|
+
for await (const user of this.scrypted.datastore.getAll(db_types_1.ScryptedUser)) {
|
21
|
+
users.set(user._id, user);
|
22
|
+
}
|
23
|
+
this.users = users;
|
24
|
+
return [...this.users.values()];
|
25
|
+
})();
|
26
|
+
}
|
27
|
+
return this.usersPromise;
|
28
|
+
}
|
29
|
+
updateUsersPromise() {
|
30
|
+
this.usersPromise = Promise.resolve([...this.users.values()]);
|
31
|
+
}
|
32
|
+
async getAllUsers() {
|
33
|
+
const users = await this.ensureUsersPromise();
|
34
|
+
return users.map(user => ({
|
35
|
+
username: user._id,
|
36
|
+
admin: !user.aclId,
|
37
|
+
}));
|
38
|
+
}
|
39
|
+
async removeUser(username) {
|
40
|
+
await this.ensureUsersPromise();
|
41
|
+
await this.scrypted.datastore.removeId(db_types_1.ScryptedUser, username);
|
42
|
+
this.users.delete(username);
|
43
|
+
this.updateUsersPromise();
|
44
|
+
}
|
45
|
+
async removeAllUsers() {
|
46
|
+
await this.ensureUsersPromise();
|
47
|
+
await this.scrypted.datastore.removeAll(db_types_1.ScryptedUser);
|
48
|
+
this.users.clear();
|
49
|
+
this.updateUsersPromise();
|
50
|
+
}
|
51
|
+
async addUserInternal(username, password, aclId) {
|
52
|
+
await this.ensureUsersPromise();
|
53
|
+
const user = new db_types_1.ScryptedUser();
|
54
|
+
user._id = username;
|
55
|
+
user.aclId = aclId;
|
56
|
+
user.token = crypto_1.default.randomBytes(16).toString('hex');
|
57
|
+
setScryptedUserPassword(user, password, Date.now());
|
58
|
+
await this.scrypted.datastore.upsert(user);
|
59
|
+
this.users.set(username, user);
|
60
|
+
this.updateUsersPromise();
|
61
|
+
return user;
|
62
|
+
}
|
63
|
+
async addUser(username, password, aclId) {
|
64
|
+
await this.addUserInternal(username, password, aclId);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
exports.UsersService = UsersService;
|
68
|
+
function setScryptedUserPassword(user, password, timestamp) {
|
69
|
+
user.salt = crypto_1.default.randomBytes(64).toString('base64');
|
70
|
+
user.passwordHash = crypto_1.default.createHash('sha256').update(user.salt + password).digest().toString('hex');
|
71
|
+
user.passwordDate = timestamp;
|
72
|
+
user.token = crypto_1.default.randomBytes(16).toString('hex');
|
73
|
+
}
|
74
|
+
exports.setScryptedUserPassword = setScryptedUserPassword;
|
75
|
+
//# sourceMappingURL=users.js.map
|