-
Notifications
You must be signed in to change notification settings - Fork 20
Feat/add sticker support clean #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anshika-guleria
wants to merge
6
commits into
CodePlaygroundHub:main
Choose a base branch
from
anshika-guleria:feat/add-sticker-support-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce4f1de
feat/added stickers using svg support
anshika-guleria b565872
fix: resolve sticker routes import and pass backend CI
anshika-guleria 1c5ffbb
Merge branch 'main' into feat/add-sticker-support-clean
anshika-guleria 2608010
fix: add missing SVG sticker assets and image load handling
anshika-guleria 7a43737
revert: remove unrelated dev OTP bypass from auth controller
anshika-guleria 251cf0f
fix: validate stickerUrl against registered sticker packs
anshika-guleria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we validate stickerUrl against the available sticker packs before saving/sending it? Right now it looks like an arbitrary URL could be stored as a favorite/recent sticker. |
This file contains hidden or 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,188 @@ | ||
| import User from "../models/user.model.js"; | ||
|
|
||
| // Built-in sticker packs definition (also served via API for dynamic pack extensions) | ||
| export const BUILTIN_STICKER_PACKS = [ | ||
| { | ||
| id: "reactions", | ||
| name: "Reactions", | ||
| icon: "😂", | ||
| category: "Emotions", | ||
| stickers: [ | ||
| { id: "mindblown", name: "Mind Blown", url: "/stickers/reactions/mindblown.svg", tags: ["mindblown", "shock", "wow", "explode", "omg"] }, | ||
| { id: "laughing", name: "Laughing", url: "/stickers/reactions/laughing.svg", tags: ["laugh", "lol", "haha", "rofl", "joy"] }, | ||
| { id: "crying", name: "Crying", url: "/stickers/reactions/crying.svg", tags: ["cry", "sad", "tears", "sob", "upset"] }, | ||
| { id: "party", name: "Party Time", url: "/stickers/reactions/party.svg", tags: ["party", "celebrate", "confetti", "yay", "cheers"] }, | ||
| { id: "cool", name: "Cool Sunglasses", url: "/stickers/reactions/cool.svg", tags: ["cool", "sunglasses", "chill", "boss", "swag"] }, | ||
| { id: "heart_eyes", name: "Heart Eyes", url: "/stickers/reactions/heart_eyes.svg", tags: ["love", "heart", "eyes", "crush", "cute"] }, | ||
| { id: "fire", name: "On Fire", url: "/stickers/reactions/fire.svg", tags: ["fire", "lit", "hot", "flame", "awesome"] }, | ||
| { id: "facepalm", name: "Facepalm", url: "/stickers/reactions/facepalm.svg", tags: ["facepalm", "smh", "disappointed", "duh", "oops"] }, | ||
| { id: "thinking", name: "Thinking", url: "/stickers/reactions/thinking.svg", tags: ["think", "hmm", "ponder", "wonder", "curious"] }, | ||
| { id: "shocked", name: "Shocked", url: "/stickers/reactions/shocked.svg", tags: ["shock", "gasp", "scared", "fear", "omg"] }, | ||
| { id: "angry", name: "Angry", url: "/stickers/reactions/angry.svg", tags: ["angry", "mad", "rage", "furious", "annoyed"] }, | ||
| { id: "angel", name: "Innocent Angel", url: "/stickers/reactions/angel.svg", tags: ["angel", "innocent", "good", "halo", "pure"] }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "pepe_memes", | ||
| name: "Pepe & Memes", | ||
| icon: "🐸", | ||
| category: "Memes", | ||
| stickers: [ | ||
| { id: "pepe_happy", name: "Pepe Happy", url: "/stickers/memes/pepe_happy.svg", tags: ["pepe", "happy", "smile", "feelsgood", "frog"] }, | ||
| { id: "pepe_sad", name: "Pepe Sad", url: "/stickers/memes/pepe_sad.svg", tags: ["pepe", "sad", "cry", "feelsbadman", "rain"] }, | ||
| { id: "pepe_hype", name: "Pepe Hype", url: "/stickers/memes/pepe_hype.svg", tags: ["pepe", "hype", "party", "dance", "energy"] }, | ||
| { id: "pepe_smart", name: "Big Brain Pepe", url: "/stickers/memes/pepe_smart.svg", tags: ["pepe", "brain", "smart", "genius", "iq"] }, | ||
| { id: "doge_wow", name: "Doge Wow", url: "/stickers/memes/doge_wow.svg", tags: ["doge", "wow", "shiba", "dog", "meme"] }, | ||
| { id: "score_100", name: "100 Percent", url: "/stickers/memes/score_100.svg", tags: ["100", "score", "perfect", "facts", "real"] }, | ||
| { id: "gg_wp", name: "GG Well Played", url: "/stickers/memes/gg_wp.svg", tags: ["gg", "game", "win", "gamer", "wp"] }, | ||
| { id: "stonks", name: "Stonks Up", url: "/stickers/memes/stonks.svg", tags: ["stonks", "profit", "money", "up", "crypto"] }, | ||
| { id: "popcat", name: "Pop Cat", url: "/stickers/memes/popcat.svg", tags: ["popcat", "cat", "mouth", "pop", "meme"] }, | ||
| { id: "bruh", name: "Bruh Moment", url: "/stickers/memes/bruh.svg", tags: ["bruh", "moment", "what", "bro", "meme"] }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "cute_animals", | ||
| name: "Cute Animals", | ||
| icon: "🐱", | ||
| category: "Animals", | ||
| stickers: [ | ||
| { id: "cat_heart", name: "Cat Love", url: "/stickers/animals/cat_heart.svg", tags: ["cat", "love", "heart", "kitty", "purr"] }, | ||
| { id: "cat_laptop", name: "Coder Cat", url: "/stickers/animals/cat_laptop.svg", tags: ["cat", "laptop", "code", "work", "busy"] }, | ||
| { id: "dog_happy", name: "Happy Pup", url: "/stickers/animals/dog_happy.svg", tags: ["dog", "pup", "wag", "happy", "cute"] }, | ||
| { id: "fox_sleeping", name: "Sleepy Fox", url: "/stickers/animals/fox_sleeping.svg", tags: ["fox", "sleep", "rest", "night", "bed"] }, | ||
| { id: "bear_hug", name: "Bear Hug", url: "/stickers/animals/bear_hug.svg", tags: ["bear", "hug", "love", "cuddle", "friend"] }, | ||
| { id: "bunny_cheer", name: "Cheering Bunny", url: "/stickers/animals/bunny_cheer.svg", tags: ["bunny", "rabbit", "hop", "cheer", "jump"] }, | ||
| { id: "panda_bamboo", name: "Panda Munch", url: "/stickers/animals/panda_bamboo.svg", tags: ["panda", "eat", "food", "cute", "bamboo"] }, | ||
| { id: "penguin_waddle", name: "Waddling Penguin", url: "/stickers/animals/penguin_waddle.svg", tags: ["penguin", "walk", "cold", "cute", "bird"] }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "anime_chibi", | ||
| name: "Anime & Chibi", | ||
| icon: "✨", | ||
| category: "Anime", | ||
| stickers: [ | ||
| { id: "chibi_sparkle", name: "Sparkle Eyes", url: "/stickers/anime/chibi_sparkle.svg", tags: ["anime", "sparkle", "eyes", "star", "chibi"] }, | ||
| { id: "chibi_rage", name: "Chibi Rage", url: "/stickers/anime/chibi_rage.svg", tags: ["anime", "rage", "anger", "flame", "chibi"] }, | ||
| { id: "chibi_sweat", name: "Nervous Sweat", url: "/stickers/anime/chibi_sweat.svg", tags: ["anime", "nervous", "sweat", "awkward", "oops"] }, | ||
| { id: "chibi_blush", name: "Kawaii Blush", url: "/stickers/anime/chibi_blush.svg", tags: ["anime", "blush", "kawaii", "shy", "cute"] }, | ||
| { id: "chibi_peace", name: "Peace Sign", url: "/stickers/anime/chibi_peace.svg", tags: ["anime", "peace", "victory", "pose", "v"] }, | ||
| { id: "chibi_sleepy", name: "Sleepy Chibi", url: "/stickers/anime/chibi_sleepy.svg", tags: ["anime", "sleep", "zzz", "tired", "chibi"] }, | ||
| { id: "chibi_gaming", name: "Pro Gamer", url: "/stickers/anime/chibi_gaming.svg", tags: ["anime", "game", "controller", "gamer", "play"] }, | ||
| { id: "chibi_coffee", name: "Coffee Time", url: "/stickers/anime/chibi_coffee.svg", tags: ["anime", "coffee", "morning", "tea", "drink"] }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "vibes_gestures", | ||
| name: "Vibes & Gestures", | ||
| icon: "✌️", | ||
| category: "Gestures", | ||
| stickers: [ | ||
| { id: "thumbs_up", name: "Thumbs Up", url: "/stickers/vibes/thumbs_up.svg", tags: ["thumbsup", "ok", "yes", "like", "agree"] }, | ||
| { id: "heart_hands", name: "Heart Hands", url: "/stickers/vibes/heart_hands.svg", tags: ["heart", "hands", "love", "kpop", "care"] }, | ||
| { id: "high_five", name: "High Five", url: "/stickers/vibes/high_five.svg", tags: ["highfive", "team", "celebrate", "slap", "hands"] }, | ||
| { id: "peace_out", name: "Peace Sign", url: "/stickers/vibes/peace_out.svg", tags: ["peace", "vibe", "bye", "chill", "cool"] }, | ||
| { id: "clapping", name: "Clapping", url: "/stickers/vibes/clapping.svg", tags: ["clap", "applause", "bravo", "great", "cheer"] }, | ||
| { id: "rocket_blast", name: "Rocket Launch", url: "/stickers/vibes/rocket_blast.svg", tags: ["rocket", "launch", "moon", "speed", "fast"] }, | ||
| { id: "sparkle_star", name: "Super Star", url: "/stickers/vibes/sparkle_star.svg", tags: ["star", "sparkle", "gold", "shine", "winner"] }, | ||
| { id: "coffee_mug", name: "Fresh Coffee", url: "/stickers/vibes/coffee_mug.svg", tags: ["coffee", "cup", "morning", "fuel", "tea"] }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const ALL_VALID_STICKER_URLS = new Set( | ||
| BUILTIN_STICKER_PACKS.flatMap((pack) => pack.stickers.map((s) => s.url)) | ||
| ); | ||
|
|
||
| // GET /api/stickers/packs | ||
| export const getStickerPacks = async (req, res) => { | ||
| try { | ||
| res.status(200).json({ packs: BUILTIN_STICKER_PACKS }); | ||
| } catch (error) { | ||
| console.error("getStickerPacks error:", error); | ||
| res.status(500).json({ message: "Failed to load sticker packs" }); | ||
| } | ||
| }; | ||
|
|
||
| // GET /api/stickers/user-data | ||
| export const getUserStickerData = async (req, res) => { | ||
| try { | ||
| const user = await User.findById(req.user._id).select("favoriteStickers recentStickers"); | ||
| if (!user) { | ||
| return res.status(404).json({ message: "User not found" }); | ||
| } | ||
|
|
||
| res.status(200).json({ | ||
| favoriteStickers: user.favoriteStickers || [], | ||
| recentStickers: user.recentStickers || [], | ||
| }); | ||
| } catch (error) { | ||
| console.error("getUserStickerData error:", error); | ||
| res.status(500).json({ message: "Failed to load user sticker data" }); | ||
| } | ||
| }; | ||
|
|
||
| // POST /api/stickers/favorites/toggle | ||
| export const toggleFavoriteSticker = async (req, res) => { | ||
| try { | ||
| const { stickerUrl } = req.body; | ||
| if (!stickerUrl || typeof stickerUrl !== "string" || !ALL_VALID_STICKER_URLS.has(stickerUrl)) { | ||
| return res.status(400).json({ message: "Valid stickerUrl from official sticker packs is required" }); | ||
| } | ||
|
|
||
| const user = await User.findById(req.user._id); | ||
| if (!user) { | ||
| return res.status(404).json({ message: "User not found" }); | ||
| } | ||
|
|
||
| const currentFavorites = user.favoriteStickers || []; | ||
| const exists = currentFavorites.includes(stickerUrl); | ||
|
|
||
| let updatedFavorites; | ||
| if (exists) { | ||
| updatedFavorites = currentFavorites.filter((url) => url !== stickerUrl); | ||
| } else { | ||
| updatedFavorites = [stickerUrl, ...currentFavorites]; | ||
| } | ||
|
|
||
| user.favoriteStickers = updatedFavorites; | ||
| await user.save(); | ||
|
|
||
| res.status(200).json({ | ||
| favoriteStickers: user.favoriteStickers, | ||
| isFavorited: !exists, | ||
| }); | ||
| } catch (error) { | ||
| console.error("toggleFavoriteSticker error:", error); | ||
| res.status(500).json({ message: "Failed to toggle favorite sticker" }); | ||
| } | ||
| }; | ||
|
|
||
| // POST /api/stickers/recents | ||
| export const addRecentSticker = async (req, res) => { | ||
| try { | ||
| const { stickerUrl } = req.body; | ||
| if (!stickerUrl || typeof stickerUrl !== "string" || !ALL_VALID_STICKER_URLS.has(stickerUrl)) { | ||
| return res.status(400).json({ message: "Valid stickerUrl from official sticker packs is required" }); | ||
| } | ||
|
|
||
| const user = await User.findById(req.user._id); | ||
| if (!user) { | ||
| return res.status(404).json({ message: "User not found" }); | ||
| } | ||
|
|
||
| const currentRecents = user.recentStickers || []; | ||
| // Place at front, deduplicate, and limit to max 30 items | ||
| const filtered = currentRecents.filter((url) => url !== stickerUrl); | ||
| user.recentStickers = [stickerUrl, ...filtered].slice(0, 30); | ||
|
|
||
| await user.save(); | ||
|
|
||
| res.status(200).json({ | ||
| recentStickers: user.recentStickers, | ||
| }); | ||
| } catch (error) { | ||
| console.error("addRecentSticker error:", error); | ||
| res.status(500).json({ message: "Failed to add recent sticker" }); | ||
| } | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is the OTP/auth logic being changed in this PR? These changes don't seem related to #119. Please revert the unrelated auth changes so this PR stays scoped to sticker support.