File size: 476 Bytes
07ae658
 
 
a99b4ac
07ae658
f64828c
a99b4ac
 
07ae658
 
 
 
 
 
 
a99b4ac
 
 
 
07ae658
a99b4ac
07ae658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import path from 'node:path'
import fs from 'node:fs'

import tmpDir from 'temp-dir'

export const downloadVideo = async (remoteUrl: string, fileName: string): Promise<string> => {

  const filePath = path.resolve(tmpDir, fileName)

  // download the video
  const response = await fetch(remoteUrl)

  // write it to the disk
  const arrayBuffer = await response.arrayBuffer()

  await fs.promises.writeFile(
    filePath,
    Buffer.from(arrayBuffer)
  )

  return fileName
}