refactor(media): share fileExists

This commit is contained in:
Peter Steinberger
2026-02-15 17:33:00 +00:00
parent b6069fc68c
commit 5c88d3c9f1
3 changed files with 15 additions and 24 deletions

View File

@@ -0,0 +1,13 @@
import fs from "node:fs/promises";
export async function fileExists(filePath?: string | null): Promise<boolean> {
if (!filePath) {
return false;
}
try {
await fs.stat(filePath);
return true;
} catch {
return false;
}
}

View File

@@ -25,6 +25,7 @@ import {
DEFAULT_TIMEOUT_SECONDS,
} from "./defaults.js";
import { MediaUnderstandingSkipError } from "./errors.js";
import { fileExists } from "./fs.js";
import { extractGeminiResponse } from "./output-extract.js";
import { describeImageWithModel } from "./providers/image.js";
import { getMediaUnderstandingProvider, normalizeMediaProviderId } from "./providers/index.js";
@@ -129,18 +130,6 @@ function resolveWhisperCppOutputPath(args: string[]): string | null {
return `${outputBase}.txt`;
}
async function fileExists(filePath?: string | null): Promise<boolean> {
if (!filePath) {
return false;
}
try {
await fs.stat(filePath);
return true;
} catch {
return false;
}
}
async function resolveCliOutput(params: {
command: string;
args: string[];

View File

@@ -32,6 +32,7 @@ import {
DEFAULT_IMAGE_MODELS,
} from "./defaults.js";
import { isMediaUnderstandingSkipError } from "./errors.js";
import { fileExists } from "./fs.js";
import { extractGeminiResponse } from "./output-extract.js";
import {
buildMediaUnderstandingRegistry,
@@ -175,18 +176,6 @@ async function hasBinary(name: string): Promise<boolean> {
return Boolean(await findBinary(name));
}
async function fileExists(filePath?: string | null): Promise<boolean> {
if (!filePath) {
return false;
}
try {
await fs.stat(filePath);
return true;
} catch {
return false;
}
}
async function probeGeminiCli(): Promise<boolean> {
const cached = geminiProbeCache.get("gemini");
if (cached) {