Skip to content

Commit

Permalink
Merge pull request #4 from vinayakjaas/pdf_rendering_backend
Browse files Browse the repository at this point in the history
Implement server-side code for PDFDatabaseRenderer #1
  • Loading branch information
rks-031 authored Jun 29, 2024
2 parents 659203d + d47315e commit e5ec948
Show file tree
Hide file tree
Showing 12 changed files with 2,794 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/.gitignore
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*
62 changes: 62 additions & 0 deletions Pdf_Library/PDFDatabaseRenderer/backend-pdfrender/app.js
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit e5ec948

Please sign in to comment.