Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download from Encore in OSC #3

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
stagingDir?: string;
noImplicitAudio?: boolean;
shakaExecutable?: string;
serviceAccessToken?: string;
}

export async function doPackage(opts: PackageOptions) {
Expand All @@ -42,7 +43,8 @@
export async function download(
input: Input,
source?: URL,
stagingDir?: string
stagingDir?: string,
serviceAccessToken?: string
): Promise<string> {
if (!source) {
return input.filename;
Expand Down Expand Up @@ -71,6 +73,30 @@
}
console.log(`Downloaded ${input.filename} to ${localFilename}`);
return localFilename;
} else if (source.protocol === 'http:' || source.protocol === 'https:') {
const localFilename = join(stagingDir, path.basename(input.filename));
const auth: string[] = [];
if (serviceAccessToken) {
auth.push('-H');
auth.push(`x-jwt: Bearer ${serviceAccessToken}`);
}
const { status, stdout, stderr } = spawnSync(

Check warning on line 83 in src/packager.ts

View workflow job for this annotation

GitHub Actions / lint

'stdout' is assigned a value but never used
'curl',
auth.concat([
'-v',
'-o',
localFilename,
source.href.replace(/\/$/, '') + input.filename
])
);
if (stderr) {
console.log(stderr.toString());
}
if (status !== 0) {
throw new Error('Download failed');
}
console.log(`Downloaded ${input.filename} to ${localFilename}`);
return localFilename;
} else {
throw new Error(`Unsupported protocol for download: ${source.protocol}`);
}
Expand Down Expand Up @@ -114,11 +140,17 @@
}

export async function createPackage(opts: PackageOptions) {
const { inputs, source, stagingDir, noImplicitAudio } = opts;
const { inputs, source, stagingDir, noImplicitAudio, serviceAccessToken } =
opts;
const sourceUrl = toUrlOrUndefined(source);
const downloadedInputs: Input[] = await Promise.all(
inputs.map(async (input) => {
const filename = await download(input, sourceUrl, stagingDir);
const filename = await download(
input,
sourceUrl,
stagingDir,
serviceAccessToken
);
return {
...input,
filename
Expand Down
Loading