more cleanup

This commit is contained in:
Sparticuz 2023-03-27 12:46:23 -04:00
parent f337cdad26
commit 8ab732f14e
1 changed files with 13 additions and 7 deletions

View File

@ -24,22 +24,22 @@ interface Viewport {
/** /**
* Specify device scale factor. * Specify device scale factor.
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | devicePixelRatio} for more info. * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | devicePixelRatio} for more info.
* @defaultValue 1 * @default 1
*/ */
deviceScaleFactor?: number; deviceScaleFactor?: number;
/** /**
* Whether the `meta viewport` tag is taken into account. * Whether the `meta viewport` tag is taken into account.
* @defaultValue false * @default false
*/ */
isMobile?: boolean; isMobile?: boolean;
/** /**
* Specifies if the viewport is in landscape mode. * Specifies if the viewport is in landscape mode.
* @defaultValue false * @default false
*/ */
isLandscape?: boolean; isLandscape?: boolean;
/** /**
* Specify if the viewport supports touch events. * Specify if the viewport supports touch events.
* @defaultValue false * @default false
*/ */
hasTouch?: boolean; hasTouch?: boolean;
} }
@ -76,7 +76,7 @@ class Chromium {
/** /**
* Downloads or symlinks a custom font and returns its basename, patching the environment so that Chromium can find it. * Downloads or symlinks a custom font and returns its basename, patching the environment so that Chromium can find it.
*/ */
static font(input: string): Promise<string | null> { static font(input: string): Promise<string> {
if (process.env.HOME === undefined) { if (process.env.HOME === undefined) {
process.env.HOME = "/tmp"; process.env.HOME = "/tmp";
} }
@ -244,7 +244,7 @@ class Chromium {
} }
/** /**
* Returns sensible default viewport settings. * Returns sensible default viewport settings for serverless environments.
*/ */
static get defaultViewport(): Required<Viewport> { static get defaultViewport(): Required<Viewport> {
return { return {
@ -270,9 +270,15 @@ class Chromium {
return Promise.resolve("/tmp/chromium"); return Promise.resolve("/tmp/chromium");
} }
/**
* If input is a valid URL, download and extract the file. It will extract to /tmp/chromium-pack
* and executablePath will be recursively called on that location, which will then extract
* the brotli files to the correct locations
*/
if (input && isValidUrl(input)) { if (input && isValidUrl(input)) {
return this.executablePath(await downloadAndExtract(input)); return this.executablePath(await downloadAndExtract(input));
} }
/** /**
* If input is defined, use that as the location of the brotli files, * If input is defined, use that as the location of the brotli files,
* otherwise, the default location is ../bin. * otherwise, the default location is ../bin.
@ -289,7 +295,7 @@ class Chromium {
// Extract the required files // Extract the required files
const promises = [LambdaFS.inflate(`${input}/chromium.br`)]; const promises = [LambdaFS.inflate(`${input}/chromium.br`)];
if (this.graphicsMode) { if (this.graphics) {
// Only inflate graphics stack if needed // Only inflate graphics stack if needed
promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`)); promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`));
} }