All files / src/lib avatar-media.ts

100% Statements 14/14
100% Branches 3/3
100% Functions 1/1
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x   1x   1x 1x 1x 1x 1x     1x 5x 5x 1x 1x 4x 4x  
import { AppError } from "@ontrack/backend-common";
 
export const MAX_AVATAR_BYTES = 5 * 1024 * 1024;
 
const EXT_BY_MIME: Record<string, string> = {
  "image/jpeg": "jpg",
  "image/png": "png",
  "image/webp": "webp",
};
 
/** Расширение по MIME-типу; неподдерживаемый тип → 415. */
export function avatarExtension(mimeType: string): string {
  const ext = EXT_BY_MIME[mimeType.toLowerCase()];
  if (!ext) {
    throw new AppError(415, "UNSUPPORTED_MEDIA_TYPE", "Поддерживаются JPEG, PNG, WebP");
  }
  return ext;
}