UNPKG

@uppy/companion

Version:

OAuth helper and remote fetcher for Uppy's (https://uppy.io) extensible file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Dropbox and Google Drive, S3 and more :dog:

32 lines (31 loc) 903 B
"use strict"; const logger = require('./logger'); const { getProtectedGot } = require('./helpers/request'); const { prepareStream } = require('./helpers/utils'); /** * Downloads the content in the specified url, and passes the data * to the callback chunk by chunk. * * @param {string} url * @param {boolean} allowLocalIPs * @param {string} traceId * @returns {Promise} */ const downloadURL = async (url, allowLocalIPs, traceId, options) => { try { const protectedGot = await getProtectedGot({ allowLocalIPs }); const stream = protectedGot.stream.get(url, { responseType: 'json', ...options, }); const { size } = await prepareStream(stream); return { stream, size }; } catch (err) { logger.error(err, 'controller.url.download.error', traceId); throw err; } }; module.exports = { downloadURL, };