From 1479b7fb27acc5c69c40a0da2095b4e3ac5194e0 Mon Sep 17 00:00:00 2001 From: Marat Atayev Date: Wed, 9 Oct 2024 12:43:15 -0400 Subject: [PATCH] fixes #175 - updated regex to find a signed package on `/plugin_package` page (#176) * fixes #175 - updated regex to find a signed package on `/plugin_package` page * Add anchor tag fallback --------- Co-authored-by: Bronley Plumb --- src/RokuDeploy.spec.ts | 43 ++++++++++++++++++++++++++++++++++++++++++ src/RokuDeploy.ts | 8 +++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index f34c411..5dd4593 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1482,6 +1482,13 @@ describe('index', () => { expect(pkgPath).to.equal('pkgs//P6953175d5df120c0069c53de12515b9a.pkg'); }); + it('should return created pkg from SD card on success', async () => { + mockDoPostRequest(fakePluginPackageResponse); + + let pkgPath = await rokuDeploy.signExistingPackage(options); + expect(pkgPath).to.equal('pkgs/sdcard0/Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg'); + }); + it('should return our fallback error if neither error or package link was detected', async () => { mockDoPostRequest(); await expectThrowsAsync( @@ -3790,3 +3797,39 @@ function getFakeResponseBody(messages: string): string { `; } + +const fakePluginPackageResponse = ` + + + + + + + Roku Development Kit + + + +
+
+ +
+
+
+Pae6cec1eab06a45ca1a7f5b69edd3a20.pkg
+ + + + + + +`; diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 51dd340..73392a9 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -623,7 +623,13 @@ export class RokuDeploy { throw new errors.FailedDeviceResponseError(failedSearchMatches[1], results); } - let pkgSearchMatches = //.exec(results.body); + //grab the package url from the JSON on the page if it exists (https://regex101.com/r/1HUXgk/1) + let pkgSearchMatches = /"pkgPath"\s*:\s*"(.*?)"/.exec(results.body); + if (pkgSearchMatches) { + return pkgSearchMatches[1]; + } + //for some reason we couldn't find the pkgPath from json, look in the tag + pkgSearchMatches = //.exec(results.body); if (pkgSearchMatches) { return pkgSearchMatches[1]; }