/
createSong.js
58 lines (46 loc) · 1.39 KB
/
createSong.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// // createSong.js
// import Song from '../models/Song'; // Adjust the import path as needed
// async function createNewSong() {
// const newSongData = {
// title: 'Song Title',
// artist: 'Artist Name',
// lyrics: 'These are the lyrics...',
// };
// const newSong = new Song(newSongData);
// try {
// await newSong.save(); // Save the document to the database
// console.log('Song saved successfully.');
// } catch (error) {
// console.error('Error saving song:', error);
// }
// }
// export default createNewSong;
// createSong.js
import Song from './models/song'; // Import your Mongoose model
async function createNewSong(songData) {
// Extract data from the songData object
const { title, artist, lyrics, lyricsK,
lyricsE, thumbnail } = songData;
// Parse lyrics and perform any other necessary operations
// const parsedLyrics = await parseLyrics(lyrics); // Replace with your parsing logic
// Create a new song document
const newSong = new Song({
title,
artist,
// lyrics: parsedLyrics, // Use the parsed lyrics
lyrics,
lyricsK,
lyricsE,
thumbnail
});
try {
console.log(newSong)
// Save the new song to the database
await newSong.save();
console.log('Song saved successfully.');
} catch (error) {
console.error('Error saving song:', error);
throw error;
}
}
export default createNewSong;