mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: get image only when cors error (#721)
This commit is contained in:
@ -18,23 +18,32 @@ const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="dialog-header-container">
|
<div className="dialog-header-container">
|
||||||
<p className="title-text">{t("common.about")}</p>
|
<p className="title-text flex items-center">
|
||||||
|
<img className="w-7 h-auto mr-1" src="/logo.webp" alt="" />
|
||||||
|
{t("common.about")} memos
|
||||||
|
</p>
|
||||||
<button className="btn close-btn" onClick={handleCloseBtnClick}>
|
<button className="btn close-btn" onClick={handleCloseBtnClick}>
|
||||||
<Icon.X />
|
<Icon.X />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="dialog-content-container">
|
<div className="dialog-content-container">
|
||||||
<p className="flex justify-start items-center">
|
|
||||||
<img className="logo-img w-16 h-auto" src="/logo.webp" alt="" />
|
|
||||||
<span className=" font-mono text-4xl">memos</span>
|
|
||||||
</p>
|
|
||||||
<p>{t("slogan")}</p>
|
<p>{t("slogan")}</p>
|
||||||
<br />
|
<div className="border-t mt-1 pt-2 flex flex-row justify-start items-center">
|
||||||
<div className="addition-info-container">
|
<span className=" text-gray-500 mr-2">Other projects:</span>
|
||||||
|
<a href="https://github.com/boojack/sticky-notes" className="flex items-center underline text-blue-600 hover:opacity-80">
|
||||||
|
<img
|
||||||
|
className="w-5 h-auto mr-1"
|
||||||
|
src="https://raw.githubusercontent.com/boojack/sticky-notes/main/public/sticky-notes.ico"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
<span>Sticky notes</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 flex flex-row text-sm justify-start items-center">
|
||||||
<GitHubBadge />
|
<GitHubBadge />
|
||||||
<span className="ml-2">
|
<span className="ml-2">
|
||||||
{t("common.version")}:
|
{t("common.version")}:
|
||||||
<span className="pre-text">
|
<span className="font-mono">
|
||||||
{profile.version}-{profile.mode}
|
{profile.version}-{profile.mode}
|
||||||
</span>
|
</span>
|
||||||
🎉
|
🎉
|
||||||
|
@ -6,11 +6,20 @@ const applyStyles = async (sourceElement: HTMLElement, clonedElement: HTMLElemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sourceElement.tagName === "IMG") {
|
if (sourceElement.tagName === "IMG") {
|
||||||
|
const url = sourceElement.getAttribute("src") ?? "";
|
||||||
|
let covertFailed = false;
|
||||||
try {
|
try {
|
||||||
const url = await convertResourceToDataURL(sourceElement.getAttribute("src") ?? "");
|
(clonedElement as HTMLImageElement).src = await convertResourceToDataURL(url);
|
||||||
(clonedElement as HTMLImageElement).src = url;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// do nth
|
covertFailed = true;
|
||||||
|
}
|
||||||
|
// NOTE: Get image blob from backend to avoid CORS error.
|
||||||
|
if (covertFailed) {
|
||||||
|
try {
|
||||||
|
(clonedElement as HTMLImageElement).src = await convertResourceToDataURL(`/o/get/image?url=${url}`);
|
||||||
|
} catch (error) {
|
||||||
|
// do nth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ const renderer = (rawStr: string): string => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const imageUrl = absolutifyLink(escape(matchResult[1]));
|
const imageUrl = absolutifyLink(escape(matchResult[1]));
|
||||||
// NOTE: Get image blob from backend to avoid CORS.
|
return `<img class='img' src='${imageUrl}' />`;
|
||||||
return `<img class='img' src='/o/get/image?url=${imageUrl}' />`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,31 +1,13 @@
|
|||||||
.about-site-dialog {
|
.about-site-dialog {
|
||||||
@apply px-4;
|
|
||||||
|
|
||||||
> .dialog-container {
|
> .dialog-container {
|
||||||
@apply w-112 max-w-full;
|
@apply w-112 max-w-full;
|
||||||
|
|
||||||
> .dialog-content-container {
|
> .dialog-content-container {
|
||||||
@apply flex flex-col justify-start items-start leading-relaxed;
|
@apply flex flex-col justify-start items-start;
|
||||||
|
|
||||||
> .logo-img {
|
|
||||||
@apply h-16;
|
|
||||||
}
|
|
||||||
|
|
||||||
> p {
|
> p {
|
||||||
@apply my-1;
|
@apply my-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pre-text {
|
|
||||||
@apply font-mono mx-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .addition-info-container {
|
|
||||||
@apply flex flex-row text-sm justify-start items-center;
|
|
||||||
|
|
||||||
> .github-badge-container {
|
|
||||||
@apply mr-4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.dialog-wrapper {
|
.dialog-wrapper {
|
||||||
@apply fixed top-0 left-0 flex flex-col justify-start items-center w-full h-full pt-16 pb-8 z-100 overflow-x-hidden overflow-y-scroll bg-transparent transition-all hide-scrollbar;
|
@apply fixed top-0 left-0 flex flex-col justify-start items-center w-full h-full pt-16 pb-8 px-4 z-100 overflow-x-hidden overflow-y-scroll bg-transparent transition-all hide-scrollbar;
|
||||||
|
|
||||||
&.showup {
|
&.showup {
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
@ -10,7 +10,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
> .dialog-container {
|
> .dialog-container {
|
||||||
@apply flex flex-col justify-start items-start bg-white dark:bg-zinc-800 dark:text-gray-200 p-4 rounded-lg;
|
@apply max-w-full flex flex-col justify-start items-start bg-white dark:bg-zinc-800 dark:text-gray-200 p-4 rounded-lg;
|
||||||
|
|
||||||
> .dialog-header-container {
|
> .dialog-header-container {
|
||||||
@apply flex flex-row justify-between items-center w-full mb-4;
|
@apply flex flex-row justify-between items-center w-full mb-4;
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
> .tip-text {
|
> .tip-text {
|
||||||
@apply hidden ml-1 text-xs leading-5 text-gray-700 border border-gray-300 rounded-xl px-2;
|
@apply hidden ml-1 text-xs leading-5 text-gray-600 dark:text-gray-300 border border-gray-300 dark:border-zinc-500 rounded-xl px-2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
.share-memo-dialog {
|
.share-memo-dialog {
|
||||||
> .dialog-container {
|
> .dialog-container {
|
||||||
@apply w-96 p-0 bg-white dark:bg-zinc-800;
|
@apply w-96 max-w-full p-0 bg-white dark:bg-zinc-800;
|
||||||
|
|
||||||
> .dialog-header-container {
|
> .dialog-header-container {
|
||||||
@apply py-2 pt-4 px-4 pl-6 mb-0 rounded-t-lg;
|
@apply py-3 px-4 pl-6 mb-0 rounded-t-lg border-b dark:border-b-zinc-600;
|
||||||
}
|
}
|
||||||
|
|
||||||
> .dialog-content-container {
|
> .dialog-content-container {
|
||||||
|
Reference in New Issue
Block a user