Something went wrong. Try again.
leaflet fork for copy edit / bug fixes forked from leaflet.pub/leaflet
Something went wrong. Try again.
TypeScript
at ghost-import
123456789101112131415161718192021222324252627282930313233343536373839404142434445"use server";import { getAuthIdentity } from "src/auth";import { createNewLeaflet } from "./createNewLeaflet";import { supabaseServerClient } from "supabase/serverClient";import { isConfirmedContributor } from "src/contributorPermissions";
export async function createPublicationDraft(publication_uri: string) { let identity = await getAuthIdentity(); if (!identity || !identity.atp_did) return null;
let { data: publication } = await supabaseServerClient .from("publications") .select("identity_did") .eq("uri", publication_uri) .single(); if (!publication) return null;
let isOwner = publication.identity_did === identity.atp_did; if (!isOwner && !(await isConfirmedContributor(publication_uri, identity.atp_did))) return null;
let newLeaflet = await createNewLeaflet({ pageType: "doc", redirectUser: false, firstBlockType: "text", });
await supabaseServerClient .from("leaflets_in_publications") .insert({ publication: publication_uri, leaflet: newLeaflet, doc: null });
// If a contributor created the draft, automatically add them as a draft // contributor so it shows up on their dashboard. if (!isOwner && newLeaflet) { await supabaseServerClient .from("leaflet_contributors") .upsert( { leaflet: newLeaflet, contributor_did: identity.atp_did }, { onConflict: "leaflet,contributor_did", ignoreDuplicates: true }, ); }
return newLeaflet;}