···7979 }
80808181 return mediaBuffer;
8282-} 8282+}
8383+8484+/**
8585+ * Reads and parses a JSON file from the specified path.
8686+ *
8787+ * If the file does not exist, logs an informational message and returns the provided fallback value.
8888+ * If the file exists but cannot be parsed as JSON, logs a warning and returns the fallback value.
8989+ *
9090+ * @param filePath - The path to the JSON file to read.
9191+ * @param missingFileMessage - Optional message to log if the file is not found. Defaults to 'File not found.'.
9292+ * @param fallback - Optional fallback value to return if the file is missing or cannot be parsed. Defaults to an empty array.
9393+ * @returns The parsed JSON content as an array, or the fallback value if the file is missing or invalid.
9494+ */
9595+export function readJsonFile(filePath: string, missingFileMessage: string = 'File not found.', fallback: any[] = []): any[] {
9696+ if (!FS.existsSync(filePath)) {
9797+ logger.info(missingFileMessage)
9898+ return fallback;
9999+ }
100100+101101+ try {
102102+ const buffer = FS.readFileSync(filePath);
103103+ return JSON.parse(buffer.toString());
104104+ } catch (error) {
105105+ logger.warn(`Failed to parse ${filePath}: ${(error as Error)?.message}`);
106106+ return fallback;
107107+ }
108108+};