tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
use a lock for blob uploads
awarm.space
4 months ago
3d1b1992
0fd0b80a
+9
-3
1 changed file
expand all
collapse all
unified
split
actions
publishToPublication.ts
+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
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
166
+
// Create a lock to serialize image uploads
167
167
+
const uploadLock = new Lock();
168
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
175
-
let blob = await agent.com.atproto.repo.uploadBlob(binary, {
176
176
-
headers: { "Content-Type": binary.type },
179
179
+
return uploadLock.withLock(async () => {
180
180
+
let blob = await agent.com.atproto.repo.uploadBlob(binary, {
181
181
+
headers: { "Content-Type": binary.type },
182
182
+
});
183
183
+
return blob.data.blob;
177
184
});
178
178
-
return blob.data.blob;
179
185
}
180
186
async function blocksToRecord(
181
187
blocks: Block[],