Download backend/controllers/rubricController.js from essay003/prmsu: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/essay003/prmsu/resolve/main/backend/controllers/rubricController.js
- Command line
-
hf download hf://spaces/essay003/prmsu/backend/controllers/rubricController.js
-
curl -L -o rubricController.js https://huggingface.co/spaces/essay003/prmsu/resolve/main/backend/controllers/rubricController.js
1.17 kB
| import crypto from "node:crypto"; | |
| import { extractRubricFromImage } from "../services/aiService.js"; | |
| import { findRubricByImageHash, saveRubric } from "../services/rubricService.js"; | |
| export const uploadRubric = async (req, res) => { | |
| try { | |
| if (!req.file) { | |
| return res.status(400).json({ error: "No file uploaded" }); | |
| } | |
| const imageHash = crypto.createHash("sha256").update(req.file.buffer).digest("hex"); | |
| const cached = await findRubricByImageHash(imageHash); | |
| if (cached) { | |
| return res.json({ | |
| ...cached, | |
| cached: true | |
| }); | |
| } | |
| const extracted = await extractRubricFromImage(req.file); | |
| if (!extracted?.isValidRubric || !Array.isArray(extracted.rubric) || extracted.rubric.length === 0) { | |
| return res.status(400).json({ error: "rubric is invalid" }); | |
| } | |
| const rubric = extracted.rubric; | |
| const saved = await saveRubric({ | |
| rubric, | |
| imageHash, | |
| ownerUid: req.user?.uid || null | |
| }); | |
| res.json({ | |
| ...saved, | |
| cached: false | |
| }); | |
| } catch (err) { | |
| res.status(500).json({ | |
| error: "Failed to process rubric", | |
| message: err.message | |
| }); | |
| } | |
| }; | |