Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions __tests__/base-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ describe('PassBase', () => {

const bpWithAllowHttpFalse = new PassBase({}, undefined, undefined, {
allowHttp: false,
disableImageCheck: false,
});
expect(() => {
bpWithAllowHttpFalse.webServiceURL = 'http://transfers.do/webservice';
}).toThrow();

const bpWithAllowHttpTrue = new PassBase({}, undefined, undefined, {
allowHttp: true,
disableImageCheck: false,
});
expect(() => {
bpWithAllowHttpTrue.webServiceURL = 'http://transfers.do/webservice';
Expand Down
7 changes: 4 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export type ApplePass = PassStandardKeys &
PassWebServiceKeys &
PassStructureFields;

export interface Options {
allowHttp: boolean
}
export interface Options {
allowHttp: boolean;
disableImageCheck: boolean;
}
10 changes: 8 additions & 2 deletions src/lib/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class PassImages extends Map<string, string | Buffer> {
* loaded, nothing bad happens if directory contains other files.
*
* @param {string} dirPath - path to a directory with images
* @param {boolean} disableImageCheck - disable image dimension validation
* @memberof PassImages
*/
async load(dirPath: string): Promise<this> {
async load(dirPath: string, disableImageCheck?: boolean): Promise<this> {
// Check if the path is accessible directory actually
const entries = await fs.readdir(dirPath, { withFileTypes: true });
// checking rest of files
Expand All @@ -101,6 +102,7 @@ export class PassImages extends Map<string, string | Buffer> {
path.join(currentPath, f.name),
img.density,
lang,
disableImageCheck
),
);
}
Expand All @@ -113,6 +115,8 @@ export class PassImages extends Map<string, string | Buffer> {
img.imageType,
path.join(dirPath, entry.name),
img.density,
undefined,
disableImageCheck
),
);
}
Expand All @@ -121,11 +125,13 @@ export class PassImages extends Map<string, string | Buffer> {
return this;
}

// eslint-disable-line max-params
async add(
imageType: ImageType,
pathOrBuffer: string | Buffer,
density?: ImageDensity,
lang?: string,
disableImageCheck?: boolean
): Promise<void> {
if (!IMAGES_TYPES.has(imageType))
throw new TypeError(`Unknown image type ${imageSize} for ${imageType}`);
Expand Down Expand Up @@ -154,7 +160,7 @@ export class PassImages extends Map<string, string | Buffer> {
);
sizeRes = parser.getResult() as ImageSizeResult;
}
this.checkImage(imageType, sizeRes, density);
if (!disableImageCheck) this.checkImage(imageType, sizeRes, density);
super.set(this.getImageFilename(imageType, density, lang), pathOrBuffer);
}

Expand Down
6 changes: 5 additions & 1 deletion src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class Template extends PassBase {
join(currentPath, f.name),
img.density,
lang,
options?.disableImageCheck
),
);
}
Expand All @@ -150,6 +151,8 @@ export class Template extends PassBase {
img.imageType,
join(folderPath, entry.name),
img.density,
undefined,
options?.disableImageCheck
),
);
}
Expand Down Expand Up @@ -211,6 +214,7 @@ export class Template extends PassBase {
imgBuffer,
img.density,
img.lang,
options?.disableImageCheck,
);
} else {
// the only option lest is 'pass.strings' file in localization folder
Expand Down Expand Up @@ -362,6 +366,6 @@ export class Template extends PassBase {
}
}

function createDefaultTemplate(options?: Options): Template{
function createDefaultTemplate(options?: Options): Template {
return new Template(undefined, {}, undefined, undefined, options)
}