support for self hosted PDS

This commit is contained in:
Madiator2011
2024-11-16 18:24:16 +01:00
committed by GitHub
parent be2779da79
commit d6ae71877b
5 changed files with 86 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import { AtUri, AtpAgent, type AtpSessionData } from "@atproto/api";
import { BSKY_DOMAIN } from "./constants";
// try and cut down the amount of session resumes by caching the clients
const clientCache = new Map<string, BskyClient>();
@@ -10,7 +11,7 @@ export type BskyLoginParams = {
};
export class BskyClient {
private service = "https://bsky.social";
private service = `https://${BSKY_DOMAIN}`;
me: {
did: string;
handle: string;

View File

@@ -99,3 +99,5 @@ export const DOCUMENT_LINK = {
PAGE_ERROR:
"https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors",
} as const;
export const BSKY_DOMAIN = process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social";

View File

@@ -1,3 +1,5 @@
import { BSKY_DOMAIN } from "./constants";
export const getUserCells = ({
queryParam,
filterInsertedElement,
@@ -20,13 +22,14 @@ export const getUserCells = ({
};
export const getAccountNameAndDisplayName = (userCell: Element) => {
const [avatarEl, displayNameEl] = userCell.querySelectorAll("a");
const anchors = Array.from(userCell.querySelectorAll("a"));
const [avatarEl, displayNameEl] = anchors;
const twAccountName = avatarEl?.getAttribute("href")?.replace("/", "");
const twAccountNameRemoveUnderscore = twAccountName.replaceAll("_", ""); // bsky does not allow underscores in handle, so remove them.
const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-");
const twDisplayName = displayNameEl?.textContent;
const bskyHandle =
userCell.textContent?.match(/([^/\s]+\.bsky\.social)/)?.[1] ??
userCell.textContent?.match(new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`))?.[1] ??
userCell.textContent
?.match(/bsky\.app\/profile\/([^/\s]+)…?/)?.[1]
?.replace("…", "") ??

View File

@@ -14,6 +14,7 @@ import {
RATE_LIMIT_ERROR_MESSAGE,
STORAGE_KEYS,
TARGET_URLS_REGEX,
BSKY_DOMAIN,
} from "~lib/constants";
function IndexPopup() {
@@ -135,7 +136,7 @@ function IndexPopup() {
setIsLoading(true);
const formattedIdentifier = (
identifier.includes(".") ? identifier : `${identifier}.bsky.social`
identifier.includes(".") ? identifier : `${identifier}.${BSKY_DOMAIN}`
).replace(/^@/, "");
try {
const { session, error } = await sendToBackground({
@@ -236,7 +237,7 @@ function IndexPopup() {
<input
type="text"
name="identifier"
placeholder="your-username.bsky.social"
placeholder={`your-username.${BSKY_DOMAIN}`}
value={identifier}
onChange={(e) => setIdentifier(e.target.value)}
className="input input-bordered input-sm w-full max-w-xs join-item focus:outline-none mt-1"