From 3f7b801ffb11bb9a7b802195d6c634886c2a67b6 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 20 Sep 2024 15:05:56 -0700 Subject: [PATCH] cloud: server id reporting --- plugins/cloud/.vscode/settings.json | 2 +- plugins/cloud/package-lock.json | 4 ++-- plugins/cloud/package.json | 2 +- plugins/cloud/src/main.ts | 11 ++++++----- sdk/types/scrypted_python/scrypted_sdk/types.py | 1 + sdk/types/src/types.input.ts | 1 + 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/cloud/.vscode/settings.json b/plugins/cloud/.vscode/settings.json index 964a62559..a620593fa 100644 --- a/plugins/cloud/.vscode/settings.json +++ b/plugins/cloud/.vscode/settings.json @@ -1,4 +1,4 @@ { - "scrypted.debugHost": "scrypted-server", + "scrypted.debugHost": "scrypted-nvr", } \ No newline at end of file diff --git a/plugins/cloud/package-lock.json b/plugins/cloud/package-lock.json index be2b72e6b..626fdbc22 100644 --- a/plugins/cloud/package-lock.json +++ b/plugins/cloud/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/cloud", - "version": "0.2.43", + "version": "0.2.44", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/cloud", - "version": "0.2.43", + "version": "0.2.44", "dependencies": { "@eneris/push-receiver": "^4.2.0", "@scrypted/common": "file:../../common", diff --git a/plugins/cloud/package.json b/plugins/cloud/package.json index 38e95fdec..27c0706a1 100644 --- a/plugins/cloud/package.json +++ b/plugins/cloud/package.json @@ -53,5 +53,5 @@ "@types/node": "^22.5.2", "ts-node": "^10.9.2" }, - "version": "0.2.43" + "version": "0.2.44" } diff --git a/plugins/cloud/src/main.ts b/plugins/cloud/src/main.ts index 3d660053f..de9db8156 100644 --- a/plugins/cloud/src/main.ts +++ b/plugins/cloud/src/main.ts @@ -258,6 +258,7 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings, this.converters = [ [ScryptedMimeTypes.LocalUrl, ScryptedMimeTypes.Url], [ScryptedMimeTypes.PushEndpoint, ScryptedMimeTypes.Url], + ['*/*', ScryptedMimeTypes.ServerId], ]; // legacy cleanup this.fromMimeType = undefined; @@ -723,10 +724,7 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings, } async convertMedia(data: string | Buffer | any, fromMimeType: string, toMimeType: string, options?: MediaObjectOptions): Promise { - if (!toMimeType.startsWith(ScryptedMimeTypes.Url)) - throw new Error('unsupported cloud url conversion'); - - if (fromMimeType.startsWith(ScryptedMimeTypes.LocalUrl)) { + if (toMimeType.startsWith(ScryptedMimeTypes.Url) && fromMimeType.startsWith(ScryptedMimeTypes.LocalUrl)) { // if cloudflare is enabled and the plugin isn't set up as a custom domain, try to use the cloudflare url for // short lived urls. if (this.cloudflareTunnel && this.storageSettings.values.forwardingMode !== 'Custom Domain') { @@ -740,7 +738,7 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings, } return this.whitelist(data.toString(), 10 * 365 * 24 * 60 * 60 * 1000, `https://${this.getHostname()}`); } - else if (fromMimeType.startsWith(ScryptedMimeTypes.PushEndpoint)) { + else if (toMimeType.startsWith(ScryptedMimeTypes.Url) && fromMimeType.startsWith(ScryptedMimeTypes.PushEndpoint)) { const validDomain = this.getSSLHostname(); if (validDomain) return Buffer.from(`https://${validDomain}${await this.getCloudMessagePath()}/${data}`); @@ -748,6 +746,9 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings, const url = `http://127.0.0.1/push/${data}`; return this.whitelist(url, 10 * 365 * 24 * 60 * 60 * 1000, `https://${this.getHostname()}${SCRYPTED_CLOUD_MESSAGE_PATH}`); } + else if (toMimeType === ScryptedMimeTypes.ServerId) { + return this.storageSettings.values.serverId; + } throw new Error('unsupported cloud url conversion'); } diff --git a/sdk/types/scrypted_python/scrypted_sdk/types.py b/sdk/types/scrypted_python/scrypted_sdk/types.py index 7b6791361..e0d9e8ecc 100644 --- a/sdk/types/scrypted_python/scrypted_sdk/types.py +++ b/sdk/types/scrypted_python/scrypted_sdk/types.py @@ -214,6 +214,7 @@ class ScryptedMimeTypes(str, Enum): RequestMediaObject = "x-scrypted/x-scrypted-request-media-object" RequestMediaStream = "x-scrypted/x-scrypted-request-stream" SchemePrefix = "x-scrypted/x-scrypted-scheme-" + ServerId = "text/x-server-id" Url = "text/x-uri" class SecuritySystemMode(str, Enum): diff --git a/sdk/types/src/types.input.ts b/sdk/types/src/types.input.ts index 69402b1ff..175ae55c7 100644 --- a/sdk/types/src/types.input.ts +++ b/sdk/types/src/types.input.ts @@ -2478,6 +2478,7 @@ export enum ScryptedMimeTypes { Url = 'text/x-uri', InsecureLocalUrl = 'text/x-insecure-local-uri', LocalUrl = 'text/x-local-uri', + ServerId = 'text/x-server-id', PushEndpoint = 'text/x-push-endpoint',