chore(backend): Aanpassingen Dwengo Learning-Object-Repository

Processing uit Dwengo Learning-Object-Repository geconverteerd naar TypeScript en aangepast aan onze app.

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:
Gerald Schmittinger 2025-03-07 23:20:57 +01:00
parent ba3da01d2d
commit 463c8c9fc0
45 changed files with 1258 additions and 3747 deletions

View file

@ -0,0 +1,38 @@
/**
* Based on https://github.com/dwengovzw/Learning-Object-Repository/blob/main/app/processors/extern/extern_processor.js
*/
import Processor from "../processor.js";
import DOMPurify from 'isomorphic-dompurify';
import {ProcessingError} from "../processing-error";
import {isValidHttpUrl} from "../../../../util/links";
import {DwengoContentType} from "../content-type";
class ExternProcessor extends Processor<string> {
constructor() {
super(DwengoContentType.EXTERN);
}
override renderFn(externURL: string) {
if (!isValidHttpUrl(externURL)) {
throw new ProcessingError("The url is not valid: " + externURL);
}
// If a seperate youtube-processor would be added, this code would need to move to that processor
// Converts youtube urls to youtube-embed urls
let match = /(.*youtube.com\/)watch\?v=(.*)/.exec(externURL)
if (match) {
externURL = match[1] + "embed/" + match[2];
}
return DOMPurify.sanitize(`
<div class="iframe-container">
<iframe src="${externURL}" allowfullscreen></iframe>
</div>`,
{ ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling']}
);
}
}
export default ExternProcessor;