Skip to content

Commit

Permalink
read from the host, actually
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Sep 9, 2022
1 parent eccdbad commit f0dd249
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions Linear.omnifocusjs/Resources/pull.js
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions Linear.omnifocusjs/Resources/pull.ts
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions types/omnifocus.d.ts
Expand Up @@ -1572,6 +1572,7 @@ declare class URL {
deletingLastPathComponent(): URL;
readonly string: string;
readonly toObject: Object | null;
readonly host: string | null;
}

// URL.Access
Expand Down

0 comments on commit f0dd249

Please sign in to comment.