shell bypass 403
const express = require("express")
const Artist = require("../schema/Artist")
const Music = require("../schema/Music")
const VideoSong = require("../schema/VideoSong")
const router = express.Router()
router.post('/new', async (req, res) => {
try {
const { firstName, lastName, avatar, tags } = req.body
const artist = await Artist.create({ firstName, lastName, avatar, tags })
console.log('artist', artist)
if (artist) {
return res.json({
success: true,
artist
})
}
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, firstName, lastName, avatar, tags } = req.body
const artist = await Artist.findById(id)
if (artist) {
artist.firstName = firstName
artist.lastName = lastName
artist.avatar = avatar
artist.tags = tags
await artist.save()
return res.json({
success: true,
artist
})
}
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 artists = await Artist.find()
console.log('artists', artists)
if (artists) {
return res.json({
success: true,
artists
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
return res.json({
success: false,
error: error.message
})
}
})
router.post('/fetch-video-artist', async (req, res) => {
try {
// const { page } = req.query
const videoSongArtist = await VideoSong.find().select('artist');
const videoArtistId = videoSongArtist.map(item => item.artist.toString())
console.log('videoArtistId', videoArtistId)
const artists = await Artist.find({_id: videoArtistId})
if (artists) {
return res.json({
success: true,
artists
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
return res.json({
success: false,
error: error.message
})
}
})
router.post('/:id', async (req, res) => {
try {
// const { page } = req.query
const { id } = req.params
const artist = await Artist.findById(id)
if (artist) {
const music = await Music.find({ artist: artist._id }).populate('artist').populate('album')
const videoSongs = await VideoSong.find({ artist: artist._id }).populate('artist').populate('album')
return res.json({
success: true,
artist,
music,
videoSongs
})
}
// const artists = await Artist.find()
// console.log('artists', artists)
// if (artists) {
// return res.json({
// success: true,
// artists
// })
// }
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 artists = await Artist.findByIdAndDelete(id)
console.log('artists', artists)
if (artists) {
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" } },
{ tags: { $regex: searchQuery, $options: "i" } },
],
})
console.log('artists', artists)
if (artists) {
return res.json({
success: true,
artists
})
}
return res.json({
success: false,
error: 'Something Went Wrong'
})
} catch (error) {
return res.json({
success: false,
error: error.message
})
}
})
module.exports = router