-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from vinayakjaas/pdf_rendering_backend
Implement server-side code for PDFDatabaseRenderer #1
- Loading branch information
Showing
12 changed files
with
2,794 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/.gitignore
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,21 @@ | ||
s | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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,62 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
const mongoose = require("mongoose"); | ||
app.use(express.json()); | ||
const cors = require("cors"); | ||
app.use(cors()); | ||
app.use("/files", express.static("files")); | ||
|
||
const mongoUrl = "mongodb+srv://vinayakrajqaz:[email protected]/?retryWrites=true&w=majority&appName=Cluster0"; | ||
|
||
mongoose | ||
.connect(mongoUrl) | ||
.then(() => { | ||
console.log("Connected to database"); | ||
}) | ||
.catch((e) => console.log(e)); | ||
|
||
const multer = require("multer"); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
cb(null, "./files"); | ||
}, | ||
filename: function (req, file, cb) { | ||
const uniqueSuffix = Date.now(); | ||
cb(null, uniqueSuffix + file.originalname); | ||
}, | ||
}); | ||
|
||
require("./pdfDetails"); | ||
const PdfSchema = mongoose.model("PdfDetails"); | ||
const upload = multer({ storage: storage }); | ||
|
||
app.post("/upload-files", upload.single("file"), async (req, res) => { | ||
console.log(req.file); | ||
const title = req.body.title; | ||
const fileName = req.file.filename; | ||
try { | ||
await PdfSchema.create({ title: title, pdf: fileName }); | ||
res.send({ status: "ok" }); | ||
} catch (error) { | ||
res.json({ status: error }); | ||
} | ||
}); | ||
|
||
app.get("/get-files", async (req, res) => { | ||
try { | ||
PdfSchema.find({}).then((data) => { | ||
res.send({ status: "ok", data: data }); | ||
}); | ||
} catch (error) { | ||
res.json({ status: error }); | ||
} | ||
}); | ||
|
||
app.get("/", async (req, res) => { | ||
res.send("Success!!!!!!"); | ||
}); | ||
|
||
app.listen(5000, () => { | ||
console.log("Server Started"); | ||
}); |
Binary file added
BIN
+15.2 KB
Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/files/1718425438237Agent_Question.pdf
Binary file not shown.
Binary file added
BIN
+1.64 MB
Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/files/1718630574001Vinayak_Passport.pdf
Binary file not shown.
Binary file added
BIN
+1.64 MB
Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/files/1718630603963pdf2.pdf
Binary file not shown.
Binary file added
BIN
+1.64 MB
Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/files/1718631262925Vinayak_Passport.pdf
Binary file not shown.
Oops, something went wrong.