-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Saifullah-dev/feature/backend
Feature/backend
- Loading branch information
Showing
68 changed files
with
2,434 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${file}/server.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const mongoose = require("mongoose"); | ||
const dotenv = require("dotenv"); | ||
|
||
dotenv.config(); | ||
|
||
const connectDB = async () => { | ||
try { | ||
await mongoose.connect(process.env.MONGO_URI); | ||
console.log("MongoDB connected"); | ||
} catch (error) { | ||
console.error("MongoDB connection failed:", error.message); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
module.exports = connectDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const multer = require("multer"); | ||
const path = require("path"); | ||
const FileSystem = require("../models/FileSystem"); | ||
const fs = require("fs"); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: async (req, file, cb) => { | ||
let uploadPath = path.join(__dirname, "../uploads"); | ||
|
||
if (req.body.parentId) { | ||
try { | ||
const parentFolder = await FileSystem.findById(req.body.parentId); | ||
if (!parentFolder || !parentFolder.isDirectory) { | ||
return cb(new Error("Invalid parentId!"), false); | ||
} | ||
uploadPath = path.join(__dirname, "../uploads", parentFolder.path); | ||
} catch (error) { | ||
return cb(error, false); | ||
} | ||
} | ||
|
||
const fullFilePath = path.join(uploadPath, file.originalname); | ||
if (fs.existsSync(fullFilePath)) { | ||
return cb(new multer.MulterError("File already exists!", file), false); | ||
} | ||
|
||
cb(null, uploadPath); | ||
}, | ||
filename: (req, file, cb) => { | ||
cb(null, file.originalname); | ||
}, | ||
}); | ||
|
||
const upload = multer({ storage }); | ||
|
||
module.exports = upload; |
Oops, something went wrong.