Browse Source

fix daniel route

pull/1/head
Rich Brown 4 months ago
parent
commit
f38a612e09
4 changed files with 7 additions and 6 deletions
  1. +1
    -1
      src/danielRouter.js
  2. +2
    -2
      src/funcs/danielSpeaks.js
  3. +3
    -2
      src/funcs/saveMP3toFileserver.js
  4. +1
    -1
      src/index.js

+ 1
- 1
src/danielRouter.js View File

@@ -8,7 +8,7 @@ const danielRouter = express.Router();

danielRouter.use("/", (req, res) => {
if (req.body && req.body.code && req.body.code === process.env.CODE) {
return danielSpeaks()
return danielSpeaks(req.body.string)
.then(({ string, filename }) => res.json({ string, filename }))
.catch(() => res.json({ message: "right code but something went wrong"}))
} else {


+ 2
- 2
src/funcs/danielSpeaks.js View File

@@ -8,12 +8,12 @@ const go = string =>
savePhraseAsText(string)
.then(({filename, string}) => saveTextAsAudio({filename, string}))
.then(({filename, string}) => convertAACtoMP3({filename, string}))
.then(({filename, string}) => isProd ? saveMP3toFileserver({ filename, string}) : {filename, string})
.then(({filename, string}) => saveMP3toFileserver({ filename, string, daniel: true }))
.then(({filename, string}) => isProd ? deleteTempFiles({ filename, string }) : {filename, string})
.then(result => result)
.catch(e => console.log(e));

export default () => new Promise(async (resolve, reject) => {
export default (text) => new Promise(async (resolve, reject) => {
try {
resolve(go(text));
} catch(e) {


+ 3
- 2
src/funcs/saveMP3toFileserver.js View File

@@ -2,9 +2,10 @@ import request from "request";
import fs from "fs";
import slugifyPhrase from "./slugifyPhrase.js";

export default ({filename, string}) => new Promise((resolve, reject) => {
export default ({filename, string, daniel}) => new Promise((resolve, reject) => {
var r = request.post('https://www.porknachos.com/cms/pod/', function optionalCallback (err, httpResponse, body) {
if (err) {
console.log(err)
reject("uploading MP3 to server failed");
}
resolve({ filename, string })
@@ -13,7 +14,7 @@ export default ({filename, string}) => new Promise((resolve, reject) => {
var form = r.form();
form.append(
'file',
fs.createReadStream(`${filename}POSTCONCAT.mp3`), // TODO: hacky, yuck.
fs.createReadStream(daniel ? `${filename}.mp3` : `${filename}POSTCONCAT.mp3`), // TODO: hacky, yuck.
{ filename: `${slug}.mp3`}
);
});

+ 1
- 1
src/index.js View File

@@ -3,7 +3,7 @@ import express from 'express';

import episodeRouter from "./episodeRouter";
import sayRouter from "./sayRouter";
import danielRouter from "./sayRouter";
import danielRouter from "./danielRouter";

const app = express();
const port = process.env.PORT;


Loading…
Cancel
Save