Spaces:
Running
Running
File size: 1,744 Bytes
8dd5bba dba0530 8dd5bba f9e47b5 8dd5bba f9e47b5 08ff55b f9e47b5 8dd5bba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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));
}
}
}
} |