chore(backend): Opzetten processing begonnen.
Functionaliteit van Dwengo Learning-Object-Repository in ons project gekopiëerd en deels aanBestanden die enkel types of interfaces exporteren hernoemd naar *.d.tsgepast aan TypeScript en ons project.
This commit is contained in:
parent
2d9f17484c
commit
ba3da01d2d
18 changed files with 875 additions and 11 deletions
|
@ -0,0 +1,36 @@
|
|||
import DOMPurify from 'isomorphic-dompurify'
|
||||
import Processor from "../processor.ts"
|
||||
import path from "path"
|
||||
|
||||
class TextProcessor extends Processor {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} plain text
|
||||
* @param {object} args Optional arguments
|
||||
* @returns
|
||||
*/
|
||||
render(text, args = {}) {
|
||||
// Sanitize plain text to prevent xss.
|
||||
return DOMPurify.sanitize(text);
|
||||
}
|
||||
|
||||
processFiles(files, metadata){
|
||||
let inputString = "";
|
||||
let file = files.find((f) => {
|
||||
let ext = path.extname(f.originalname);
|
||||
if (ext == ".txt") {
|
||||
inputString = f.buffer.toString('utf8');
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return [this.render(inputString), files]
|
||||
}
|
||||
}
|
||||
|
||||
export default TextProcessor;
|
Loading…
Add table
Add a link
Reference in a new issue