mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-09-13 07:23:32 -06:00
🚀 support for firefox
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AtUri, BskyAgent } from "@atproto/api";
|
||||
import { AtUri, BskyAgent, type AtpSessionData } from "@atproto/api";
|
||||
|
||||
export type BskyLoginParams = {
|
||||
identifier: string;
|
||||
@@ -13,9 +13,24 @@ export class BskyClient {
|
||||
email: string;
|
||||
};
|
||||
agent: BskyAgent;
|
||||
session = {}
|
||||
|
||||
private constructor() {
|
||||
this.agent = new BskyAgent({ service: this.service });
|
||||
this.agent = new BskyAgent({ service: this.service, persistSession: (evt, session) => {
|
||||
this.session = session
|
||||
} });
|
||||
}
|
||||
|
||||
public static createAgentFromSession(session: AtpSessionData): BskyClient {
|
||||
const client = new BskyClient();
|
||||
client.agent.resumeSession(session);
|
||||
client.me = {
|
||||
did: session.did,
|
||||
handle: session.handle,
|
||||
email: session.email,
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public static async createAgent({
|
||||
|
92
src/lib/bskyServiceWorkerClient.ts
Normal file
92
src/lib/bskyServiceWorkerClient.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { sendToBackground } from "@plasmohq/messaging";
|
||||
|
||||
export type BskyLoginParams = {
|
||||
identifier: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class BskyServiceWorkerClient {
|
||||
private session = {}
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
public static async createAgent({
|
||||
identifier,
|
||||
password,
|
||||
}: BskyLoginParams): Promise<BskyServiceWorkerClient> {
|
||||
const client = new BskyServiceWorkerClient();
|
||||
const { session } = await sendToBackground({
|
||||
name: "login",
|
||||
body: {
|
||||
identifier,
|
||||
password,
|
||||
}
|
||||
})
|
||||
client.session = session
|
||||
return client;
|
||||
}
|
||||
|
||||
public searchUser = async ({
|
||||
term,
|
||||
limit,
|
||||
}: {
|
||||
term: string;
|
||||
limit: number;
|
||||
}) => {
|
||||
const { actors } = await sendToBackground({
|
||||
name: "searchUser",
|
||||
body: {
|
||||
session: this.session,
|
||||
term,
|
||||
limit,
|
||||
}
|
||||
})
|
||||
return actors;
|
||||
};
|
||||
|
||||
public follow = async (subjectDid: string) => {
|
||||
const { result } = await sendToBackground({
|
||||
name: "follow",
|
||||
body: {
|
||||
session: this.session,
|
||||
subjectDid
|
||||
}
|
||||
})
|
||||
return result;
|
||||
}
|
||||
|
||||
public unfollow = async (followUri: string) => {
|
||||
const { result } = await sendToBackground({
|
||||
name: "unfollow",
|
||||
body: {
|
||||
session: this.session,
|
||||
followUri
|
||||
}
|
||||
})
|
||||
return result;
|
||||
}
|
||||
|
||||
public block = async (subjectDid: string) => {
|
||||
const { result } = await sendToBackground({
|
||||
name: "block",
|
||||
body: {
|
||||
session: this.session,
|
||||
subjectDid
|
||||
}
|
||||
})
|
||||
return result;
|
||||
}
|
||||
|
||||
public unblock = async (blockUri: string) => {
|
||||
// TODO: unblock is not working. Need to fix it.
|
||||
const { result } = await sendToBackground({
|
||||
name: "unblock",
|
||||
body: {
|
||||
session: this.session,
|
||||
blockUri
|
||||
}
|
||||
})
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import { debugLog } from "~lib/utils";
|
||||
import type { BskyClient } from './bskyClient';
|
||||
import type { ViewerState } from '@atproto/api/dist/client/types/app/bsky/actor/defs';
|
||||
import type { UserCellBtnLabel } from './components/BskyUserCell';
|
||||
import type { BskyServiceWorkerClient } from './bskyServiceWorkerClient';
|
||||
|
||||
|
||||
const notFoundUserCache = new Set<string>()
|
||||
@@ -20,7 +21,7 @@ export const searchAndInsertBskyUsers = async (
|
||||
addQuery,
|
||||
removeQuery,
|
||||
}: {
|
||||
agent: BskyClient,
|
||||
agent: BskyServiceWorkerClient | BskyClient,
|
||||
userCellQueryParam: string,
|
||||
btnLabel: UserCellBtnLabel,
|
||||
statusKey: keyof ViewerState,
|
||||
|
Reference in New Issue
Block a user