Skip to content

Commit ae1167b

Browse files
author
Michael Lively
committed
refactor with updated metadata properties
1 parent ea09b02 commit ae1167b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

extensions/ipynb/src/notebookImagePaste.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,11 @@ function encodeBase64(buffer: Uint8Array, padded = true, urlSafe = false) {
125125

126126
function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string, filetype: string, startingAttachments: any): { [key: string]: any } {
127127
const outputMetadata = { ...cell.metadata };
128-
const customField = cell.metadata.custom;
129-
if (!customField) {
130-
return { 'custom': { 'attachments': { [filename]: { 'image/png': b64 } } } };
131-
}
132128

133-
const attachmentField = cell.metadata.custom.attachments;
134-
if (!attachmentField) {
135-
outputMetadata['attachments'] = { [filename]: { 'image/png': b64 } };
129+
if (!outputMetadata.custom) {
130+
outputMetadata['custom'] = { 'attachments': { [filename]: { 'image/png': b64 } } };
131+
} else if (!outputMetadata.custom.attachments) {
132+
outputMetadata.custom['attachments'] = { [filename]: { 'image/png': b64 } };
136133
} else {
137134
for (let appendValue = 2; filename in startingAttachments; appendValue++) {
138135
const objEntries = Object.entries(startingAttachments[filename]);
@@ -145,6 +142,7 @@ function buildMetadata(b64: string, cell: vscode.NotebookCell, filename: string,
145142
}
146143
outputMetadata.custom.attachments[filename] = { 'image/png': b64 };
147144
}
145+
148146
return outputMetadata;
149147
}
150148

0 commit comments

Comments
 (0)