Uname: 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
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.142.54.83
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : videoSong.js
const express = require("express")
const VideoSong = require('../schema/VideoSong')
const Album = require("../schema/Album")
const router = express.Router()

router.post('/new', async (req, res) => {
    try {
        const { thumbnail, title, album, artist, videoId, tags } = req.body
        var videoSong
        if (album) {
            videoSong = await VideoSong.create({ thumbnail, title, album, artist, videoId, tags })
        } else {
            videoSong = await VideoSong.create({ thumbnail, title, artist, tags, videoId })
        }
        if (album) {
            const albumObj = await Album.findById(album)
            if (!albumObj.songs) {
                albumObj.songs = [videoSong._id]
            } else {
                albumObj.songs.push(videoSong._id)
            }
            await albumObj.save()
        }
        if (videoSong) {
            return res.json({
                success: true,
                videoSong
            })
        }
        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 videoSong = await VideoSong.findById(id)
        if (videoSong) {
            videoSong.thumbnail = thumbnail
            videoSong.title = title
            videoSong.album = album
            videoSong.artist = artist
            videoSong.videoId = videoId
            videoSong.tags = tags
            await videoSong.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 videoSongs = await VideoSong.find().populate('artist').populate('album')
        // .populate('comment').populate('likes')
        if (videoSongs) {
            return res.json({
                success: true,
                videoSongs
            })
        }
        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 videoSongs = await VideoSong.find({artist}).populate('artist').populate('album')
        // .populate('comment').populate('likes')
        if (videoSongs) {
            return res.json({
                success: true,
                videoSongs
            })
        }
        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 videoSong = await VideoSong.findByIdAndDelete(id)
        console.log('videoSong', videoSong)
        if (videoSong) {
            return res.json({
                success: true
            })
        }
        return res.json({
            success: false,
            error: 'Something Went Wrong'
        })
    } catch (error) {
        return res.json({
            success: false,
            error: error.message
        })
    }
})

module.exports = router
© 2025 GrazzMean-Shell