MCPcopy Index your code
hub / github.com/resend/react-email / executeUploadFlow

Function executeUploadFlow

packages/editor/src/plugins/image/upload-flow.ts:24–51  ·  view source on GitHub ↗
({
  editor,
  file,
  uploadImage,
}: ExecuteUploadFlowParams)

Source from the content-addressed store, hash-verified

22}
23
24export async function executeUploadFlow({
25 editor,
26 file,
27 uploadImage,
28}: ExecuteUploadFlowParams): Promise<void> {
29 const blobUrl = URL.createObjectURL(file);
30
31 const selectedImageAttrs = getSelectedImageAttrs(editor);
32
33 editor
34 .chain()
35 .focus()
36 .setImage({ ...selectedImageAttrs, src: blobUrl })
37 .run();
38
39 try {
40 const { url } = await uploadImage(file);
41 swapImageSrc(editor, blobUrl, url);
42 } catch (error) {
43 removeImageBySrc(editor, blobUrl);
44 console.error(
45 `Failed to upload image "${file.name}":`,
46 error instanceof Error ? error : new Error(String(error)),
47 );
48 } finally {
49 URL.revokeObjectURL(blobUrl);
50 }
51}
52
53function swapImageSrc(editor: Editor, oldSrc: string, newSrc: string): void {
54 const { state } = editor;

Callers 4

addCommandsFunction · 0.90
handlePasteFunction · 0.90
handleDropFunction · 0.90

Calls 5

getSelectedImageAttrsFunction · 0.85
uploadImageFunction · 0.85
swapImageSrcFunction · 0.85
removeImageBySrcFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected