Skip to content

Commit

Permalink
fix: tmp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sglkc committed Jan 29, 2025
1 parent 263f389 commit 25977c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion functions/netlify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default async function handler(req) {
const query = Object.fromEntries(new URL(req.url).searchParams)
const payload = Object.assign({}, body, form, query)

return await main(payload, '/var/task/bin/ffmpeg')
return await main(payload, '/tmp/', '/var/task/bin/ffmpeg')
}
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
*/

import { readFile, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import * as TTS from '@sefinek/google-tts-api'
import Ffmpeg from 'fluent-ffmpeg'

export default async function main(payload, ffmpegPath = null) {
export default async function main(payload, tmp = '', ffmpegPath = '') {
const { text, lang = 'en', speed, pitch = 1 } = payload
const headers = {
'Access-Control-Allow-Origin': '*',
Expand All @@ -30,10 +31,10 @@ export default async function main(payload, ffmpegPath = null) {
const ffmpeg = Ffmpeg()
const files = []

if (ffmpegPath) ffmpeg.setFfmpegPath(ffmpegPath)
if (ffmpegPath.length) ffmpeg.setFfmpegPath(ffmpegPath)

for (const { base64 } of audios) {
const path = `${Date.now()}.mp3`
const path = join(tmp, `${Date.now()}.mp3`)
const buffer = Buffer.from(base64, 'base64')

files.push(path)
Expand Down

0 comments on commit 25977c4

Please sign in to comment.