From 1f26ba8d8986a5c87aa06aaf641bd874567133a4 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 1 May 2025 15:59:01 -0700 Subject: [PATCH] this is going well --- JS/BlueskyAPI.js | 10 +++++++--- JS/setting.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index fff1150..b00a3c5 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -2,9 +2,13 @@ import * as Cookie from "./Cookies.js"; export async function GetBlueskyDID(PDS, Handle) { let DPoP = await ClientDPoPPDS("GET", PDS + "/xrpc/com.atproto.identity.resolveDid"); - let request = fetch(PDS + "/xrpc/com.atproto.identity.resolveDid?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}) - .then((response) => response.json()); - return request; + return fetch(PDS + "/xrpc/com.atproto.identity.resolveDid?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}); +} + +// Added after all the components: in case of nonce mismatch... +export async function FixNonceMismatch(head) { + Cookie.InputCookie(Cookie.BlueskyNonceName, head); + return true; } // Component 1/4 diff --git a/JS/setting.js b/JS/setting.js index a493d36..9d42584 100644 --- a/JS/setting.js +++ b/JS/setting.js @@ -95,4 +95,15 @@ async function CheckLogin() { CheckLogin(); // TESTING! -BlueskyAPI.GetBlueskyDID(Cookie.BlueskyPDSName, "crowdedgames.group"); +async function TESTING() { + let response = BlueskyAPI.GetBlueskyDID("https://woodear.us-west.host.bsky.network", "crowdedgames.group"); + let body = await response.then((res) => res.json()); + if (response.status == 401) { + await BlueskyAPI.FixNonceMismatch(response.headers.get("dpop-nonce")); + response = BlueskyAPI.GetBlueskyDID("https://woodear.us-west.host.bsky.network", "crowdedgames.group"); + body = await response.then((res) => res.json()); + } + console.log(response); +} + +TESTING();