30 lines
833 B
JavaScript
30 lines
833 B
JavaScript
const express = require("express");
|
|
const multer = require("multer");
|
|
const path = require("path");
|
|
|
|
const app = express();
|
|
|
|
// Set up multer for handling file uploads
|
|
const storage = multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
const nip05Username = req.query.nip05Username; // Extract nip05Username from query params
|
|
const uploadPath = path.join(__dirname, ".nip05Storage", nip05Username);
|
|
cb(null, uploadPath);
|
|
},
|
|
filename: function (req, file, cb) {
|
|
cb(null, file.originalname);
|
|
},
|
|
});
|
|
|
|
const upload = multer({ storage: storage });
|
|
|
|
app.listen(3000, () => {
|
|
console.log("Server is running on port 3000");
|
|
});
|
|
|
|
app.post("/upload", upload.single("file"), (req, res) => {
|
|
// The file has been uploaded to the destination folder
|
|
// Respond with success status
|
|
res.sendStatus(200);
|
|
});
|