fix
This commit is contained in:
@@ -104,15 +104,57 @@ export function formatFileSize(bytes?: number) {
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1)} МБ`;
|
||||
}
|
||||
|
||||
export interface ChatLocationMetadata {
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
address?: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export function parseMessageMetadata(metadataJson?: string) {
|
||||
if (!metadataJson) return {} as { fileName?: string; fileSize?: number; durationMs?: number; videoNote?: boolean };
|
||||
if (!metadataJson) {
|
||||
return {} as { fileName?: string; fileSize?: number; durationMs?: number; videoNote?: boolean } & ChatLocationMetadata;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(metadataJson) as { fileName?: string; fileSize?: number; durationMs?: number; videoNote?: boolean };
|
||||
return JSON.parse(metadataJson) as {
|
||||
fileName?: string;
|
||||
fileSize?: number;
|
||||
durationMs?: number;
|
||||
videoNote?: boolean;
|
||||
} & ChatLocationMetadata;
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function parseLocationMetadata(
|
||||
metadataJson?: string,
|
||||
e2ePayload?: { kind?: string; latitude?: number; longitude?: number; address?: string; label?: string; text?: string } | null
|
||||
): ChatLocationMetadata | null {
|
||||
if (e2ePayload?.kind === 'location') {
|
||||
const { latitude, longitude } = e2ePayload;
|
||||
if (typeof latitude === 'number' && typeof longitude === 'number') {
|
||||
return {
|
||||
latitude,
|
||||
longitude,
|
||||
address: e2ePayload.address,
|
||||
label: e2ePayload.label ?? e2ePayload.text
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const meta = parseMessageMetadata(metadataJson);
|
||||
if (typeof meta.latitude === 'number' && typeof meta.longitude === 'number') {
|
||||
return {
|
||||
latitude: meta.latitude,
|
||||
longitude: meta.longitude,
|
||||
address: meta.address,
|
||||
label: meta.label
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function fileIconLabel(fileName?: string, mimeType?: string) {
|
||||
const extension = extractFileExtension(fileName);
|
||||
if (extension === 'pdf' || mimeType === 'application/pdf') return 'PDF';
|
||||
|
||||
Reference in New Issue
Block a user