MIt dem aktuellen Update, durchgeführt am 09.04.2021, wurden alle vorhanden Benutzer-Profile automatisch auf privat gesetzt. Wer ein öffentliches Profil haben möchte, muss diese Einstellung nun manuell unter den Profileinstellungen umstellen.

Commit b4ab3ae5 authored by Daniel Schiffner's avatar Daniel Schiffner

Initial commit

parent 4c802ae6
node_modules
\ No newline at end of file
const parseXlsx = require('excel').default;
const chokidar = require("chokidar");
const fs = require('fs');
const path = require("path");
const config = {
assignments_file: path.resolve(process.env.IBSD_ASSIGNMENTS_FILE || "assignments.xlsx")
};
let assignmentData = {};
const watcher = chokidar.watch(config.assignments_file);
function parseData() {
if(fs.existsSync(config.assignments_file)) {
console.log(`Loading assignments from ${config.assignments_file}`);
//reset data
assignmentData = {};
parseXlsx(config.assignments_file).then(data => {
for(let d of data) {
console.log(" - " + d[0] + " : " + d[1]);
assignmentData[d[0]] = d[1];
}
}).catch(() => {
console.log(`Failed to parse data from assigments file @ ${config.assignments_file}`);
})
} else {
console.log(`No assignments file found @ ${config.assignments_file} -> falling back to default`);
}
}
watcher.on("change", parseData);
watcher.on("add", parseData);
const findAssignment = function(userName) {
if(userName == "daniel") {
return "SPECIALE";
}
return assignmentData[userName];
};
module.exports = {findAssignment, watcher};
const express = require("express");
const {findAssignment, watcher} = require('./assignments');
let router = new express.Router();
router.init = () => {};
router.close = async () => {
await watcher.close();
console.log("Watcher closed");
};
router.use("/courses/:course?", (req, res, next) => {
let user = req.query['userId'];
console.log(`Check if a course is available for user ${user}`);
if (user) {
let c = findAssignment(user);
req.course = c;
}
//continue -> handler should honor this
next();
});
module.exports = router;
\ No newline at end of file
{
"name": "ibsd-xlsx-assignment",
"version": "1.0.0",
"description": "",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://gitlab.tba-hosting.de/tba-public/ibsd-plugins/ibsd-xlsx-assignment.git"
},
"keywords": [],
"author": "Dr. Daniel Schiffner",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"chokidar": "^3.4.2",
"excel": "^1.0.1",
"express": "^4.17.1"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment