File size: 1,062 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
/**
 * Inbox processing utilities
 * Extracted common logic from inbox processors for better maintainability
 */

import { createLoggerWithContext } from "@midday/logger";

const logger = createLoggerWithContext("worker:inbox-processing");

/**
 * Validate file path and extract filename
 */
export function validateFilePath(filePath: string[]): {
  fileName: string;
  fullPath: string;
} {
  const filename = filePath.at(-1);

  // Edge case: Validate filename exists
  if (!filename || filename.trim().length === 0) {
    throw new Error("Invalid file path: filename is missing");
  }

  return {
    fileName: filename,
    fullPath: filePath.join("/"),
  };
}

/**
 * Validate file size
 */
export function validateFileSize(size: number): void {
  // Edge case: Validate file size is reasonable
  if (size <= 0) {
    throw new Error(`Invalid file size: ${size} bytes`);
  }

  // Warn about very large files (optional)
  const sizeInMB = size / (1024 * 1024);
  if (sizeInMB > 100) {
    logger.warn(`Large file detected: ${sizeInMB.toFixed(2)}MB`);
  }
}