picture.ts (519B)
1 import { DomainError } from "#core/domain/error.ts"; 2 3 const MAX_SIZE = 524_288; /** 500kb */ 4 const BASE64PNG_PREFIX = "data:image/png;base64,iVBORw0KGg"; 5 6 export class Picture { 7 constructor(readonly value: string) { 8 if (!value.startsWith(BASE64PNG_PREFIX) || value.length > MAX_SIZE) { 9 throw new InvalidPicture(); 10 } 11 } 12 13 toString() { 14 return this.value; 15 } 16 } 17 18 export class InvalidPicture extends DomainError { 19 constructor(options?: ErrorOptions) { 20 super("Invalid PNG Image", options); 21 } 22 }