-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new api for cover, added meta tags (#108)
* new api for cover, added meta tags * fixed redundant props * handled authenticated routes
- Loading branch information
1 parent
92dd296
commit 24bd78c
Showing
7 changed files
with
178 additions
and
57 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
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,70 @@ | ||
import { fetchSavedCards } from '@/api-helpers/persistance'; | ||
import { createCoverUsingVercel } from '@/api-helpers/vercel-cover-generator'; | ||
import { CardTypes } from '@/types/cards'; | ||
import { | ||
bcryptGen, | ||
extractFilenameWithoutExtension | ||
} from '@/utils/stringHelpers'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const fetchAndDownloadImageBuffer = async ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => { | ||
const [username, hash] = req.query.params as string[]; | ||
|
||
if (!username || !hash) { | ||
return res.status(400).json({ | ||
message: 'Invalid parameters, must pass valid username and hash.' | ||
}); | ||
} | ||
|
||
const generatedHash = bcryptGen(username); | ||
|
||
if (generatedHash !== hash) { | ||
return res.status(400).json({ | ||
message: 'Invalid parameters, must pass valid hash.' | ||
}); | ||
} | ||
const imageData = await fetchSavedCards(username); | ||
|
||
const images = imageData | ||
.sort((a, b) => { | ||
const indexA = priority.indexOf( | ||
extractFilenameWithoutExtension(a.fileName).toUpperCase() as CardTypes | ||
); | ||
const indexB = priority.indexOf( | ||
extractFilenameWithoutExtension(b.fileName).toUpperCase() as CardTypes | ||
); | ||
|
||
return indexA - indexB; | ||
}) | ||
.slice(0, 3) | ||
.map((image) => { | ||
const file = extractFilenameWithoutExtension(image.fileName); | ||
const uniqueHash = bcryptGen(username + file); | ||
const domain = process.env.NEXTAUTH_URL; | ||
return `${domain}/shared/${username}/${file}/${uniqueHash}`; | ||
}); | ||
|
||
const getCoverImage = await createCoverUsingVercel(username, images); | ||
res.setHeader('Content-Type', 'image/jpeg'); | ||
res.setHeader('Content-Length', getCoverImage.length); | ||
res.send(getCoverImage); | ||
}; | ||
|
||
export default fetchAndDownloadImageBuffer; | ||
|
||
const priority = [ | ||
CardTypes.YOUR_CONTRIBUTIONS, | ||
CardTypes.PR_REVIEWED_VS_AUTHORED, | ||
CardTypes.IT_TAKES_A_VILLAGE, | ||
CardTypes.TOP_REVIEWERS, | ||
CardTypes.CONTRIBUTION_STREAK, | ||
CardTypes.GUARDIAN_OF_PROD, | ||
CardTypes.ZEN_OR_NINJA, | ||
CardTypes.DAY_NIGHT_CYCLE, | ||
CardTypes.OSS_CONTRIBUTION, | ||
CardTypes.PRODUCTION_BREAKING, | ||
CardTypes.UNWRAPPED_INTRO | ||
]; |
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