G

Untitled

public
Guest Jan 25, 2025 Never 18
Clone
Plaintext paste1.txt 48 lines (39 loc) | 1.32 KB
1
const express = require("express");
2
const multer = require("multer");
3
const path = require("path");
4
const fs = require("fs");
5
6
const app = express();
7
const PORT = 5000;
8
9
const storage = multer.diskStorage({
10
destination: (req, file, cb) => {
11
const uploadPath = path.join(__dirname, "uploads");
12
if (!fs.existsSync(uploadPath)) {
13
fs.mkdirSync(uploadPath, { recursive: true });
14
}
15
cb(null, uploadPath);
16
},
17
filename: (req, file, cb) => {
18
const uniqueSuffix = `${Date.now()}-${Math.round(Math.random() * 1e9)}`;
19
cb(null, `${uniqueSuffix}-${file.originalname}`);
20
},
21
});
22
23
const upload = multer({ storage });
24
25
app.use(express.json());
26
27
app.post("/api/submit-music", upload.single("musicFile"), (req, res) => {
28
const { artistName, submissionType, paymentType, musicLink } = req.body;
29
const musicFile = req.file;
30
31
if (!artistName || !submissionType || !paymentType || !musicLink || !musicFile) {
32
return res.status(400).json({ error: "All fields are required." });
33
}
34
35
console.log({
36
artistName,
37
submissionType,
38
paymentType,
39
musicLink,
40
musicFilePath: musicFile.path,
41
});
42
43
res.status(200).json({ message: "Music submitted successfully!" });
44
});
45
46
app.listen(PORT, () => {
47
console.log(`Server is running on http://localhost:${PORT}`);
48
});