shell bypass 403
const express = require("express")
const Album = require("../schema/Album")
const Artist = require("../schema/Artist")
const Music = require("../schema/Music")
const router = express.Router()
router.post('/new', async (req, res) => {
try {
const { thumbnail, title, artist, description, tags } = req.body
const album = await Album.create({ thumbnail, title, artist, description, tags })
if (album) {
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('/update', async (req, res) => {
try {
const { id, thumbnail, title, artist, description, tags } = req.body
const album = await Album.findById(id)
if (album) {
album.thumbnail = thumbnail
album.title = title
album.artist = artist
album.description = description
album.tags = tags
await album.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 albums = await Album.find().populate('artist')
console.log('albums', albums)
if (albums) {
return res.json({
success: true,
albums
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
return res.json({
success: false,
error: error.message
})
}
})
router.post('/fetchbyartist', async (req, res) => {
try {
const { artist } = req.body
console.log('artist', artist)
const albums = await Album.find({ artist }).populate('artist')
console.log('albums', albums)
if (albums) {
return res.json({
success: true,
albums
})
}
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 album = await Album.findByIdAndDelete(id)
console.log('album', album)
if (album) {
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 artists = await Artist.find({
$or: [
{ firstName: { $regex: searchQuery, $options: "i" } },
{ lastName: { $regex: searchQuery, $options: "i" } },
]
})
const artistsIds = artists.map((artist) => artist._id)
const albums = await Album.find({
$or: [
{ thumbnail: { $regex: searchQuery, $options: "i" } },
{ title: { $regex: searchQuery, $options: "i" } },
// { artist: { $regex: searchQuery, $options: "i" } },
{ description: { $regex: searchQuery, $options: "i" } },
{ tags: { $regex: searchQuery, $options: "i" } },
{ artist: { $in: artistsIds } },
],
}).populate('artist');
console.log('albums', albums)
if (albums) {
return res.json({
success: true,
albums
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
console.log('error', error)
return res.json({
success: false,
error: error.message
})
}
})
router.post('/:id', async (req, res) => {
try {
const { id } = req.params
// const { page } = req.query
const album = await Album.findById(id).populate('artist')
console.log('album', album)
if (album) {
const musics = await Music.find({ album: album._id }).populate('artist').populate('album')
return res.json({
success: true,
album,
musics
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
return res.json({
success: false,
error: error.message
})
}
})
module.exports = router