/
githubmirror
/
atom
Обзор
Документация
Войти
/
githubmirror
/
atom
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
script/lib/download-file-from-github.js
25 строк
740 B
sadick254
Add authorization
04 янв 2021, 22:19
Не верифицирован
04 янв 2021, 22:19
b9ef64e
Код
Авторство
О чём код?
'use strict'; const fs = require('fs-extra'); const path = require('path'); const syncRequest = require('sync-request'); module.exports = function(downloadURL, destinationPath) { console.log(`Downloading file from GitHub Repository to ${destinationPath}`); const response = syncRequest('GET', downloadURL, { headers: { Accept: 'application/vnd.github.v3.raw', 'User-Agent': 'Atom Build', Authorization: `token ${process.env.GITHUB_TOKEN}` } }); if (response.statusCode === 200) { fs.mkdirpSync(path.dirname(destinationPath)); fs.writeFileSync(destinationPath, response.body); } else { throw new Error( 'Error downloading file. HTTP Status ' + response.statusCode + '.' ); } };