a tool for shared writing and social publishing

use a lock for blob uploads

+9 -3
+9 -3
actions/publishToPublication.ts
··· 42 42 import { $Typed, UnicodeString } from "@atproto/api"; 43 43 import { List, parseBlocksToList } from "src/utils/parseBlocksToList"; 44 44 import { getBlocksWithTypeLocal } from "src/hooks/queries/useBlocks"; 45 + import { Lock } from "src/utils/lock"; 45 46 46 47 export async function publishToPublication({ 47 48 root_entity, ··· 162 163 type: "doc" | "canvas"; 163 164 }[] = []; 164 165 166 + // Create a lock to serialize image uploads 167 + const uploadLock = new Lock(); 168 + 165 169 let firstEntity = scan.eav(root_entity, "root/page")?.[0]; 166 170 if (!firstEntity) throw new Error("No root page"); 167 171 let blocks = getBlocksWithTypeLocal(facts, firstEntity?.data.value); ··· 172 176 let data = await fetch(src); 173 177 if (data.status !== 200) return; 174 178 let binary = await data.blob(); 175 - let blob = await agent.com.atproto.repo.uploadBlob(binary, { 176 - headers: { "Content-Type": binary.type }, 179 + return uploadLock.withLock(async () => { 180 + let blob = await agent.com.atproto.repo.uploadBlob(binary, { 181 + headers: { "Content-Type": binary.type }, 182 + }); 183 + return blob.data.blob; 177 184 }); 178 - return blob.data.blob; 179 185 } 180 186 async function blocksToRecord( 181 187 blocks: Block[],