merge with main
This commit is contained in:
parent
9149bba868
commit
9b7e8ab276
10 changed files with 434 additions and 54 deletions
|
|
@ -1,23 +1,44 @@
|
|||
const intructorRouter = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
const multer = require('multer');
|
||||
const FormData = require('form-data');
|
||||
|
||||
|
||||
const DB_ASSIGNMENT_SERVICE_URL =
|
||||
process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000";
|
||||
console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL);
|
||||
|
||||
// Use memory storage to keep file in RAM
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
|
||||
// This endpoint is for instructors to create a new assignment
|
||||
intructorRouter.post(
|
||||
"/create",
|
||||
// passport.authenticate("jwt", { session: false }),
|
||||
intructorRouter.post("/create",
|
||||
upload.single('file'),
|
||||
// passport.authenticate("jwt", { session: false }),
|
||||
async (req, res) => {
|
||||
try {
|
||||
|
||||
const file = req.file;
|
||||
const assignmentData = req.body;
|
||||
|
||||
if (!file) {
|
||||
return res.status(400).send('No file uploaded.');
|
||||
}
|
||||
|
||||
await axios.post('https://target-api.com/endpoint', {
|
||||
filename: file.originalname,
|
||||
mimetype: file.mimetype,
|
||||
content: file.buffer.toString('base64')
|
||||
}, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Creating a new assignment with data:", req.body);
|
||||
const response = await axios.post(
|
||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments`,
|
||||
req.body
|
||||
);
|
||||
const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body);
|
||||
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,49 @@
|
|||
const studentRouter = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
const bcrypt = require("bcrypt");
|
||||
require("dotenv").config();
|
||||
const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL;
|
||||
|
||||
studentRouter.post("/save", (req, res) => {
|
||||
|
||||
|
||||
studentRouter.post("/save", (req, res) => {});
|
||||
|
||||
studentRouter.post("/deploy", (req, res) => {});
|
||||
|
||||
studentRouter.post("/verify/", async (req, res) => {
|
||||
try {
|
||||
const assignmentId = req.body.id;
|
||||
const password = req.body.password;
|
||||
console.log(
|
||||
"Accessing assignment with ID:",
|
||||
assignmentId,
|
||||
"and password:",
|
||||
password
|
||||
);
|
||||
|
||||
console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`);
|
||||
const response = await axios.get(
|
||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
|
||||
);
|
||||
|
||||
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||
console.log("Password provided:", password);
|
||||
console.log("Password hash from database:", response.data.passwordhash);
|
||||
|
||||
const isPasswordValid = await bcrypt.compare(
|
||||
password,
|
||||
response.data.passwordhash
|
||||
);
|
||||
|
||||
if (!isPasswordValid || !response.data) {
|
||||
return res.status(401).json({ error: "Invalid id and password" });
|
||||
}
|
||||
|
||||
res.status(response.status).json(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching assignment details:", error.message);
|
||||
res.status(error.response?.status || 500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
studentRouter.post("/deploy", (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
module.exports = studentRouter;
|
||||
module.exports = studentRouter;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue