-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4224 from serlo/refactor/add-image-proxy
refactor(editor): add image proxy for privacy (serlo-only)
- Loading branch information
Showing
8 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
6 changes: 4 additions & 2 deletions
6
packages/editor/src/plugins/image-gallery/components/static/static-lightbox-image.tsx
This file contains 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 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
25 changes: 25 additions & 0 deletions
25
packages/editor/src/plugins/image/components/editor-image.tsx
This file contains 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,25 @@ | ||
import { serloDomain } from '@editor/utils/serlo-domain' | ||
import { SerloOnlyFeaturesContext } from '@editor/utils/serlo-extra-context' | ||
import { ImgHTMLAttributes, useContext } from 'react' | ||
|
||
/** | ||
* Proxies external editor images via cloudflare worker | ||
* Temporary fix for privacy reasons. Long term we want to upload | ||
* images to our own bucket instead | ||
*/ | ||
export function EditorImage(props: ImgHTMLAttributes<HTMLImageElement>) { | ||
const isSerlo = useContext(SerloOnlyFeaturesContext).isSerlo | ||
return <img {...props} src={getSrc(isSerlo, props.src)} /> | ||
} | ||
|
||
function getSrc(isSerlo?: boolean, src?: string) { | ||
if (!isSerlo || !src) return src | ||
|
||
const isAllowed = | ||
src.startsWith('https://assets.serlo.org/') || | ||
src.startsWith('https://pixabay.com/') | ||
|
||
if (isAllowed) return src | ||
|
||
return `https://asset-proxy.${serloDomain}/image?url=${encodeURIComponent(src)}` | ||
} |
This file contains 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