From a3ec8db3e0a435547e964e637db3f26dc6fc6a7d Mon Sep 17 00:00:00 2001 From: chanho Date: Tue, 18 Feb 2025 03:31:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor/Editor.tsx | 11 +++++++++-- src/utils/jwtDecode.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/utils/jwtDecode.ts diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx index c062b26..52e25cd 100644 --- a/src/components/editor/Editor.tsx +++ b/src/components/editor/Editor.tsx @@ -52,11 +52,18 @@ import { CustomTableCell } from './customComponent/CustomTableCell'; import CustomTextStyle from './customComponent/CustomTextStyle'; import { CustomTable } from './customComponent/CustomTable'; import CustomOembed from './customComponent/CustomOembed'; +import { jwtDecode } from '../../utils/jwtDecode'; const Editor = ({ content }: { content: JSONContent[] | null }) => { + // 토큰을 가져와 디코딩하여 사용자 닉네임을 가져와서 authorName에 넣어준다. + const token = localStorage.getItem('token'); + const decodedToken = jwtDecode(token); + const authorName = decodedToken.nickname; + decodedToken.nickname = authorName; + const [articleData, setArticleData] = useState({ title: '', - authorName: 'none', + authorName: authorName, categoryName: 'none', type: 'none', paywallUp: '', @@ -364,4 +371,4 @@ const Editor = ({ content }: { content: JSONContent[] | null }) => { ); }; -export default Editor; +export default Editor; \ No newline at end of file diff --git a/src/utils/jwtDecode.ts b/src/utils/jwtDecode.ts new file mode 100644 index 0000000..9fa595c --- /dev/null +++ b/src/utils/jwtDecode.ts @@ -0,0 +1,14 @@ +export const jwtDecode = (token: string | null) => { + if (!token) return null; + + const base64Url = token.split('.')[1]; + const base64 = base64Url.replace('-', '+').replace('_', '/'); + const jsonPayload = decodeURIComponent( + atob(base64) + .split('') + .map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)) + .join('') + ); + + return JSON.parse(jsonPayload); +} \ No newline at end of file From 1fcc83351aab8b5316fe0ff45ef37a137cdc2835 Mon Sep 17 00:00:00 2001 From: chanho Date: Tue, 18 Feb 2025 03:31:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20html=20=EB=B3=80=ED=99=98=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor/PreviewComponrnt.tsx | 2 +- .../editor/common/extractPaywallData.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/editor/PreviewComponrnt.tsx b/src/components/editor/PreviewComponrnt.tsx index eba0ae0..4811a99 100644 --- a/src/components/editor/PreviewComponrnt.tsx +++ b/src/components/editor/PreviewComponrnt.tsx @@ -131,7 +131,7 @@ const PreviewComponent: React.FC = ({ {new Date().toLocaleDateString()}
BY. {authorName}

-
+
{!isPremium ? ( <>
diff --git a/src/components/editor/common/extractPaywallData.ts b/src/components/editor/common/extractPaywallData.ts index d18ff43..6392dd6 100644 --- a/src/components/editor/common/extractPaywallData.ts +++ b/src/components/editor/common/extractPaywallData.ts @@ -107,8 +107,20 @@ const extractPaywallData = (editor: Editor): PaywallData => { paywallDown = convertToHTML(content.slice(index + 1)); } - if (!imageLink && node.type === 'photo' && node.attrs?.src) { - imageLink = node.attrs.src; + if (!imageLink) { + if (node.type === 'photo' && node.attrs?.src) { + imageLink = node.attrs.src; + } else if ( + (node.type === 'photoGroup' || node.type === 'photoStrip') && + node.content + ) { + const firstImgNode = node.content.find( + (childNode) => childNode.type === 'image', + ); + if (firstImgNode && firstImgNode.attrs?.src) { + imageLink = firstImgNode.attrs.src; + } + } } });