Server IP : 162.213.251.212 / Your IP : 18.217.246.20 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/allssztx/clarkesmusicservices.com/routes/ |
Upload File : |
const express = require("express") const Music = require('../schema/Music') const Album = require("../schema/Album") const router = express.Router() router.post('/new', async (req, res) => { try { const { thumbnail, title, album, releaseDate, artist, file, tags } = req.body var music if (album) { music = await Music.create({ thumbnail, title, album, releaseDate, artist, file, tags }) } else { music = await Music.create({ thumbnail, title, releaseDate, artist, file, tags }) } if (album) { const albumObj = await Album.findById(album) if (!albumObj.songs) { albumObj.songs = [music._id] } else { albumObj.songs.push(music._id) } await albumObj.save() } if (music) { return res.json({ success: true, music }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) router.post('/update', async (req, res) => { try { const { id, thumbnail, title, album, releaseDate, artist, file, tags } = req.body const music = await Music.findById(id) if (music) { music.thumbnail = thumbnail music.title = title music.album = album music.releaseDate = releaseDate music.artist = artist music.file = file music.tags = tags await music.save() return res.json({ success: true, album }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) router.post('/fetch', async (req, res) => { try { // const { page } = req.query const musics = await Music.find().populate('artist').populate('album') // .populate('comment').populate('likes') if (musics) { return res.json({ success: true, musics }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) router.post('/delete', async (req, res) => { try { const { id } = req.body const music = await Music.findByIdAndDelete(id) console.log('music', music) if (music) { return res.json({ success: true }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) router.post('/search', async (req, res) => { try { const { searchQuery } = req.body const musics = await Music.find({ $or: [ { title: { $regex: searchQuery, $options: "i" } }, ] }) console.log('musics', musics) if (musics) { return res.json({ success: true, musics }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { console.log('error', error) return res.json({ success: false, error: error.message }) } }) module.exports = router