import path from "path"; import { Plugin } from "./plugin.js"; export class FlattenPathsPlugin extends Plugin { constructor(name, options) { super(name, options); } async applyPrerender(originalManuscript, jobId) { let transcript = originalManuscript.transcript if (originalManuscript.bgMusic) { originalManuscript.bgMusic = path.join('public', path.basename(originalManuscript.bgMusic)); } for (let item of transcript) { // flatten any media objects attached directly to the transcript item if (item.mediaAbsPaths && item.mediaAbsPaths.length > 0) { item.mediaAbsPaths = item.mediaAbsPaths.map((mediaObj) => { let flattenedPath = path.join('public', path.basename(mediaObj.path)); return { ...mediaObj, path: flattenedPath, }; }); } // also flatten any bubble media paths if bubbles exist if (item.bubbles && item.bubbles.length > 0) { item.bubbles.forEach((b) => { if (b.mediaAbsPath && b.mediaAbsPath.path) { b.mediaAbsPath.path = path.join( 'public', path.basename(b.mediaAbsPath.path) ); } if (b.bubbleHtml && b.bubbleHtml.path) { b.bubbleHtml.path = path.join( 'public', path.basename(b.bubbleHtml.path) ); } }); } if (item.audioCaptionFile) { item.audioCaptionFile = path.join('public', path.basename(item.audioCaptionFile)); } if (item.audioFullPath) { item.audioFullPath = path.join('public', path.basename(item.audioFullPath)); } } } }