export type ApkEnvironment = 'dev' | 'sandbox' | 'product' | 'other'; export interface ParsedApkMetadata { environment: ApkEnvironment; commit: string | null; isValid: boolean; } // Environment mapping based on filename patterns const ENVIRONMENT_MAP: Record = { 'timeshift': 'dev', 'lan': 'dev', 'dev': 'dev', 'sandbox': 'sandbox', }; export function detectEnvironment(filename: string): ApkEnvironment { // Pattern: ft_[environment]_version_commit.apk // Extract the environment segment between first and second underscores const match = filename.match(/^ft_([^_]+)_/); if (!match) { // No environment suffix, default to product return 'product'; } const env = match[1].toLowerCase(); return ENVIRONMENT_MAP[env] || 'other'; } export function parseApkFilename(filename: string): ParsedApkMetadata { const environment = detectEnvironment(filename); const commitMatch = filename.match(/([a-f0-9]{7,})\.apk$/); const commit = commitMatch ? commitMatch[1] : null; const isValid = commit !== null; return { environment, commit, isValid, }; }