{"size": 885, "ext": "js", "max_stars_repo_path": "packages/fileimport-service/src/filesApi.js", "max_stars_repo_name": "specklesystems/Server", "max_stars_repo_stars_event_min_datetime": "2020-08-26T12:51:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T21:19:21.000Z", "max_issues_repo_path": "packages/fileimport-service/src/filesApi.js", "max_issues_repo_name": "specklesystems/Server", "max_issues_repo_issues_event_min_datetime": "2020-09-02T15:39:18.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-03T11:01:03.000Z", "max_forks_repo_path": "packages/fileimport-service/src/filesApi.js", "max_forks_repo_name": "specklesystems/Server", "max_forks_repo_forks_event_min_datetime": "2020-08-26T18:10:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T07:02:26.000Z"}
{"max_stars_count": 19, "max_issues_count": 22, "max_forks_count": 3, "avg_line_length": 26.8181818182, "max_line_length": 92, "alphanum_fraction": 0.5966101695}
/* istanbul ignore file */
'use strict'
const fs = require('fs')
const path = require('node:path')
const { stream, fetch } = require('undici')

module.exports = {
  async downloadFile({ fileId, streamId, token, destination }) {
    fs.mkdirSync(path.dirname(destination), { recursive: true })
    await stream(
      `${process.env.SPECKLE_SERVER_URL}/api/stream/${streamId}/blob/${fileId}`,
      {
        opaque: fs.createWriteStream(destination),
        headers: {
          Authorization: `Bearer ${token}`
        }
      },
      ({ opaque }) => opaque
    )
  },
  async getFileInfoByName({ fileName, streamId, token }) {
    const response = await fetch(
      `${process.env.SPECKLE_SERVER_URL}/api/stream/${streamId}/blobs?fileName=${fileName}`,
      {
        headers: {
          Authorization: `Bearer ${token}`
        }
      }
    )
    return response.json()
  }
}
