2024-03-05 16:30:28 +08:00
|
|
|
import { IChunk } from '@/interfaces/database/knowledge';
|
2024-03-06 19:17:45 +08:00
|
|
|
import { UploadFile } from 'antd';
|
2024-03-05 16:30:28 +08:00
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
|
2024-03-26 14:51:34 +08:00
|
|
|
export const buildChunkHighlights = (
|
|
|
|
|
selectedChunk: IChunk,
|
|
|
|
|
size: { width: number; height: number },
|
|
|
|
|
) => {
|
2024-03-05 16:30:28 +08:00
|
|
|
return Array.isArray(selectedChunk?.positions) &&
|
|
|
|
|
selectedChunk.positions.every((x) => Array.isArray(x))
|
|
|
|
|
? selectedChunk?.positions?.map((x) => {
|
|
|
|
|
const boundingRect = {
|
2024-03-26 14:51:34 +08:00
|
|
|
width: size.width,
|
|
|
|
|
height: size.height,
|
|
|
|
|
x1: x[1],
|
|
|
|
|
x2: x[2],
|
|
|
|
|
y1: x[3],
|
|
|
|
|
y2: x[4],
|
2024-03-05 16:30:28 +08:00
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
id: uuid(),
|
|
|
|
|
comment: {
|
|
|
|
|
text: '',
|
|
|
|
|
emoji: '',
|
|
|
|
|
},
|
|
|
|
|
content: { text: selectedChunk.content_with_weight },
|
|
|
|
|
position: {
|
|
|
|
|
boundingRect: boundingRect,
|
|
|
|
|
rects: [boundingRect],
|
|
|
|
|
pageNumber: x[0],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
: [];
|
|
|
|
|
};
|
2024-03-06 19:17:45 +08:00
|
|
|
|
|
|
|
|
export const isFileUploadDone = (file: UploadFile) => file.status === 'done';
|
2024-03-27 17:56:34 +08:00
|
|
|
|
|
|
|
|
export const getExtension = (name: string) =>
|
|
|
|
|
name?.slice(name.lastIndexOf('.') + 1).toLowerCase() ?? '';
|
2024-03-28 16:18:16 +08:00
|
|
|
|
|
|
|
|
export const isPdf = (name: string) => {
|
|
|
|
|
return getExtension(name) === 'pdf';
|
|
|
|
|
};
|