Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import { ok } from "@atcute/client";import { mainSchema as uploadBlobSchema } from "@atcute/atproto/types/repo/uploadBlob";import type { Nsid } from "@atcute/lexicons/syntax";import type { OAuthUserAgent } from "@atcute/oauth-browser-client";import { createClient } from "$lib/auth/agent";import { FOLLOW_VIEWER, STAR_VIEWER } from "$lib/api/descriptors";import { enrich, target } from "$lib/api/enrich";import { jsonGet } from "$lib/api/_request";import type { BobbinContext, XrpcRequestInit } from "$lib/api/client";import { putRecord } from "$lib/api/write";import type * as ShTangledActorGetTrending from "$lib/api/lexicons/types/sh/tangled/actor/getTrending";import type { ProfileRecord } from "$lib/api/records";
const PROFILE_COLLECTION = "sh.tangled.actor.profile" as Nsid;
const AVATAR_TYPES: Record<string, true> = { "image/png": true, "image/jpeg": true };const MAX_AVATAR_BYTES = 1_000_000;
export const getTrending = (ctx: BobbinContext, init?: XrpcRequestInit) => jsonGet<ShTangledActorGetTrending.$output>(ctx, "sh.tangled.actor.getTrending", {}, init);
export const getTrendingWithViewerState = ( ctx: BobbinContext, viewer: string, init?: XrpcRequestInit) => enrich<ShTangledActorGetTrending.$output>( ctx, { xrpc: "sh.tangled.actor.getTrending", viewer, enrich: [target(FOLLOW_VIEWER, ["people[].did"]), target(STAR_VIEWER, ["repos[].did"])] }, init );
export const uploadProfileAvatar = async ( agent: OAuthUserAgent, image: Blob): Promise<NonNullable<ProfileRecord["avatar"]>> => { if (!AVATAR_TYPES[image.type]) throw new Error("Choose a PNG or JPEG image."); if (image.size > MAX_AVATAR_BYTES) throw new Error("Profile pictures must be 1 MB or smaller.");
const rpc = createClient(agent); const { blob } = await ok(rpc.call(uploadBlobSchema, { input: image })); return blob;};
// the profile record lives at the fixed rkey `self`; put upserts it.export const putProfile = async (agent: OAuthUserAgent, record: ProfileRecord): Promise<void> => { await putRecord(agent, PROFILE_COLLECTION, "self", record);};