···1010}) {
1111 let record = pub.record as PubLeafletPublication.Record;
1212 if (isProductionDomain() && record?.base_path) {
1313- return new URL(record.base_path);
1313+ return record.base_path;
1414 }
1515 let aturi = new AtUri(pub.uri);
1616 return `/lish/${aturi.host}/${record?.name || pub.name}`;
+79
app/lish/createPub/updatePublication.ts
···11+"use server";
22+import { TID } from "@atproto/common";
33+import { AtpBaseClient, PubLeafletPublication } from "lexicons/api";
44+import { createOauthClient } from "src/atproto-oauth";
55+import { getIdentityData } from "actions/getIdentityData";
66+import { supabaseServerClient } from "supabase/serverClient";
77+import { Json } from "supabase/database.types";
88+99+export async function updatePublication({
1010+ uri,
1111+ name,
1212+ description,
1313+ iconFile,
1414+}: {
1515+ uri: string;
1616+ name: string;
1717+ description: string;
1818+ iconFile: File | null;
1919+}) {
2020+ const oauthClient = await createOauthClient();
2121+ let identity = await getIdentityData();
2222+ if (!identity || !identity.atp_did) return;
2323+2424+ let credentialSession = await oauthClient.restore(identity.atp_did);
2525+ let agent = new AtpBaseClient(
2626+ credentialSession.fetchHandler.bind(credentialSession),
2727+ );
2828+ let { data: existingPub } = await supabaseServerClient
2929+ .from("publications")
3030+ .select("*")
3131+ .eq("uri", uri)
3232+ .single();
3333+ if (!existingPub || existingPub.identity_did! === identity.atp_did) return;
3434+3535+ let record: PubLeafletPublication.Record = {
3636+ $type: "pub.leaflet.publication",
3737+ name,
3838+ ...(existingPub.record as object),
3939+ };
4040+4141+ if (description) {
4242+ record.description = description;
4343+ }
4444+4545+ // Upload the icon if provided How do I tell if there isn't a new one?
4646+ if (iconFile && iconFile.size > 0) {
4747+ const buffer = await iconFile.arrayBuffer();
4848+ const uploadResult = await agent.com.atproto.repo.uploadBlob(
4949+ new Uint8Array(buffer),
5050+ { encoding: iconFile.type },
5151+ );
5252+5353+ if (uploadResult.data.blob) {
5454+ record.icon = uploadResult.data.blob;
5555+ }
5656+ }
5757+5858+ let result = await agent.com.atproto.repo.putRecord({
5959+ repo: credentialSession.did!,
6060+ rkey: TID.nextStr(),
6161+ record,
6262+ collection: record.$type,
6363+ validate: false,
6464+ });
6565+6666+ //optimistically write to our db!
6767+ let { data: publication } = await supabaseServerClient
6868+ .from("publications")
6969+ .update({
7070+ identity_did: credentialSession.did!,
7171+ name: record.name,
7272+ record: record as Json,
7373+ })
7474+ .eq("uri", uri)
7575+ .select()
7676+ .single();
7777+7878+ return { success: true, publication };
7979+}