-
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.
* resvg-js 추가 * png api 추가 * png api에서 api prefix 제거
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
import type { Theme } from 'server/theme/types'; | ||
|
||
import createMoonFuncMap from 'server/theme'; | ||
import { isTheme } from 'server/utils/type'; | ||
import { renderPng } from 'server/utils/png'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse, | ||
) { | ||
const { date, size = '100', theme = 'basic', rotate = '0' } = req.query; | ||
|
||
if (!isTheme(theme)) { | ||
return res.status(200).end(''); | ||
} | ||
|
||
const createMoon = createMoonFuncMap[theme as Theme]; | ||
const moonSvg = await createMoon( | ||
date as string, | ||
size as string, | ||
rotate as string, | ||
); | ||
|
||
res.setHeader('Content-Type', 'image/png'); | ||
res.setHeader('Cache-Control', 's-maxage=3600, max-age=3600'); | ||
res.status(200).end(renderPng(moonSvg)); | ||
} |
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,15 @@ | ||
import { Resvg } from '@resvg/resvg-js'; | ||
|
||
const opts = { | ||
fitTo: { | ||
mode: 'width', | ||
value: 100, | ||
}, | ||
} as const; | ||
|
||
export const renderPng = (moonSvg: string) => { | ||
const resvg = new Resvg(moonSvg, opts); | ||
const pngData = resvg.render(); | ||
const pngBuffer = pngData.asPng(); | ||
return pngBuffer; | ||
}; |
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
e4f5d42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
monosvg – ./
monosvg-git-main-hmu332233.vercel.app
moon-svg.minung.dev
moon-phase.vercel.app
monosvg-hmu332233.vercel.app