|
1 | 1 | import * as core from '@actions/core'
|
2 | 2 | import { promises as fs, createWriteStream } from 'fs'
|
3 | 3 | import { dirname, join, resolve } from 'path'
|
| 4 | +import { pipeline } from 'stream' |
4 | 5 | import * as tar from 'tar'
|
| 6 | +import { promisify } from 'util' |
5 | 7 |
|
6 |
| -async function downloadFile( |
7 |
| - url: string, |
8 |
| - outputPath: string, |
9 |
| - token?: string |
10 |
| -): Promise<void> { |
| 8 | +const streamPipeline = promisify(pipeline) |
| 9 | + |
| 10 | +async function downloadFile(url: string, outputPath: string, token?: string): Promise<void> { |
11 | 11 | core.info(`Starting download from URL: ${url}`)
|
12 | 12 | const packageJson = require('../package.json')
|
13 | 13 | const userAgent = `beat-forge/init-beatsaber@${packageJson.version}`
|
@@ -36,24 +36,15 @@ async function downloadFile(
|
36 | 36 | core.debug(`Created directory for output path: ${dirname(outputPath)}`)
|
37 | 37 |
|
38 | 38 | const fileStream = createWriteStream(outputPath)
|
39 |
| - const reader = response.body?.getReader() |
40 |
| - |
41 |
| - if (!reader) { |
42 |
| - core.error('Failed to get reader from response body') |
43 |
| - throw new Error('Failed to get reader from response body') |
44 |
| - } |
45 | 39 |
|
46 | 40 | core.info('Starting to read and write file stream')
|
47 |
| - const pump = async () => { |
48 |
| - while (true) { |
49 |
| - const { done, value } = await reader.read() |
50 |
| - if (done) break |
51 |
| - if (value) fileStream.write(value) |
52 |
| - } |
53 |
| - fileStream.close() |
| 41 | + |
| 42 | + if (response.body) { |
| 43 | + await streamPipeline(response.body, fileStream) |
| 44 | + } else { |
| 45 | + throw new Error('Response body is null') |
54 | 46 | }
|
55 | 47 |
|
56 |
| - await pump() |
57 | 48 | core.info('File downloaded and written successfully')
|
58 | 49 | }
|
59 | 50 |
|
@@ -126,12 +117,12 @@ async function run(): Promise<void> {
|
126 | 117 | core.info('Initializing Beat Saber modding environment...')
|
127 | 118 |
|
128 | 119 | const token = core.getInput('token')
|
129 |
| - let requestedVersion = core.getInput('version') |
130 |
| - let manifestPath = core.getInput('manifest') |
131 |
| - let referencesPath = core.getInput('path') || './Refs' |
| 120 | + const repo = core.getInput('repo') |
| 121 | + const host = core.getInput('host') |
132 | 122 |
|
133 |
| - let repo = core.getInput('repo') || 'beat-forge/beatsaber-stripped' |
134 |
| - let host = core.getInput('host') || 'github.com' |
| 123 | + const manifestPath = core.getInput('manifest') |
| 124 | + const referencesPath = core.getInput('path') |
| 125 | + let requestedVersion = core.getInput('version') |
135 | 126 |
|
136 | 127 | core.debug(
|
137 | 128 | `Inputs: version=${requestedVersion}, manifest=${manifestPath}, path=${referencesPath}, repo=${repo}, host=${host}`
|
|
0 commit comments