Skip to content

Commit c88f134

Browse files
moved constants in constants file
1 parent 43a5812 commit c88f134

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/commander/upload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import getGitInfo from '../tasks/getGitInfo.js';
99
import createBuild from '../tasks/createBuild.js';
1010
import uploadScreenshots from '../tasks/uploadScreenshots.js';
1111
import finalizeBuild from '../tasks/finalizeBuild.js';
12+
import constants from '../lib/constants.js';
1213

13-
const ZIP_EXTENSION = '.zip';
1414
const command = new Command();
1515

1616
command
@@ -33,7 +33,7 @@ command
3333
return;
3434
}
3535

36-
if (path.extname(directory).toLowerCase() === ZIP_EXTENSION) {
36+
if (path.extname(directory).toLowerCase() === constants.ZIP_EXTENSION) {
3737
ctx.log.debug(`Zips are not accepted. ${directory}`)
3838
console.log(`Error: The provided directory ${directory} is a zip file. Zips are not accepted.`);
3939
return;

src/lib/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ export default {
6767
// log file path
6868
LOG_FILE_PATH: '.smartui.log',
6969

70+
// Disallowed Zip Extension
71+
ZIP_EXTENSION: '.zip',
72+
73+
// Magic Numbers
74+
MAGIC_NUMBERS: [
75+
{ ext: 'jpg', magic: Buffer.from([0xFF, 0xD8, 0xFF]) },
76+
{ ext: 'jpeg', magic: Buffer.from([0xFF, 0xD8, 0xFF]) },
77+
{ ext: 'png', magic: Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) },
78+
],
79+
7080
SUPPORTED_MOBILE_DEVICES: {
7181
'Blackberry KEY2 LE': { os: 'android', viewport: {width: 412, height: 618}},
7282
'Galaxy A12': { os: 'android', viewport: {width: 360, height: 800}},

src/lib/screenshot.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import * as utils from "./utils.js"
66
import constants from './constants.js'
77
import chalk from 'chalk';
88

9-
const magicNumbers = [
10-
{ ext: 'jpg', magic: Buffer.from([0xFF, 0xD8, 0xFF]) },
11-
{ ext: 'jpeg', magic: Buffer.from([0xFF, 0xD8, 0xFF]) },
12-
{ ext: 'png', magic: Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) },
13-
];
14-
159
async function captureScreenshotsForConfig(
1610
ctx: Context,
1711
browsers: Record<string, Browser>,
@@ -173,7 +167,7 @@ function getImageDimensions(filePath: string): { width: number, height: number }
173167

174168
function isImage(buffer: Buffer): boolean {
175169

176-
return magicNumbers.some(magic => buffer.slice(0, magic.magic.length).equals(magic.magic));
170+
return constants.MAGIC_NUMBERS.some(magic => buffer.slice(0, magic.magic.length).equals(magic.magic));
177171
}
178172

179173
export async function uploadScreenshots(ctx: Context): Promise<void> {

0 commit comments

Comments
 (0)