shiveshnavin commited on
Commit
6b85c8b
·
1 Parent(s): ffa9858

Add outfile

Browse files
routes.js CHANGED
@@ -14,6 +14,7 @@ import pkg from 'common-utils';
14
  const { Utils, PerformanceRecorder, FileUploader, Vault } = pkg;
15
  import bodyParser from 'body-parser';
16
  import { existsSync } from 'fs';
 
17
 
18
  const RenderRouter = Router();
19
  const __filename = fileURLToPath(import.meta.url);
@@ -134,6 +135,9 @@ RenderRouter.post('/api/render-sync', async (req, res) => {
134
  let skipRender = req.body.skip_render;
135
  let zip = req.body.zip ?? true;
136
 
 
 
 
137
  if (!fileUrl) {
138
  return res.status(400).send({
139
  message:
@@ -169,9 +173,9 @@ RenderRouter.post('/api/render-sync', async (req, res) => {
169
  else {
170
  console.log(`Job ${jobId} assets already exploded to public. Not downloading again.`)
171
  }
172
- let originalManuscript = Utils.readFileToObject(
173
- path.join(__dirname, `public`, `original_manuscript.json`)
174
- );
175
  if (!skipRender) {
176
  let renderMethod = req.body.method || req.query.method || 'cli';
177
  if (renderMethod == 'cli' || req.query.media_type == 'image') {
@@ -332,6 +336,9 @@ RenderRouter.post('/api/render-sync', async (req, res) => {
332
  );
333
  }
334
  }
 
 
 
335
  const uploader = new FileUploader('oracle', {
336
  url: targetUrl + jobId + '/',
337
  });
 
14
  const { Utils, PerformanceRecorder, FileUploader, Vault } = pkg;
15
  import bodyParser from 'body-parser';
16
  import { existsSync } from 'fs';
17
+ import { applyPluginsPostrender, applyPluginsPrerender } from './server-plugins/apply.js';
18
 
19
  const RenderRouter = Router();
20
  const __filename = fileURLToPath(import.meta.url);
 
135
  let skipRender = req.body.skip_render;
136
  let zip = req.body.zip ?? true;
137
 
138
+ // {name,...options}[]
139
+ let plugins = req.body.plugins || [];
140
+
141
  if (!fileUrl) {
142
  return res.status(400).send({
143
  message:
 
173
  else {
174
  console.log(`Job ${jobId} assets already exploded to public. Not downloading again.`)
175
  }
176
+ const originalManuscriptPath = path.join(__dirname, `public`, `original_manuscript.json`)
177
+ let originalManuscript = Utils.readFileToObject(originalManuscriptPath);
178
+ await applyPluginsPrerender(plugins, originalManuscript, originalManuscriptPath, jobId)
179
  if (!skipRender) {
180
  let renderMethod = req.body.method || req.query.method || 'cli';
181
  if (renderMethod == 'cli' || req.query.media_type == 'image') {
 
336
  );
337
  }
338
  }
339
+
340
+ await applyPluginsPostrender(plugins, originalManuscript, jobId, [outFile])
341
+
342
  const uploader = new FileUploader('oracle', {
343
  url: targetUrl + jobId + '/',
344
  });
server-plugins/apply.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import _ from 'lodash'
2
+ import fs from 'fs'
3
+ import { SplitRenderPlugin } from './split-render.js';
4
+
5
+ const pluginRegistry = {
6
+ 'split-media-render': SplitRenderPlugin,
7
+ };
8
+
9
+ export async function applyPluginsPrerender(plugins, originalManuscript, originalManuscriptPath, jobId) {
10
+ for (let pluginInfo of plugins) {
11
+ let pluginName = pluginInfo.name;
12
+ let options = pluginInfo.options || {};
13
+ _.set(originalManuscript, 'meta.plugins', plugins)
14
+ fs.writeFileSync(originalManuscriptPath, JSON.stringify(originalManuscript, null, 2))
15
+
16
+ console.log(`Applying plugin: ${pluginName} with options:`, options)
17
+
18
+ if (pluginRegistry[pluginName]) {
19
+ let pluginInstance = new pluginRegistry[pluginName](pluginName, options);
20
+ await pluginInstance.applyPrerender(originalManuscript, originalManuscriptPath);
21
+ } else {
22
+ console.warn(`Plugin ${pluginName} not found in registry.`);
23
+
24
+ }
25
+ }
26
+ }
27
+
28
+ export async function applyPluginsPostrender(plugins, originalManuscript, jobId, outFiles) {
29
+ for (let pluginInfo of plugins) {
30
+ let pluginName = pluginInfo.name;
31
+ let options = pluginInfo.options || {};
32
+ console.log(`Applying post-render plugin: ${pluginName} with options:`, options)
33
+ }
34
+ }
server-plugins/plugin.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ export class Plugin {
3
+ constructor(name, options) {
4
+ this.name = name;
5
+ this.options = options || {};
6
+ }
7
+ async applyPrerender(manuscript, manuscriptPath) {
8
+ console.log(`Applying plugin: ${this.name} with options:`, this.options);
9
+ }
10
+
11
+ async applyPostrender(renderedFramesPath) {
12
+ console.log(`Applying post-render plugin: ${this.name} with options:`, this.options);
13
+ }
14
+ }
15
+
server-plugins/split-render.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import _ from 'lodash'
2
+ import fs from 'fs'
3
+ import { Plugin } from './plugin.js';
4
+
5
+ export class SplitRenderPlugin extends Plugin {
6
+ constructor(name, options) {
7
+ super(name, options);
8
+ }
9
+ async applyPrerender(manuscript, manuscriptPath) {
10
+ _.set(manuscript, 'meta.splitRender', this.options);
11
+ fs.writeFileSync(manuscriptPath, JSON.stringify(manuscript, null, 2));
12
+ console.log(`Applying split-render plugin: ${this.name} with options:`, this.options);
13
+ }
14
+ async applyPostrender(renderedFramesPath) {
15
+ console.log(`Applying post-render split-render plugin: ${this.name} with options:`, this.options);
16
+ }
17
+ }