-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 시그니처 정리 * chore: satori version update * refactor: 불필요 로직 삭제 * refactor: 불필요 로직 삭제 * feat: image response api route 생성 * chore: api extension 설정 * feat: api route 이용해서 이미지 사용 * feat: dna 이미지 다운로드 모달 lazy 임포트 * refactor: 미사용 라이브러리 및 유틸 삭제 * chore: 주석 추가
- Loading branch information
Showing
30 changed files
with
189 additions
and
812 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-571 KB
.yarn/cache/@shuding-opentype.js-npm-1.4.0-beta.0-498d62cde8-af3478c40c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-5.24 KB
.yarn/cache/css-background-parser-npm-0.1.0-d1e94221f7-cf53bef8d5.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-33.6 KB
.yarn/cache/css-to-react-native-npm-3.2.0-46e31a25e3-263be65e80.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-3.61 KB
.yarn/cache/string.prototype.codepointat-npm-0.2.1-82003deaf5-bafa15844d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
File renamed without changes.
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,112 @@ | ||
/* eslint-disable unicorn/filename-case */ | ||
import { ImageResponse, type NextRequest } from 'next/server'; | ||
|
||
import { type Group } from '~/utils/resultLogic'; | ||
|
||
type ImageOptions = ConstructorParameters<typeof ImageResponse>[1]; | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
}; | ||
|
||
export default async function handler(req: NextRequest) { | ||
try { | ||
const { searchParams } = new URL(req.url); | ||
const group = searchParams.get('group'); | ||
const nickname = searchParams.get('nickname'); | ||
const position = searchParams.get('position'); | ||
|
||
const notoSansScFont700 = await fetchFont('Noto+Sans+KR', 700); | ||
if (!notoSansScFont700) { | ||
throw new Error('Failed to fetch font'); | ||
} | ||
|
||
// TODO: 이미지 크기 및 위치 조절 | ||
const imageOptions: ImageOptions = { | ||
width: 375, | ||
height: 666, | ||
fonts: [ | ||
{ | ||
name: 'Noto Sans KR', | ||
data: notoSansScFont700, | ||
weight: 700, | ||
style: 'normal', | ||
}, | ||
], | ||
}; | ||
|
||
return new ImageResponse( | ||
( | ||
<div | ||
style={{ | ||
position: 'relative', | ||
display: 'flex', | ||
}} | ||
> | ||
{/* eslint-disable-next-line @next/next/no-img-element */} | ||
<img | ||
style={{ | ||
width: '375px', | ||
height: '666px', | ||
}} | ||
src={HOISTING_IMAGE_BY_GROUP[group as Group]} | ||
alt={'dna_' + group} | ||
width={375} | ||
height={666} | ||
/> | ||
<span | ||
style={{ | ||
position: 'absolute', | ||
top: '112px', | ||
fontWeight: 700, | ||
fontSize: '20px', | ||
color: '#fff', | ||
left: '70px', | ||
textShadow: '1px 1px 2px #849BDA30', | ||
}} | ||
> | ||
{nickname} | ||
</span> | ||
<span | ||
style={{ | ||
position: 'absolute', | ||
top: '407px', | ||
left: '71px', | ||
color: '#17171B', | ||
fontWeight: 700, | ||
fontSize: '16.8px', | ||
}} | ||
> | ||
{position} | ||
</span> | ||
</div> | ||
), | ||
imageOptions, | ||
); | ||
} catch (error: unknown) { | ||
return new Response('Failed to generate image', { status: 500 }); | ||
} | ||
} | ||
|
||
async function fetchFont(fontFamily = 'Noto+Sans+KR', fontWeight = 700): Promise<ArrayBuffer | null> { | ||
const fontUrl = `https://fonts.googleapis.com/css2?family=${fontFamily}:wght@${fontWeight}`; | ||
|
||
const css = await (await fetch(fontUrl)).text(); | ||
|
||
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/); | ||
|
||
if (!resource) return null; | ||
|
||
const res = await fetch(resource[1]); | ||
|
||
return res.arrayBuffer(); | ||
} | ||
|
||
const HOISTING_IMAGE_BY_GROUP: Record<Group, string> = { | ||
A: `https://github.com/depromeet/na-lab-client/assets/49177223/0b224b08-3858-4305-8323-1a6082dbb4f7`, | ||
B: `https://github.com/depromeet/na-lab-client/assets/49177223/fec4951a-270f-40e8-8520-43eecb89416f`, | ||
C: `https://github.com/depromeet/na-lab-client/assets/49177223/faefd0ee-7048-4578-8ec5-b70713e6efd9`, | ||
D: `https://github.com/depromeet/na-lab-client/assets/49177223/4dbecfeb-5492-4c6b-b4a7-cd933cd5621e`, | ||
E: `https://github.com/depromeet/na-lab-client/assets/49177223/1eb9e7e4-801d-475a-8037-aa35a2776441`, | ||
F: `https://github.com/depromeet/na-lab-client/assets/49177223/8667e31c-9722-490b-9def-3b952d115275`, | ||
}; |
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,62 @@ | ||
/* eslint-disable unicorn/filename-case */ | ||
import { css } from '@emotion/react'; | ||
import { m } from 'framer-motion'; | ||
|
||
import Modal from '~/components/modal/Modal'; | ||
import { HEAD_2_BOLD } from '~/styles/typo'; | ||
|
||
const DNAImageDownloadModal = ({ | ||
imageSrc, | ||
onClose, | ||
isShowing, | ||
}: { | ||
imageSrc: string; | ||
onClose: () => void; | ||
isShowing: boolean; | ||
}) => { | ||
return ( | ||
<Modal isShowing={isShowing}> | ||
<Modal.Header onBackClick={onClose} overrideCss={imageDownloadModalHeaderCss} /> | ||
<m.div | ||
css={imageDownloadModalCss} | ||
variants={{ | ||
initial: { opacity: 0 }, | ||
animate: { opacity: 1 }, | ||
exit: { opacity: 0 }, | ||
}} | ||
initial="initial" | ||
animate="animate" | ||
exit="exit" | ||
> | ||
<h1>꾹 눌러서 이미지를 저장하세요</h1> | ||
|
||
<img src={imageSrc} alt="dna" /> | ||
</m.div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DNAImageDownloadModal; | ||
|
||
const imageDownloadModalHeaderCss = css` | ||
background-color: transparent; | ||
border-bottom: none; | ||
`; | ||
|
||
const imageDownloadModalCss = css` | ||
overflow-y: auto; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
align-items: center; | ||
h1 { | ||
${HEAD_2_BOLD}; | ||
user-select: none; | ||
} | ||
img { | ||
user-select: none; | ||
width: 80%; | ||
} | ||
`; |
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
Oops, something went wrong.