const axios = require('axios')

async function upload(url){
  const upload_api = axios.create({
        baseURL: 'https://uploader-us01.pandavideo.com.br:3020'
  })

  const meta_response = await upload_api.post('/url/meta',{
    url
  })
  const meta = meta_response.data
  
  const created_upload_response = await upload_api.post('/url/get',{
    endpoint: 'https://uploader-us01.pandavideo.com.br/files/',
    protocol: 'tus',
    size: meta.size,
    url,
    fileId: url,
    metadata:{
        authorization: 'YOUR_APIKEY',
      name: 'FILE NAME',
      type: meta.type,
      description: 'SOME METADATA',
    }
  }) 
  
  const created_upload = created_upload_response.data
  const socket_url = `wss://uploader-fr01.pandavideo.com.br:3020/api/${created_upload.token}`
  let socket = new WebSocket(socket_url);
  socket.onmessage = async (event) => {
    console.log('EVENT ', JSON.stringify(event))
  }
}