From 90664d7417a898753ea457bd6aad07d4d0ccb092 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sat, 19 Aug 2023 16:00:43 +0700 Subject: [PATCH] UBER-771: Use cookie instead of token for images (#3607) Signed-off-by: Andrey Sobolev --- packages/presentation/src/utils.ts | 6 +- .../src/components/StyledTextBox.svelte | 2 +- .../text-editor/src/components/extensions.ts | 4 +- .../text-editor/src/components/imageExt.ts | 72 +++++++++---------- packages/ui/src/components/Panel.svelte | 13 +++- packages/ui/src/location.ts | 2 +- plugins/workbench-resources/src/connect.ts | 4 ++ server/front/src/index.ts | 24 ++++++- 8 files changed, 81 insertions(+), 46 deletions(-) diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index 5fa7794e73..84dfd646c8 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -284,11 +284,11 @@ export function getFileUrl (file: string, size: IconSize = 'full', filename?: st return file } const uploadUrl = getMetadata(plugin.metadata.UploadURL) - const token = getMetadata(plugin.metadata.Token) + if (filename !== undefined) { - return `${uploadUrl as string}/${filename}?file=${file}&token=${token as string}&size=${size as string}` + return `${uploadUrl as string}/${filename}?file=${file}&size=${size as string}` } - return `${uploadUrl as string}?file=${file}&token=${token as string}&size=${size as string}` + return `${uploadUrl as string}?file=${file}&size=${size as string}` } /** diff --git a/packages/text-editor/src/components/StyledTextBox.svelte b/packages/text-editor/src/components/StyledTextBox.svelte index 8561516254..ad54c96603 100644 --- a/packages/text-editor/src/components/StyledTextBox.svelte +++ b/packages/text-editor/src/components/StyledTextBox.svelte @@ -143,7 +143,7 @@ const attachments = new Map() const imagePlugin = ImageRef.configure({ - inline: false, + inline: true, HTMLAttributes: {}, attachFile, reportNode: (id, node) => { diff --git a/packages/text-editor/src/components/extensions.ts b/packages/text-editor/src/components/extensions.ts index a248032681..abe370de1f 100644 --- a/packages/text-editor/src/components/extensions.ts +++ b/packages/text-editor/src/components/extensions.ts @@ -71,8 +71,8 @@ export const defaultExtensions: AnyExtension[] = [ openOnClick: true, HTMLAttributes: { class: 'cursor-pointer', rel: 'noopener noreferrer', target: '_blank' } }), - ...tableExtensions, - ...taskListExtensions + ...tableExtensions + // ...taskListExtensions // Disable since tasks are not working properly now. ] export const mInsertTable = [ diff --git a/packages/text-editor/src/components/imageExt.ts b/packages/text-editor/src/components/imageExt.ts index 03d45bbf0b..83d48c7973 100644 --- a/packages/text-editor/src/components/imageExt.ts +++ b/packages/text-editor/src/components/imageExt.ts @@ -57,7 +57,7 @@ export const ImageRef = Node.create({ addOptions () { return { - inline: false, + inline: true, HTMLAttributes: {} } }, @@ -75,25 +75,23 @@ export const ImageRef = Node.create({ addAttributes () { return { - fileid: { - default: null, - parseHTML: (element) => element.getAttribute('file-id'), - renderHTML: (attributes) => { - // eslint-disable-next-line - if (!attributes.fileid) { - return {} - } - - return { - 'file-id': attributes.fileid - } - } + 'file-id': { + default: null }, width: { default: null }, height: { default: null + }, + src: { + default: null + }, + alt: { + default: null + }, + title: { + default: null } } }, @@ -115,29 +113,31 @@ export const ImageRef = Node.create({ HTMLAttributes ) const id = merged['file-id'] - merged.src = getFileUrl(id, 'full') - let width: IconSize | undefined - switch (merged.width) { - case '32px': - width = 'small' - break - case '64px': - width = 'medium' - break - case '128px': - case '256px': - width = 'large' - break - case '512px': - width = 'x-large' - break - } - if (width !== undefined) { - merged.src = getFileUrl(id, width) - merged.srcset = getFileUrl(id, width) + ' 1x,' + getFileUrl(id, getIconSize2x(width)) + ' 2x' + if (id != null) { + merged.src = getFileUrl(id, 'full') + let width: IconSize | undefined + switch (merged.width) { + case '32px': + width = 'small' + break + case '64px': + width = 'medium' + break + case '128px': + case '256px': + width = 'large' + break + case '512px': + width = 'x-large' + break + } + if (width !== undefined) { + merged.src = getFileUrl(id, width) + merged.srcset = getFileUrl(id, width) + ' 1x,' + getFileUrl(id, getIconSize2x(width)) + ' 2x' + } + merged.class = 'textEditorImage' + this.options.reportNode?.(id, node) } - merged.class = 'textEditorImage' - this.options.reportNode?.(id, node) return ['img', merged] }, diff --git a/packages/ui/src/components/Panel.svelte b/packages/ui/src/components/Panel.svelte index 1bf3393cba..550a2e2e25 100644 --- a/packages/ui/src/components/Panel.svelte +++ b/packages/ui/src/components/Panel.svelte @@ -14,7 +14,7 @@ -->