Spaces:
Running
Running
Commit
·
2d7b087
1
Parent(s):
93b115e
Backup
Browse files- .gitignore +2 -1
- app.js +34 -4
- ffmpeg-fix.js +2 -1
- firebase.json +1 -0
- functions/package.json +0 -27
- index.html +1 -1
- functions/index.js → index.js +2 -2
- package.json +11 -1
.gitignore
CHANGED
|
@@ -10,4 +10,5 @@ public/
|
|
| 10 |
**.zip
|
| 11 |
yarn.lock
|
| 12 |
package-lock.json
|
| 13 |
-
functions/*.log
|
|
|
|
|
|
| 10 |
**.zip
|
| 11 |
yarn.lock
|
| 12 |
package-lock.json
|
| 13 |
+
functions/*.log
|
| 14 |
+
**.log
|
app.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const stream = require('stream');
|
| 3 |
const bodyParser = require('body-parser');
|
| 4 |
-
const { spawn } = require('child_process');
|
| 5 |
const fs = require('fs');
|
| 6 |
const path = require('path');
|
| 7 |
const { Utils } = require('common-utils');
|
| 8 |
const { ZipFiles, UnzipFiles } = require('common-utils');
|
| 9 |
const OracleStorage = require('./common-creds/oracle/storage.json');
|
| 10 |
const axios = require('axios');
|
|
|
|
| 11 |
|
| 12 |
let pl = {
|
| 13 |
onLog: console.log
|
|
@@ -147,6 +147,10 @@ app.all('/render', async (req, res) => {
|
|
| 147 |
let manuObj = JSON.parse(fs.readFileSync(manuFile).toString())
|
| 148 |
modifyFiles(manuObj)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
res.send({
|
| 151 |
job_id: manuObj.id
|
| 152 |
})
|
|
@@ -196,14 +200,40 @@ app.post('/upload', async (req, res) => {
|
|
| 196 |
res.status(500).send({ message: 'Error uploading file' });
|
| 197 |
}
|
| 198 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
app.get('/', (req, res) => {
|
| 200 |
-
res.sendFile(
|
| 201 |
});
|
| 202 |
|
| 203 |
-
fs.writeFileSync(
|
| 204 |
-
|
| 205 |
|
| 206 |
|
|
|
|
| 207 |
module.exports = app
|
| 208 |
|
| 209 |
// let manuFile = path.join(__dirname, 'public/original_manuscript.json')
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const stream = require('stream');
|
| 3 |
const bodyParser = require('body-parser');
|
|
|
|
| 4 |
const fs = require('fs');
|
| 5 |
const path = require('path');
|
| 6 |
const { Utils } = require('common-utils');
|
| 7 |
const { ZipFiles, UnzipFiles } = require('common-utils');
|
| 8 |
const OracleStorage = require('./common-creds/oracle/storage.json');
|
| 9 |
const axios = require('axios');
|
| 10 |
+
const { spawn, exec } = require('child_process');
|
| 11 |
|
| 12 |
let pl = {
|
| 13 |
onLog: console.log
|
|
|
|
| 147 |
let manuObj = JSON.parse(fs.readFileSync(manuFile).toString())
|
| 148 |
modifyFiles(manuObj)
|
| 149 |
|
| 150 |
+
if (!skipRender) {
|
| 151 |
+
doRender()
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
res.send({
|
| 155 |
job_id: manuObj.id
|
| 156 |
})
|
|
|
|
| 200 |
res.status(500).send({ message: 'Error uploading file' });
|
| 201 |
}
|
| 202 |
});
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
function doRender(status) {
|
| 206 |
+
const npmScript = 'render-build';
|
| 207 |
+
const childProcess = exec(`npm run ${npmScript}`);
|
| 208 |
+
|
| 209 |
+
// Capture and display stdout and stderr data in real-time
|
| 210 |
+
childProcess.stdout.on('data', (data) => {
|
| 211 |
+
console.log(data.toString());
|
| 212 |
+
});
|
| 213 |
+
|
| 214 |
+
childProcess.stderr.on('data', (data) => {
|
| 215 |
+
console.error(data.toString());
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
// Listen for the completion of the child process
|
| 219 |
+
childProcess.on('close', (code) => {
|
| 220 |
+
if (code === 0) {
|
| 221 |
+
console.log(`npm script '${npmScript}' completed successfully.`);
|
| 222 |
+
} else {
|
| 223 |
+
console.error(`npm script '${npmScript}' failed with code ${code}.`);
|
| 224 |
+
}
|
| 225 |
+
})
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
let indexFile = path.join(__dirname, 'index.html')
|
| 229 |
app.get('/', (req, res) => {
|
| 230 |
+
res.sendFile(indexFile);
|
| 231 |
});
|
| 232 |
|
| 233 |
+
fs.writeFileSync(indexFile, fs.readFileSync(indexFile).toString().replace("___ORACLE_API_BASE___", oracleAPI))
|
|
|
|
| 234 |
|
| 235 |
|
| 236 |
+
doRender()
|
| 237 |
module.exports = app
|
| 238 |
|
| 239 |
// let manuFile = path.join(__dirname, 'public/original_manuscript.json')
|
ffmpeg-fix.js
CHANGED
|
@@ -31,7 +31,8 @@ async function findAndCreateSymlink(targetExecutable, ffmpegPath) {
|
|
| 31 |
// Find the target executable in the system's PATH
|
| 32 |
var ffmpegPath = ffmpegPath || await which(targetExecutable);
|
| 33 |
const symlinkPath = path.join(__dirname, 'node_modules', '@remotion', 'compositor-win32-x64-msvc', 'ffmpeg', 'remotion', 'bin', targetExecutable);
|
| 34 |
-
await createSymlink(ffmpegPath, symlinkPath);
|
|
|
|
| 35 |
} catch (error) {
|
| 36 |
console.error('An error occurred while creating symlink ffmpeg:', error);
|
| 37 |
}
|
|
|
|
| 31 |
// Find the target executable in the system's PATH
|
| 32 |
var ffmpegPath = ffmpegPath || await which(targetExecutable);
|
| 33 |
const symlinkPath = path.join(__dirname, 'node_modules', '@remotion', 'compositor-win32-x64-msvc', 'ffmpeg', 'remotion', 'bin', targetExecutable);
|
| 34 |
+
// await createSymlink(ffmpegPath, symlinkPath);
|
| 35 |
+
fs.copyFileSync(ffmpegPath, symlinkPath)
|
| 36 |
} catch (error) {
|
| 37 |
console.error('An error occurred while creating symlink ffmpeg:', error);
|
| 38 |
}
|
firebase.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"functions": {
|
| 3 |
"codebase": "semibitmedia",
|
|
|
|
| 4 |
"predeploy": [
|
| 5 |
"echo Hey"
|
| 6 |
]
|
|
|
|
| 1 |
{
|
| 2 |
"functions": {
|
| 3 |
"codebase": "semibitmedia",
|
| 4 |
+
"source": ".",
|
| 5 |
"predeploy": [
|
| 6 |
"echo Hey"
|
| 7 |
]
|
functions/package.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "functions",
|
| 3 |
-
"description": "Cloud Functions for Firebase",
|
| 4 |
-
"dependencies": {
|
| 5 |
-
"firebase-admin": "^11.9.0",
|
| 6 |
-
"firebase-functions": "^4.4.1"
|
| 7 |
-
},
|
| 8 |
-
"devDependencies": {
|
| 9 |
-
"chai": "^4.3.6",
|
| 10 |
-
"chai-as-promised": "^7.1.1",
|
| 11 |
-
"eslint": "^8.40.0",
|
| 12 |
-
"mocha": "^7.2.0",
|
| 13 |
-
"sinon": "^9.2.4"
|
| 14 |
-
},
|
| 15 |
-
"scripts": {
|
| 16 |
-
"serve": "firebase emulators:start --only functions --project semibitmedia",
|
| 17 |
-
"shell": "firebase functions:shell --project semibitmedia",
|
| 18 |
-
"start": "npm run shell",
|
| 19 |
-
"deploy": "firebase deploy --only functions --project semibitmedia",
|
| 20 |
-
"logs": "firebase functions:log --project semibitmedia",
|
| 21 |
-
"compile": "cp ../tsconfig.json ./tsconfig-compile.json && tsc --project tsconfig-compile.json && cd .. && npm run build"
|
| 22 |
-
},
|
| 23 |
-
"engines": {
|
| 24 |
-
"node": "16"
|
| 25 |
-
},
|
| 26 |
-
"private": true
|
| 27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index.html
CHANGED
|
@@ -53,7 +53,7 @@
|
|
| 53 |
|
| 54 |
if (response.ok) {
|
| 55 |
statusMessage.textContent = 'File uploaded successfully! Triggering Render';
|
| 56 |
-
let renderUrl = '/render?fileUrl=' + encodeURIComponent(uploadUrl)
|
| 57 |
response = await fetch(renderUrl);
|
| 58 |
if (response.ok)
|
| 59 |
response.text().then(t => {
|
|
|
|
| 53 |
|
| 54 |
if (response.ok) {
|
| 55 |
statusMessage.textContent = 'File uploaded successfully! Triggering Render';
|
| 56 |
+
let renderUrl = window.location.href + '/render?fileUrl=' + encodeURIComponent(uploadUrl)
|
| 57 |
response = await fetch(renderUrl);
|
| 58 |
if (response.ok)
|
| 59 |
response.text().then(t => {
|
functions/index.js → index.js
RENAMED
|
@@ -3,7 +3,7 @@ const { onRequest } = require("firebase-functions/v2/https");
|
|
| 3 |
const { setGlobalOptions } = require("firebase-functions/v2");
|
| 4 |
|
| 5 |
const { initializeApp } = require("firebase-admin/app");
|
| 6 |
-
const
|
| 7 |
setGlobalOptions({
|
| 8 |
region: "us-central1",
|
| 9 |
// memory: "2GiB",
|
|
@@ -20,5 +20,5 @@ exports.ping = onRequest(async (req, res) => {
|
|
| 20 |
});
|
| 21 |
|
| 22 |
|
| 23 |
-
exports.
|
| 24 |
|
|
|
|
| 3 |
const { setGlobalOptions } = require("firebase-functions/v2");
|
| 4 |
|
| 5 |
const { initializeApp } = require("firebase-admin/app");
|
| 6 |
+
const app = require("./app");
|
| 7 |
setGlobalOptions({
|
| 8 |
region: "us-central1",
|
| 9 |
// memory: "2GiB",
|
|
|
|
| 20 |
});
|
| 21 |
|
| 22 |
|
| 23 |
+
exports.semibitmediarenderfarm = onRequest(app);
|
| 24 |
|
package.json
CHANGED
|
@@ -13,8 +13,16 @@
|
|
| 13 |
"build": "tsc --noEmitOnError --noUnusedLocals --noUnusedParameters --allowUnusedLabels",
|
| 14 |
"upgrade": "remotion upgrade",
|
| 15 |
"test": "eslint src --ext ts,tsx,js,jsx && tsc",
|
| 16 |
-
"postinstall": "cd node_modules/common-utils && npm run build && cd ../../ && node ffmpeg-fix.js"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"repository": {},
|
| 19 |
"license": "UNLICENSED",
|
| 20 |
"pnpm": {
|
|
@@ -25,6 +33,8 @@
|
|
| 25 |
}
|
| 26 |
},
|
| 27 |
"dependencies": {
|
|
|
|
|
|
|
| 28 |
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
| 29 |
"@remotion/bundler": "4.0.19",
|
| 30 |
"@remotion/google-fonts": "4.0.19",
|
|
|
|
| 13 |
"build": "tsc --noEmitOnError --noUnusedLocals --noUnusedParameters --allowUnusedLabels",
|
| 14 |
"upgrade": "remotion upgrade",
|
| 15 |
"test": "eslint src --ext ts,tsx,js,jsx && tsc",
|
| 16 |
+
"postinstall": "cd node_modules/common-utils && npm run build && cd ../../ && node ffmpeg-fix.js",
|
| 17 |
+
"serve": "firebase emulators:start --only functions --project semibitmedia",
|
| 18 |
+
"shell": "firebase functions:shell --project semibitmedia",
|
| 19 |
+
"deploy": "firebase deploy --only functions --project semibitmedia",
|
| 20 |
+
"logs": "firebase functions:log --project semibitmedia"
|
| 21 |
},
|
| 22 |
+
"engines": {
|
| 23 |
+
"node": "16"
|
| 24 |
+
},
|
| 25 |
+
"private": true,
|
| 26 |
"repository": {},
|
| 27 |
"license": "UNLICENSED",
|
| 28 |
"pnpm": {
|
|
|
|
| 33 |
}
|
| 34 |
},
|
| 35 |
"dependencies": {
|
| 36 |
+
"firebase-admin": "^11.9.0",
|
| 37 |
+
"firebase-functions": "^4.4.1",
|
| 38 |
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
| 39 |
"@remotion/bundler": "4.0.19",
|
| 40 |
"@remotion/google-fonts": "4.0.19",
|