-
Notifications
You must be signed in to change notification settings - Fork 70
fix(canvas): route the canvas to the site's content store #1249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dc47d59
test(canvas): cover store routing for the source url, the doc check a…
benpeter 95fa1fb
fix(canvas): route the document and the collab room to the site's store
benpeter 6536d15
test(canvas): a store failure should not be reported as a permission …
benpeter cf09f96
fix(canvas): report the store's status instead of a blanket not-permi…
benpeter a292029
test(canvas): media bus images render from the preview origin
benpeter 7b68d91
fix(canvas): render media bus images from the preview origin
benpeter 79d4c04
test(canvas): image uploads go to the site's store, in the doc pane a…
benpeter b9ec78d
fix(canvas): upload images through the source api, into the site's store
benpeter 5b7053a
fix(canvas): check the sign-in before the store, and read da-admin wi…
benpeter 94601ea
test(canvas): media images render from the origin the canvas logged into
benpeter 57e8f95
fix(canvas): render media images from getPreviewOrigin, not getLivePr…
benpeter 605a7fe
fix(canvas): remove leftover debug log from handleImageReplace
mhaack 0b6b765
fix(shared): route fetchDaConfigs through getNx2Api's config API
mhaack 85aaa38
Merge branch 'main' into ewhlx6
mhaack 2e70997
fix(canvas): route getPreviewStatus through getNx2Api's status.get
mhaack 2897858
test: refuse an image over the upload limit
benpeter cd558cc
fix(canvas): fail an oversized image upload with a toast
benpeter 5f44f11
fix(canvas): apply the image size limit only on the source bus
benpeter 8ea1ff1
refactor(canvas): call buildSourceUrl directly, drop the ctx wrapper
benpeter cf312ff
fix(canvas): one line of toast text, and the exported error variant
benpeter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
blocks/canvas/ew-editor-doc/prose-plugins/mediaBusImage.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // eslint-disable-next-line import/no-unresolved | ||
| import { Plugin, PluginKey } from 'da-y-wrapper'; | ||
| import { getPreviewOrigin } from '../../editor-utils/editor-utils.js'; | ||
|
|
||
| const mediaBusImageKey = new PluginKey('canvasMediaBusImage'); | ||
|
|
||
| // a media bus src ("./media_123.png") only resolves where the page is served, so it is rewritten | ||
| // to the doc's preview origin for display; node attrs and the saved document keep the relative | ||
| // path. getPreviewOrigin matches the origin fetchWysiwygCookie logs into, unlike getLivePreviewUrl. | ||
| export function getRenderableSrc(src, ctx) { | ||
| if (!src || !src.startsWith('./media_')) return null; | ||
| const { org, repo } = ctx ?? {}; | ||
| if (!org || !repo) return null; | ||
| return `${getPreviewOrigin(org, repo)}/${src.slice(2)}`; | ||
| } | ||
|
|
||
| function updateImageSrcs(view, ctx) { | ||
| view.dom.querySelectorAll('img[src^="./media_"]').forEach((img) => { | ||
| const renderableSrc = getRenderableSrc(img.getAttribute('src'), ctx); | ||
| if (renderableSrc) img.src = renderableSrc; | ||
| }); | ||
| } | ||
|
|
||
| export default function mediaBusImage(ctx) { | ||
| return new Plugin({ | ||
| key: mediaBusImageKey, | ||
| view(view) { | ||
| updateImageSrcs(view, ctx); | ||
| return { | ||
| update(updatedView, prevState) { | ||
| if (updatedView.state.doc !== prevState.doc) updateImageSrcs(updatedView, ctx); | ||
| }, | ||
| }; | ||
| }, | ||
| }); | ||
| } |
35 changes: 18 additions & 17 deletions
35
blocks/canvas/ew-editor-doc/prose-plugins/sourceUploadContext.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,37 @@ | ||
| import { checkDoc } from './source.js'; | ||
| import { buildSourceUrl, checkDoc } from './source.js'; | ||
| import { initIms } from '../../../shared/utils.js'; | ||
|
|
||
| export async function resolveEditorDocSession(sourceUrl) { | ||
| export function sessionErrorFromResponse(resp) { | ||
| const status = resp?.status; | ||
| if (typeof status !== 'number') return { ok: false, error: 'Could not reach the content store' }; | ||
| if (resp.ok || status === 404) return null; | ||
| if (status === 401) return { ok: false, error: 'Sign in required' }; | ||
| if (status === 403) return { ok: false, error: 'Not permitted' }; | ||
| const detail = resp.headers?.get?.('x-error'); | ||
| const reason = detail ? `: ${detail}` : ''; | ||
| return { ok: false, error: `Could not load the document (${status})${reason}` }; | ||
| } | ||
|
|
||
| // takes the ctx rather than a url, so the sign-in check runs before the store lookup needs a token | ||
| export async function resolveEditorDocSession(ctx) { | ||
| const ims = await initIms(); | ||
| const token = ims?.accessToken?.token ?? null; | ||
| if (ims?.anonymous || !token) { | ||
| return { ok: false, error: 'Sign in required' }; | ||
| } | ||
|
|
||
| const resp = await checkDoc(sourceUrl); | ||
| if (!resp.ok && resp.status !== 404) { | ||
| const error = resp.status === 401 ? 'Sign in required' : 'Not permitted'; | ||
| return { ok: false, error }; | ||
| let sourceUrl; | ||
| try { | ||
| sourceUrl = await buildSourceUrl(ctx?.path); | ||
| } catch { | ||
| return { ok: false, error: 'Could not reach the content store' }; | ||
| } | ||
| if (!sourceUrl) return { ok: false, error: 'Could not reach the content store' }; | ||
|
|
||
| const resp = await checkDoc(sourceUrl); | ||
| const failure = sessionErrorFromResponse(resp); | ||
| if (failure) return failure; | ||
|
|
||
| const permissions = resp.permissions || ['read']; | ||
| return { ok: true, token, permissions }; | ||
| return { ok: true, token, permissions, sourceUrl }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.