From f0dd2498084f7639c553adde0c10f42f702ad231 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Fri, 9 Sep 2022 17:17:12 -0500 Subject: [PATCH] read from the host, actually --- Linear.omnifocusjs/Resources/pull.js | 9 ++++----- Linear.omnifocusjs/Resources/pull.ts | 9 ++++----- types/omnifocus.d.ts | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Linear.omnifocusjs/Resources/pull.js b/Linear.omnifocusjs/Resources/pull.js index a37dd2d..4ab44fb 100644 --- a/Linear.omnifocusjs/Resources/pull.js +++ b/Linear.omnifocusjs/Resources/pull.js @@ -3,22 +3,21 @@ let creds = new Credentials(); var action = new PlugIn.Action(async () => { try { - let url = "https://api.linear.app/graphql"; - let req = URL.FetchRequest.fromString(url); - if (req === null) { + let req = URL.FetchRequest.fromString("https://api.linear.app/graphql"); + if (req === null || req.url === null || req.url.host === null) { throw "could not parse the URL for Linear's API"; } ///////////////////////////////////// // Step 1: make sure we have creds // ///////////////////////////////////// - let stored = creds.read(url); + let stored = creds.read(req.url.host); let key = null; if (stored === null || app.optionKeyDown) { let credsForm = new Form(); credsForm.addField(new Form.Field.Password("key", "API Key")); await credsForm.show("Please create a personal API key in the Linear settings and paste it here\n(hold option while activating this workflow in the future to reset this)", "Save Key"); key = credsForm.values.key; - creds.write(url, "-", key); + creds.write(req.url.host, "-", key); } else { key = stored.password; diff --git a/Linear.omnifocusjs/Resources/pull.ts b/Linear.omnifocusjs/Resources/pull.ts index 94f053e..df0bee8 100644 --- a/Linear.omnifocusjs/Resources/pull.ts +++ b/Linear.omnifocusjs/Resources/pull.ts @@ -3,16 +3,15 @@ var action = new PlugIn.Action(async () => { try { - let url = "https://api.linear.app/graphql"; - let req = URL.FetchRequest.fromString(url); - if (req === null) { + let req = URL.FetchRequest.fromString("https://api.linear.app/graphql"); + if (req === null || req.url === null || req.url.host === null) { throw "could not parse the URL for Linear's API" } ///////////////////////////////////// // Step 1: make sure we have creds // ///////////////////////////////////// - let stored = creds.read(url); + let stored = creds.read(req.url.host); let key = null; if (stored === null || app.optionKeyDown) { @@ -22,7 +21,7 @@ await credsForm.show("Please create a personal API key in the Linear settings and paste it here\n(hold option while activating this workflow in the future to reset this)", "Save Key"); key = (credsForm.values as { key: string }).key; - creds.write(url, "-", key); + creds.write(req.url.host, "-", key); } else { key = stored.password; } diff --git a/types/omnifocus.d.ts b/types/omnifocus.d.ts index e624cd0..0c2b8d8 100644 --- a/types/omnifocus.d.ts +++ b/types/omnifocus.d.ts @@ -1572,6 +1572,7 @@ declare class URL { deletingLastPathComponent(): URL; readonly string: string; readonly toObject: Object | null; + readonly host: string | null; } // URL.Access