45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
export * from "./mui/theme";
|
||
export * from "./DecodeJWT";
|
||
export * from "./gltfCacheManager";
|
||
|
||
export const generateDefaultMediaName = (
|
||
objectName: string,
|
||
fileName: string,
|
||
mediaType: number | string,
|
||
isArticle: boolean = false
|
||
): string => {
|
||
const fileNameWithoutExtension = fileName.split(".").slice(0, -1).join(".");
|
||
|
||
if (isArticle && typeof mediaType === "string") {
|
||
return `${objectName}_${fileNameWithoutExtension}_${mediaType}`;
|
||
} else if (typeof mediaType === "number") {
|
||
const mediaTypeLabels: Record<number, string> = {
|
||
1: "Фото",
|
||
2: "Видео",
|
||
3: "Иконка",
|
||
4: "Водяной знак",
|
||
5: "Панорама",
|
||
6: "3Д-модель",
|
||
};
|
||
|
||
const mediaTypeLabel = mediaTypeLabels[mediaType] || "Медиа";
|
||
|
||
if (objectName && objectName.trim() !== "") {
|
||
return `${objectName}_${fileNameWithoutExtension}_${mediaTypeLabel}`;
|
||
} else {
|
||
return `Название_${fileNameWithoutExtension}_${mediaTypeLabel}`;
|
||
}
|
||
}
|
||
|
||
return `${objectName || "Название"}_${fileNameWithoutExtension}_Медиа`;
|
||
};
|
||
|
||
/** Медиа-id считается пустым, если строка пустая или состоит только из нулей (с дефисами или без). */
|
||
export const isMediaIdEmpty = (
|
||
id: string | null | undefined
|
||
): boolean => {
|
||
if (id == null || id === "") return true;
|
||
const digits = id.replace(/-/g, "");
|
||
return digits === "" || /^0+$/.test(digits);
|
||
};
|