aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-08-27 21:44:10 +0000
committerAdam Soltys <[email protected]>2023-08-27 21:44:10 +0000
commit60a79d20ab91c37a273a70d6c03336b8d5207fd6 (patch)
treea0eeff03468f712cf93f8c2a4e1cf0f1fe75104f /lib
parentc8fd7fe63f681a885fd95d9b12106b32b6729c25 (diff)
downloadcoinos-server-60a79d20ab91c37a273a70d6c03336b8d5207fd6.tar.gz
coinos-server-60a79d20ab91c37a273a70d6c03336b8d5207fd6.zip
validate amounts
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/payments.js b/lib/payments.js
index dba7f4d0..9172c794 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -5,13 +5,14 @@ import { v4 } from "uuid";
import { notify } from "$lib/notifications";
import { db, g, s, t } from "$lib/db";
import { l, err, warn } from "$lib/logging";
-import { fail } from "$lib/utils";
+import { fail, wait } from "$lib/utils";
import { callWebhook } from "$lib/webhooks";
import dollarsToWords from "dollars-to-words";
import got from "got";
import mqtt from "mqtt";
import { spawn } from "child_process";
import ffmpeg from 'fluent-ffmpeg';
+import fs from "fs";
export const types = {
internal: "internal",
@@ -116,6 +117,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
tip = parseInt(tip) || 0;
if (!memo) ({ memo } = invoice);
+ if (amount < 0 || tip < 0) fail("Invalid amount");
if (type === types.internal) amount += tip;
let user = await g(`user:${invoice.uid}`);
@@ -181,29 +183,39 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
parseFloat(((amount * p.rate) / 100000000).toFixed(2))
);
- l(words);
-
const client = mqtt.connect('mqtt://ln.coinos.io', config.mqtt);
const raw = `/app/data/uploads/${p.id}-raw.mp3`;
const out = `/app/data/uploads/${p.id}.mp3`;
const mimic = spawn("/mimic", ["-t", words, "-voice", "/cmu_us_axb.flitevox", "-o", raw]);
+ let connected;
+ let f = fs.createWriteStream(out);
+
+ mimic.stdout.on("end", async () => {
+ await wait(() => connected);
+ client.publish(username, "start");
- mimic.stdout.on("end", () => {
ffmpeg(raw)
.audioBitrate(128)
.audioFrequency(44100)
.toFormat('mp3')
- .on('end', () => {
- client.publish(username, "done");
- })
.on('error', (err) => {
- console.error('Error:', err);
+ console.log('Error:', err);
})
- .save(out);
+ .stream()
+ .on('data', (chunk) => {
+ client.publish(username, chunk);
+ f.write(chunk);
+ })
+ .on('end', () => {
+ console.log("FFMPEG done");
+ f.end();
+ client.publish(username, "end");
+ });
});
client.on('connect', function () {
client.publish(username, `${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`);
+ setTimeout(() => (connected = true), 50);
});
}