2025-10-27 22:58:31 +03:00
|
|
|
import { generateFixedHash, isValidId } from "./stringUtil";
|
2025-10-13 19:52:08 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Processes a user-entered camera name and returns both the final camera name
|
|
|
|
|
* and friendly name for Frigate configuration.
|
|
|
|
|
*
|
|
|
|
|
* @param userInput - The name entered by the user (could be display name)
|
|
|
|
|
* @returns Object with finalCameraName and friendlyName
|
|
|
|
|
*/
|
|
|
|
|
export function processCameraName(userInput: string): {
|
|
|
|
|
finalCameraName: string;
|
|
|
|
|
friendlyName?: string;
|
|
|
|
|
} {
|
|
|
|
|
const normalizedInput = userInput.replace(/\s+/g, "_").toLowerCase();
|
|
|
|
|
|
2025-10-27 22:58:31 +03:00
|
|
|
if (isValidId(normalizedInput)) {
|
2025-10-13 19:52:08 +03:00
|
|
|
return {
|
|
|
|
|
finalCameraName: normalizedInput,
|
|
|
|
|
friendlyName: userInput.includes(" ") ? userInput : undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
2025-10-27 22:58:31 +03:00
|
|
|
finalCameraName: generateFixedHash(userInput, "cam"),
|
2025-10-13 19:52:08 +03:00
|
|
|
friendlyName: userInput,
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-10-14 01:47:26 +03:00
|
|
|
|
|
|
|
|
// ==================== Reolink Camera Detection ====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect Reolink camera capabilities and recommend optimal protocol
|
|
|
|
|
*
|
|
|
|
|
* Calls the Frigate backend API which queries the Reolink camera to determine
|
|
|
|
|
* its resolution and recommends either http-flv (for 5MP and below) or rtsp
|
|
|
|
|
* (for higher resolutions).
|
|
|
|
|
*
|
|
|
|
|
* @param host - Camera IP address or hostname
|
|
|
|
|
* @param username - Camera username
|
|
|
|
|
* @param password - Camera password
|
|
|
|
|
* @returns The recommended protocol key ("http-flv" or "rtsp"), or null if detection failed
|
|
|
|
|
*/
|
|
|
|
|
export async function detectReolinkCamera(
|
|
|
|
|
host: string,
|
|
|
|
|
username: string,
|
|
|
|
|
password: string,
|
|
|
|
|
): Promise<"http-flv" | "rtsp" | null> {
|
|
|
|
|
try {
|
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
|
host,
|
|
|
|
|
username,
|
|
|
|
|
password,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`/api/reolink/detect?${params.toString()}`, {
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
if (data.success && data.protocol) {
|
|
|
|
|
return data.protocol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|