aboutsummaryrefslogtreecommitdiffstats
path: root/pages/api/youtube/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'pages/api/youtube/search.js')
-rw-r--r--pages/api/youtube/search.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/pages/api/youtube/search.js b/pages/api/youtube/search.js
new file mode 100644
index 0000000..b17d008
--- /dev/null
+++ b/pages/api/youtube/search.js
@@ -0,0 +1,26 @@
+import withSession from 'hocs/withSession'
+import youtube from 'scrape-youtube'
+
+export default withSession(async (req, res) => {
+ switch (req.method) {
+ case 'POST':
+ try {
+ const user = req.session.get('user')
+ const { quote } = req.body
+
+ if (!user || !user?.isVerified || !quote) {
+ throw new Error('Something went wrong')
+ }
+
+ const video = await youtube.search(quote)
+
+ res.status(200).json(video)
+ } catch (error) {
+ res.status(400).json([])
+ }
+ break
+ default:
+ res.status(400).send()
+ break
+ }
+})