fetcher.js 487 B

12345678910111213
  1. const fetch = require('node-fetch');
  2. const getBase64 = async (url) => {
  3. const response = await fetch(url, { headers: { 'User-Agent': 'okhttp/4.5.0' } });
  4. if (!response.ok) throw new Error(`unexpected response ${response.statusText}`);
  5. const buffer = await response.buffer();
  6. const videoBase64 = `data:${response.headers.get('content-type')};base64,` + buffer.toString('base64');
  7. if (buffer)
  8. return videoBase64;
  9. };
  10. exports.getBase64 = getBase64;