read from the host, actually

picker-v2
Brian Hicks 2022-09-09 17:17:12 -05:00
parent eccdbad453
commit f0dd249808
Signed by: brian
GPG Key ID: C4F324B9CAAB0D50
3 changed files with 9 additions and 10 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -1572,6 +1572,7 @@ declare class URL {
deletingLastPathComponent(): URL;
readonly string: string;
readonly toObject: Object | null;
readonly host: string | null;
}
// URL.Access