-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate-logo.ts
More file actions
42 lines (33 loc) · 1.14 KB
/
validate-logo.ts
File metadata and controls
42 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as fs from "fs/promises";
import { read } from "image-js";
import * as path from "path";
import * as github from "./github";
import * as messages from "./messages";
import { Entity } from "./validate-fs";
export async function validateLogo({ logo: logoPath }: Entity) {
if (!logoPath) {
return;
}
const errors: string[] = [];
const { size } = await fs.stat(logoPath);
if (size > 1024 * 100) {
errors.push("The image is too large. The maximum size is 100KB");
}
if (path.extname(logoPath) !== ".png") {
errors.push("The image format should be PNG");
} else {
const image = await read(logoPath);
// if (!image.alpha) {
// errors.push("The image background should be transparent");
// }
if (image.width != 256 || image.height != 256) {
errors.push(
`The image size must be 256x256 pixels. Current size is ${image.width}x${image.height}.`,
);
}
}
if (errors.length) {
await github.addComment(messages.invalidLogo(logoPath, errors));
throw new Error("The logo is invalid");
}
}